[osg-users] Default vertex shader
Denis Nikolskiy
nikolski at arsc.edu
Thu Jul 24 11:19:44 PDT 2008
Hello Jean-Sebastien,
I followed your advice. Everything works well. Thanks a lot for
clarifying those things and for your help.
Denis
On Jul 23, 2008, at 4:58 AM, Jean-Sébastien Guay wrote:
> 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/
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-
> openscenegraph.org
>
More information about the osg-users
mailing list