[osg-users] Default vertex shader

Jean-Sébastien Guay jean-sebastien.guay at cm-labs.com
Wed Jul 23 05:58:56 PDT 2008


Hello Denis,

> When I added vertex shader, the object was not shadowed properly 
> (with the same exact fragment shader). I suspect I'm doing something 
> wrong with the texture coordinates in a vertex shader. I looked in 
> ShadowMap.cpp, it has only fragment shaders. Do you know where can I 
> find default vertex shader?

When you start using a shader for one part of the pipeline (vertex or 
fragment) you need to do everything that that part of the pipeline used 
to do (and which is needed by your rendering). In the case of shadows, 
you'll notice that the code in ShadowMap.cpp adds an osg::TexGen that 
calculates some texture coordinates for texture unit 1. But that's the 
fixed pipeline, so you will need to calculate texture coordinates for 
unit 1 as glTexGen would in your vertex shader now that it has replaced 
the fixed-function vertex processing.

Something like this should work, though you should probably have finer 
control over when these are calculated or not:

     gl_TexCoord[1].s = dot( ecPosition, gl_EyePlaneS[1] );
     gl_TexCoord[1].t = dot( ecPosition, gl_EyePlaneT[1] );
     gl_TexCoord[1].p = dot( ecPosition, gl_EyePlaneR[1] );
     gl_TexCoord[1].q = dot( ecPosition, gl_EyePlaneQ[1] );

Note that ecPosition is:

     vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

I also assume you're transforming your texture coordinates for texture 
unit 0 properly:

     gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

Just assigning gl_MultiTexCoord0 to gl_TexCoord[0] will work until you 
try to use a texture matrix (osg::TexMat)...

I highly recommend you get/read the Orange Book, as this is all given 
there. You can also download the ShaderGen program from 3DLabs (now 
hosted on http://mew.cx/glsl since 3DLabs removed it from their site) 
which can generate shaders that emulate the fixed pipeline. Note that 
for speed, you should probably only use the features you need in your 
shaders, so I am not recommending that you generate a shader that does 
*all* of what the fixed pipeline would do... Just use what ShaderGen 
produces as a guide.

Hope this helps,

J-S
-- 
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.guay at cm-labs.com
                                http://www.cm-labs.com/
                         http://whitestar02.webhop.org/



More information about the osg-users mailing list