Re: [osg-users] Default vertex shader
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[EMAIL PROTECTED] http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users- openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Default vertex shader
Hi Denis, I followed your advice. Everything works well. Thanks a lot for clarifying those things and for your help. Glad I could help, J-S -- __ Jean-Sebastien Guay[EMAIL PROTECTED] http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Default vertex shader
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[EMAIL PROTECTED] http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Default vertex shader
Hello Jean-Sebastien, Check the top of the shader in src/osgShadow/ShadowMap.cpp, there is a bunch of uniforms with names that start with osgShadow_. You can use those same variable names in other shaders, and you will then have access to the same data (as long as the shader is on a node in the subgraph under the ShadowedScene node). The sampler is the shadow map itself, and the others are parameters. So you can use the same code and just combine it with whatever else you want to do. Thanks for clarifying those things. I followed your suggestion and I was able to access all the osgShadow_ uniforms when I added only fragment shader. 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? Thank you for your time, Denis ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org