Thank you both for your replies.  I figured out how to do it with the help of 
Terry's post.  I'm putting my answer here in case anyone else comes across the 
same problem.  

I sub-classed osg.ShadowMap, and set a new custom fragment shader code.  I 
created a flag (which I call 'ghostObject') to mark those nodes for which the 
effect will be applied.  I set the flag on each node using:

 node.getOrCreateStateSet().addUniform(osg.Uniform('ghostObject', True))

If the flag is set, the shader will set the alpha of every pixel to 0, except 
those pixels that lie inside a shadowed area.  If the flag is not set, the 
shader will just darken shadowed areas.


Code:
shaderSource = """
uniform sampler2D osgShadow_baseTexture; \m
uniform sampler2DShadow osgShadow_shadowTexture; \n
uniform vec2 osgShadow_ambientBias; \n
uniform bool ghostObject;\n
       
void main(void) \n
{\n
                 
        vec4 shadowProj = shadow2DProj( osgShadow_shadowTexture, gl_TexCoord[1] 
);\n
            
        gl_FragColor = gl_Color * texture2D( osgShadow_baseTexture, 
gl_TexCoord[0].xy );\n
            
        if(ghostObject && shadowProj.x > 0.5 )\n
            gl_FragColor.w = 0.0;\n
        else if( shadowProj.x < 0.5 ){\n
            gl_FragColor.x = gl_FragColor.x * 0.5;\n
            gl_FragColor.y = gl_FragColor.y * 0.5;\n
            gl_FragColor.z = gl_FragColor.z * 0.5;\n
        }\n
                
 }\n"""



Thank you!

Cheers,
Juan
Code:




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=57876#57876





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to