Terry Welsh schrieb: > If you are seeing transparent objects, then you are probably getting a > value smaller than 1.0 in the alpha component of gl_FragColor. It > looks like you could be getting alpha from gl_Color, > gl_FrontLightProduct[0].ambient, or from your texture. Try to figure > out where the problem is by sending those sources to gl_FragColor > individually and view your scene using each one. > > Also, you should be able to get this working without 'if' statements, > which will slow down your shader. Ambient light is usually added, not > multiplied. Try something like this: color = ((direct light * > shadow) + ambient light) * surface color. > - Terry > Hi Terry,
I think that the problem was that I cannot use gl_FrontLightProduct on the backside! Unfortunately I did not have the possibility to decide which side I am on on the fragment stage (because I use twoSided-lighting gl_BACK won´t do), so I decided to use a more complex approach with a vertex shader and a fragment shader. This gave me total control over the colors, and now it works (though it was quite hard to code for a shader-beginner like me!). What I want is to use exactly the ambient light for the shadow, and I would not know how to do this without an if-statement! Thanks, Andreas > >> Message: 7 >> Date: Sun, 04 Nov 2007 16:48:02 +0100 >> From: Andreas Goebel <[EMAIL PROTECTED]> >> Subject: [osg-users] Fragment Shader Question >> To: OpenSceneGraph Users <[email protected]> >> Message-ID: <[EMAIL PROTECTED]> >> Content-Type: text/plain; charset=ISO-8859-15; format=flowed >> >> Hi, >> >> I have played around a bit with the FragmentShader for ShadowMap.cpp >> >> Instead of using a predefined bias I wanted the shadow to appear exactly >> in the currents materials ambient color. >> >> That's what I did: >> >> 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" >> " if (!shadow2DProj(osgShadow_shadowTexture, >> gl_TexCoord[1])[0] ) { \n" >> " gl_FragColor = gl_FrontLightProduct[0].ambient * >> texture2D( osgShadow_baseTexture, gl_TexCoord[0].xy ); \n" >> " } else { \n" >> " gl_FragColor = gl_Color * texture2D( >> osgShadow_baseTexture, gl_TexCoord[0].xy ); \n" >> " } \n" >> "}\n"; >> >> This works, and the result is quite good when looking at the object from >> the same direction as the light-source. >> >> If I look at it from the other side then at the places where the shadow >> is (which is invisible here, as it uses the ambient color) the object is >> slightly transparent. >> >> Any clues on this? >> >> Regards, >> >> Andreas >> >> > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

