Archived

This topic is now archived and is closed to further replies.

Quick Shadow question

This topic is 5124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I succeded in seeing some effects from a triangle cast on a plane, and figured out what silhouettes are... Anyhow now I can see the shadow from any angle(if I modify the GL_DECR with GL_INVERT). The problem here appears as folows:outside the volume shadow everything`s fine but inside everything is upside down, meaning that there`s no shadow and I can see the silhouette poligons, like in a room . The question would be... what Stencil Func shall I use to remove this... artifact ?

Share this post


Link to post
Share on other sites
Read the current article about Cg-Shadow Volumes. In the first few pages the auther gives an explanation on how things work. On page 2 he addresses the problem that occurs when the camera moves inside the volume (that''s what you''re looking for, right?).

Share this post


Link to post
Share on other sites
Well that`s kind of my problem but I didn`t tested it yet.
I made a little more tests because I found out some weird about the front face/back face, and got to the conclusion that the front face/back face is not caomputed based on the surface normal... I enabled backface culing and rendered a terrain with the right normals and there`s culling but when I reversed the normals... it was the same thing only with lower lighting intensity... that`s not what I want... is there a way of setting a poligons front face/back face ? or OpenGl is setting it up ?

Share this post


Link to post
Share on other sites
Well... I made it work !!!

This is pretty stupid because what I used, woren`t used in any tuts but i tryed it anyhow...
If you wonder amaze yourself og my method

DrawPlane();
DrawTriangle();
glEnable(GL_CULL_FACE);
glColorMask(GL_FALSE,GL_FALSE, GL_FALSE, GL_FALSE);
glEnable(GL_STENCIL_TEST);
glDepthMask(GL_FALSE);
glStencilFunc(GL_ALWAYS,1,0);

glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);
glCullFace(GL_BACK);
DrawTriangleSilhouette();

glStencilOp(GL_KEEP, GL_INVERT,GL_KEEP);
glCullFace(GL_FRONT);
DrawTriangleSilhouette();

glDepthMask(GL_TRUE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glCullFace(GL_BACK);
glDepthFunc(GL_LEQUAL);
glStencilOp(GL_KEEP, GL_KEEP,GL_KEEP);
glStencilFunc(GL_EQUAL,1,0);

glDisable(GL_LIGHT0);
glDisable(GL_CULL_FACE);
DrawPlane();

glStencilFunc(GL_EQUAL, 0, 1);
glEnable(GL_LIGHT0);
DrawPlane();
//DrawTriangle();

glDepthFunc(GL_LEQUAL);
glDisable(GL_STENCIL_TEST);
//

glDepthFunc(GL_LEQUAL);

But now I have another bug(much smaller)... Under the DrawPlane() Plane I see both the shadow and the triangle in the color of the shadow... but I may work this out .

Share this post


Link to post
Share on other sites
The standard zfail volume shadow algorithm uses:
glStencilOp(GL_KEEP,GL_INCR,GL_KEEP); 

for the back faces and
glStencilOp(GL_KEEP, GL_DECR,GL_KEEP); 

for the front faces.
Using
glStencilOp(GL_KEEP, GL_INVERT,GL_KEEP); 

will only work for simple shadow volumes (no overlapping of shadows).

Also, for self shadowing to work properly you need to set your depth func to GL_LESS when drawing the shadow volumes.

Just to prove that I know what I''m talking about (and because I only finished the program this weekend and want to show it off)


Enigma

Share this post


Link to post
Share on other sites
I posted that code because only that code worked for me !
I reviewed dozens of tutorials on shadows and none worked so I played around those params and that`s the only config that works and I`m really happy about it...

The only bug now is that there are 2 shadows... and one is dependent of the camera and it`s written into the distance but still on the surface... I`ll have to mangle with that 2-pass lit/unlit rendering of the plane...

Share this post


Link to post
Share on other sites
I persume you are using zfail or carmacs reverse.
In that case, Did you cap the shadow volume.
Basicly what you do is that you draw the light facing polygons then the siluette and lastly the same lightfacing polygons but you extrude them the same way you did the siluette and you draw the vertics in the reverse order.

[edited by - lc_overlord on December 1, 2003 4:43:29 PM]

Share this post


Link to post
Share on other sites
After analysing the silhouette some more I changed the face orientation and managed to get all faces pointing outside so now the original algorithm works but there`s that inside bug again... so i`ll try using some PushAttrib() ...

Share this post


Link to post
Share on other sites
I looked again(now with the faces going pointing the right direction) at that ''Carmack Reverse'' and... I might say it`s not perfect... I can see the shadow when I have the light from top to bottom, and there`s no inside error .
But when I go underneath the plane, I see the shadow and that second triangle that`s almost moving with the camera...
Also when I put it in a box, the shadows only exist when the light comes from top to bottom, even if there are polys up... which is not that practical... I`m gonna try the NeHe demo next(for the third/forth time)

Share this post


Link to post
Share on other sites
I used the NeHe shadow code from the tutorial and... modifyed it to work... relatively normal like this ->

DrawPlane();
DrawTriangle();
glEnable(GL_CULL_FACE);
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT );
glDepthMask( GL_FALSE ); // Turn Off Writing To The Depth-Buffer

glDepthFunc( GL_LESS );
glEnable( GL_STENCIL_TEST ); // Turn On Stencil Buffer Testing

glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); // Don''t Draw Into The Colour Buffer

glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFFL );

glCullFace(GL_FRONT);
glStencilOp( GL_KEEP, GL_INCR,GL_KEEP);
DrawTriangleSilhouette();
// Second Pass. Decrease Stencil Value In The Shadow

glCullFace(GL_BACK);
glStencilOp( GL_KEEP, GL_DECR,GL_KEEP);
DrawTriangleSilhouette();

glDepthFunc(GL_LEQUAL);
glDisable(GL_CULL_FACE);
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glStencilFunc(GL_EQUAL,1,1);
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0,0,0,0.4f);
DrawPlane();
glDisable(GL_BLEND);
glPopAttrib();


And offcourse it had that, ''under the silhouette shit happens'' and I modifyed it some more as [Enigma] instructed and... this is what exactly happens->
http://www.geocities.com/cippyboy_7/shadowbug.jpg
as I`ve seen there`s another another triangles that`s inverting it`s color...
If I`m wrong in some part of the code please correct me !

Share this post


Link to post
Share on other sites