Vulkan Renderer Quad shader Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Vulkan Renderer Quad shader

Post by dermont »

Hi I've been trying out the Ogre Vulkan renderer and creating from code a material/shaders for a v1 mesh namely a Ogre::v1 Plane to render a video.

I am/was having problems with the correct syntax. I tried following some of the shaders updated in the media and the following link helped.

https://git.root3287.site/Sudo-Team/SPI ... 9abaf9ce91

The following works but I'm still not sure it is correct.

Code: Select all

//            @code
//                #define ogre_P0 set = 0, binding = 0 // Params buffer
//                #define ogre_B2 set = 0, binding = 1 // Const buffer at slot 2
//                #define ogre_B3 set = 0, binding = 2
//                #define ogre_T0 set = 0, binding = 3 // Tex buffer at slot 0
//                #define ogre_t1 set = 0, binding = 4 // Texture at slot 1
//                                                     // (other APIs share tex buffer & texture slots)
//                #define ogre_s1 set = 0, binding = 5 // Sampler at slot 1
//            @endcode

Vertex Shader:

Code: Select all

#version 450
#extension GL_ARB_separate_shader_objects : enable
vulkan_layout( OGRE_POSITION ) in vec3 vertex;
vulkan_layout( OGRE_NORMAL ) in vec3 normal;
vulkan_layout( OGRE_TEXCOORD0 ) in vec2 uv0;
 vulkan( layout( ogre_P0 ) uniform Params { )
    gl_uniform mat4 worldViewProj;
    gl_uniform vec4 zoom;
vulkan( }; )
out gl_PerVertex {
    vec4 gl_Position;
};
vulkan_layout( location = 0 )
out block
{
    vec2 texCoord; 
} outVs;
void main(void)
{
    gl_Position = worldViewProj*vec4(vertex.xyz,1.0)*zoom.xyzw;
    outVs.texCoord = uv0;
}
Pixel Shader:

Code: Select all

#version 450
#extension GL_ARB_separate_shader_objects : enable
vulkan_layout( ogre_t0 ) uniform texture2D videotex;
vulkan( layout( ogre_s0 ) uniform sampler texSampler );
vulkan_layout( location = 0 )
in block
{
    vec2 texCoord;
} inPs;
vulkan_layout( location = 0 ) out vec4 outputColor;

void ellipse(in float radius, in vec2 uvcoords, in float border, in vec3 borderColour, inout vec4 outColour, vec2 centre)
{
    float dpos = dot(fract(uvcoords) - centre, fract(uvcoords) - centre);
    if (dpos > radius * radius) {  
        if (dpos > radius*(1.0+border) * radius*(1.0+border)) { discard;} 
        else { outColour = vec4(borderColour ,1); }
    }
}
void main() {
    outputColor = vec4( texture( sampler2D( videotex, texSampler ),vec2( inPs.texCoord.xy )) );
    ellipse(0.48, fract(inPs.texCoord.xy), 0.0065, vec3(0.49,0.49,0.49), outputColor,vec2(0.5,0.5));
}

Thanks.

[Edit] Loading the Vulkan Renderer failed due to missing symbols, needed to link to X11-xcb.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5446
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1348

Re: Vulkan Renderer Quad shader

Post by dark_sylinc »

Oh boy! Getting anxious are we?

Please note the Vulkan renderer is WIP.

The shader code you posted appears correct.

Please note the vulkan and vulkan_layout macros are there to facilitate reusing the same shader code to target both Vulkan & GL3+ using the same source code.

You can use more 'raw' glsl syntax if you only intend to target Vulkan or use two separate shader files for each API

The macros ogre_t0 and co. (as well as OGRE_POSITION & co.) are still needed so your shader uses the correct binding points
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

[Solved]Re: Vulkan Renderer Quad shader

Post by dermont »

dark_sylinc wrote: Sat Aug 15, 2020 2:53 pm Oh boy! Getting anxious are we?
Not really. I understand that the Vulkan drivers are a WIP. I updated my graphics drivers / Vulkan SDK/rebuilt Ogre and the Ogre sample demos that ran OK before were showing a blank screen with only the overlay.

I created a stand-alone demo to try and trace the issue, the demo ran ok. It appears that the initial problem could be resolved by removing the connection to second monitor. After updating from git I couldn't reproduce this.

Anyway thanks for your help and sorry for wasting your time.