PDA

View Full Version : Handling textures when generating a shadow



Andreas Goebel
05-15-2006, 12:26 PM
Hi all,

I hope this is advanced enough...

I have the following problem:

I generate shadows in my application with projected textures.

For generating the shadowtexture, I do a render to texture (I will call this shadowtexture from now on, not to be confused with the shadowtexture for depthshadows!).

When rendering this texture I use the following material. The syntax is a bit strange because I do not use OpenGL directly, but I use OpenSceneGraph. But the material is exactly what would happen in "real" openGL:

material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4 (0.0f,0.0f,0.0f,1.0f));
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4 (0.0f,0.0f,0.0f,1.0f));
material->setEmission(osg::Material::FRONT_AND_BACK,ambientL ightColor);
material->setShininess(osg::Material::FRONT_AND_BACK,0.0f);
stateset->setAttribute(material,osg::StateAttribute::OVERRID E);

This works fine as long as the shadower doesn´t have any textures itself.

If the shadower has textures, however, they "shine through" in the shadowtexture:

Example Picture (http://home.arcor.de/goeba/TextureShinesThrough.png)

If I switch off texturing for rendering the shadowtexture this problem goes away, but if I have polygons with partially transparent textures, this looks wrong.

So what I would need is a "trick" to turn the textures to black&white while leaving the alpha intact (or setting it 1 whereever it is nonzero).

I tried to use GLTexEnv, but I didn´t manage to do the trick.

I hope I made myself clear and I hope that someone can help me.

I need an explanation rather than code, because I will have to "translate" this to OpenSceneGraph.

Thanks in advance and best regards,

Andreas

tamlin
05-15-2006, 01:55 PM
What if you keep the alpha, but set RGB to PREVIOUS for TU 0 (meaning PRIMARY_COLOR) and play around with the color?

Andreas Goebel
05-15-2006, 02:08 PM
Hi,

I guess you talk about the

glTexEnvCombine

state.

Good idea,

I will try this!

Regards,

Andreas

Andreas Goebel
05-15-2006, 02:45 PM
Ok,

I think I got this right.

The texture still shines through, though less than before. Hm.

If I dont use the ambient component of the state, then the problem is gone.

But then the shadow is pitch black.

Thanks for the help, but the problem is still unsolved!

Is there someone here around who does shadow-projection and can show me the state settings for generating the shadowtexture?

Regards,

Andreas