Hi Roger, I tested my code on GeForce 6200. First I tried using integer uniform like:
uniform int stage [..] vec4 texcolor = gl_TexCoord[ stage ]; Such code was causing GLSL compilation errors suggesting that in this profile uniform indices cannot be used. I was however assured by others that such construct works on higher end boards ;-) I guess GeForce 8800 and above may do this. Then I tried to use search and replace but to simplify modifications declared stage as const int. const int stage = 0; [..] vec4 texcolor = gl_TexCoord[ stage ]; It worked on my 6200 but again got reports from others that this did not compile on some boards (some ATI ? I am not sure...). So I ended up with solution replacing whole gl_TexCoord[ index ] expressions. Adding integer index uniform, variable or const does not solve all problems though. Vertex shaders use gl_MultiTexCoord0..gl_MultiTexCoordN symbols. There is no way to index that, unless some recent GL spec have added indexed versions. This was one more reason I gave up and created alist of symbols that are searched and replaced when user changes indices. Cheers, Wojtek -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Roger James Sent: Friday, October 03, 2008 6:31 PM To: OpenSceneGraph Users Subject: Re: [osg-users] Bug in osgShadow::ShadowMap Hi Wojciech, I was building against 2.6.0 so I had not seen your code. Having looked at it now it certainly seems a more sophisticated approach! It also looks like you avoid killing the ambient light which ShadowMap does! Going back to your comments, can you confirm that some architectures do not allow gl_TexCoord[uniform int variable] and gl_TexCoord[int variable] but do allow gl_TexCoord[int constant], or do they also allow local integer variables (i.e. gl_TexCoord[int variable]) to be used. It would be useful to know what architectures you had problems with. It would seem to be a pretty major violation of the OpenGLSL grammars definition of postfix expressions. On the nVidia Quaddro that I am testing with, using an integer variable in the postfix works fine. I now realise from reading the OpenGLSL spec that I cannot extract the texture unit from the sampler or vice-versa. So I would have to pass in another uniform. However from what you are saying I would not be able to make that work in all circumstances anyway! Roger Wojciech Lewandowski wrote: > Hi Roger, > > During work on inclusion ViewDependentShadows into osgShadow I was > dealing with similar problem. Certain architectures allow to use > integer unifrom as gl_TexCoord index but others do not. After few > different approaches I ended up with old school search and replace in > Shader text. This code is now currently added to osg svn. You may try > osgShadow::StandardShadowMap which is roughly equivalent of > osgShadow::ShadowMap and see if it works better for you. > > Cheers, > Wojtek > > From: "Roger James" <[EMAIL PROTECTED]> > To: <osg-users@lists.openscenegraph.org> > Sent: Friday, October 03, 2008 2:10 PM > Subject: [osg-users] Bug in osgShadow::ShadowMap > > >> The fragment shaders in osgShadow::ShadowMap uses hard coded values >> to access the texture coordinates (gl_TexCoord[]) passed from the >> fixed functionality. >> >> gl_FragColor = gl_Color * (osgShadow_ambientBias.x + shadow2DProj( >> osgShadow_shadowTexture, gl_TexCoord[0] ) * osgShadow_ambientBias.y); >> >> and >> >> gl_FragColor = color * (osgShadow_ambientBias.x + shadow2DProj( >> osgShadow_shadowTexture, gl_TexCoord[1] ) * osgShadow_ambientBias.y); >> >> >> This means that if the ShadowMap::setTextureUnit function is used to >> set the shadow texture to a non default value the shader will not >> function. I verfied this and tried to fix it using my own shader >> passed in using ShadowMap::addShader. However when I tried to make my >> code more general purpose and suitable for submission as a patch I >> have run up against the limit of my knowledge of fragment shaders. My >> first question is about how to get round gl_Texcoord being defined as >> varying and of indeterminate size. Anyone know how to explicitly >> declare it (as OpenGL Shading Language book say you have to, but does >> not tell you how, page 72 in my copy). I am assuming my code (below) >> works by chance and may not on other drivers as it does not do this. >> Also is there any way to convert a sampler2DShadow type into an int >> so I can avoid having to pass in another uniform to tell the shader >> what the shadow texture unit is. A problem with having to pass in >> another uniform is that the current implementation does not allow this. >> >> Here is my current test code. >> >> static const char fragmentShaderSource_withBaseTexture[] = >> "uniform sampler2D osgShadow_baseTexture; \n" >> "uniform sampler2DShadow osgShadow_shadowTexture; \n" >> "uniform vec2 osgShadow_ambientBias; \n" >> "\n" >> "void main(void) \n" >> "{ \n" >> " int ShadowUnit = 3; \n" >> " vec4 color = gl_Color * texture2D( osgShadow_baseTexture, >> gl_TexCoord[0].xy ); \n" >> " gl_FragColor = color * (osgShadow_ambientBias.x + >> shadow2DProj( osgShadow_shadowTexture, gl_TexCoord[ShadowUnit] ) * >> osgShadow_ambientBias.y); \n" >> "}\n"; >> >> Comments anyone? >> >> Roger >> _______________________________________________ >> 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 > _______________________________________________ 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