Skip to main content
GameDev.net gamedev.net
🔒 Locked

Stecil shadow

Started by ppavel Aug 24, 2006 at 5:06 PM 9 replies 1.2k views
Original Post
ppavel
ppavel
I have a problem with stencil shadows ... In places where the object is casting shadow on itself, there are gaps in the shadow when it reaches other objects ... is there some way to avoid it? viz picture ... http://hi-park.mnichovice.sweb.cz/stecil_shad.JPG
bakery2k1
bakery2k1
How are you rendering your shadow volumes? It looks like you are saturating the stencil buffer, which may be happening due to having too many volumes, or an incorrectly set stencil mask.

Let's see some code.
jfdegbo
jfdegbo
Indeed, it looks like you have saturated the stencil (wich seems to have a size of 1 bit :/ )

like said before, enlight us a little more so we can help you.
_____My little engine : I.E.
ppavel
ppavel
Thx for your response. Here is the code ...

    glDisable(GL_LIGHTING);    glDisable(GL_TEXTURE_2D);                glClearStencil(0);    glEnable(GL_CULL_FACE);    glDepthMask(GL_FALSE);    glColorMask(0,0,0,0);    glEnable(GL_STENCIL_TEST);    glStencilFunc(GL_ALWAYS, 1, 1);    glFrontFace(GL_CCW);    glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);        spiral.cast_shadow_volume(lightPos[0],lightPos[1],lightPos[2], inv_matice_objektu);        glFrontFace( GL_CW );    glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);        spiral.cast_shadow_volume(lightPos[0],lightPos[1],lightPos[2], inv_matice_objektu);        glColorMask(1,1,1,1);    glStencilFunc(GL_NOTEQUAL, 0, 1);    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP );        glPushMatrix();     glLoadIdentity();     glBegin(GL_QUADS);      glVertex3f(-1.0, -1.0,-1.0);     glVertex3f(-1.0,1.0,-1.0);     glVertex3f( 1.0, 1.0,-1.0);     glVertex3f( 1.0,-1.0,-1.0);   glEnd();   glPopMatrix();        glFrontFace(GL_CCW);    glEnable(GL_LIGHTING);    glEnable(GL_TEXTURE_2D);    glDisable(GL_STENCIL_TEST);        glDepthMask(GL_TRUE);
_neutrin0_
_neutrin0_
....
glFrontFace( GL_CW );
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);

spiral.cast_shadow_volume(lightPos[0],lightPos[1],lightPos[2], inv_matice_objektu);

glDisable(GL_DEPTH_TEST);

glColorMask(1,1,1,1);
glStencilFunc(GL_NOTEQUAL, 0, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP );

.....

This is the only extra thing that I do and it works in my engine perfectly. It should work for you. (I hope) :))
++ My::Game ++
ppavel
ppavel
It is doesn't help ...

I just add the code of shadow volume casting function ...

void OBJEKT::cast_shadow_volume(float lx,float ly,float lz, GLmatrix16f &objMat) {    POINT sv(lx,ly,lz);    POINT light;    svetlo=sv.B_trans_Matrix(objMat);    VECTOR a,b;    POINT A,B;    int v1,v2;    for (int i=0;i<face_count;i++) {                        if (plane.ExBodD(light)>0.0) {                                faces.enlighted=1;        }                if (plane.ExBodD(light)<0.0) {                                faces.enlighted=0;        }    }            for (int i=0;i<face_count;i++) {                if (faces.enlighted) {                                  for (int j=0;j<3;j++) {                                          if (!faces[faces.neigh_index[j]].enlighted) {                                                                       v1=faces.vert_index[j];                     v2=faces.vert_index[(j+1)%3];                                          a=vertexes[v1].V_A_to_B(light);                     b=vertexes[v2].V_A_to_B(light);                     a.unit();                     b.unit();                                          a.KxV(60.0);                     b.KxV(60.0);                                          A=vertexes[v1].move_ret_B(a);                     B=vertexes[v2].move_ret_B(b);                                                                                  glBegin (GL_TRIANGLE_STRIP);                     glVertex3f(vertices[v1].X,vertices[v1].Y,vertices[v1].Z);                     glVertex3f(A.X,A.Y,A.Z);                     glVertex3f(vertices[v2].X,vertices[v2].Y,vertices[v2].Z);                      glVertex3f(B.X,B.Y,B.Z);                                     glEnd();                                                                                  }                     }                                                                              } else {};           }    }     
_neutrin0_
_neutrin0_
Hey I think your stencil function masks are wrong
Try using

....
glStencilFunc(GL_ALWAYS, 1,0xffffffff);
.... //Render shadow volume
......
.....
glStencilFunc(GL_NOTEQUAL,0,0xffffffff);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
... // Draw the shadow quads.
.....
++ My::Game ++
jfdegbo
jfdegbo
indeed,

glStencilFunc(GL_ALWAYS, 1, 1); and
glStencilFunc(GL_NOTEQUAL, 0, 1);

should become :

glStencilFunc(GL_ALWAYS, 1, ~1); and
glStencilFunc(GL_NOTEQUAL, 0, ~1);

this is equivalent to no mask at all, yours is equivalent than using a binary stencil buffer ! not the same !

Hope it works,
JF
_____My little engine : I.E.
ppavel
ppavel
That was it, thanks a lot !!!
bakery2k1
bakery2k1
Quote:
Original post by jfdegbo
glStencilFunc(GL_ALWAYS, 1, ~1); and
glStencilFunc(GL_NOTEQUAL, 0, ~1);


The 3rd argument (~1) should be ~0, i.e. (for a 32-bit mask) 0xffffffff.
jfdegbo
jfdegbo
Quote:
Original post by bakery2k1
The 3rd argument (~1) should be ~0, i.e. (for a 32-bit mask) 0xffffffff.


hehe, my bad, i came back in as i realised my mistake, and thought about editing my post :)

now it's not possible anymore :)))

sorry for the stupid error, this should ofcourse be ~0 !
_____My little engine : I.E.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.