Jump to content
  • Advertisement
Sign in to follow this  
b3rs3rk

Shadows volumes: what's wrong ??!

This topic is 4972 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'm playng a bit with shadows volumes. i've wrote a small class for an object, with faces and vertexes and i've created the relative shadow volume. in my render function i clear all the biffers, then render my scene (it's a simple high tessellated floor with a quad on it that should cast the shadow, nothing special) with a wireframe version of the casted volume this is perfect) , then i set the opengl states for the stencil, render the shadow and flush. Are these the correct passes or should i do some other things? the real problem is that except the floor , the quad and the wireframe volume, nothing more is rendered. The shadows doesn't appear. It's like if the stencil buffer is not filled. This is my render function:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();	
gluLookAt(0,3,10, 0,0,0, 0,1,0);
Point3 lpos(LightPosition[0],LightPosition[1],LightPosition[2]);
glLightfv( GL_LIGHT1, GL_POSITION, LightPosition );

RenderScene();	// the floor and the shadow caster quad
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
Quad.DrawShadowVolume(lpos);	
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );


glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT );
glDisable( GL_LIGHTING );	// Turn Off Lighting
glDepthMask( GL_FALSE );	// Turn Off Writing To The Depth-Buffer
glDepthFunc( GL_LEQUAL );
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 );

glFrontFace(GL_CCW);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
Quad.DrawShadowVolume(lpos);

glFrontFace(GL_CW);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
Quad.DrawShadowVolume(lpos);

glFrontFace( GL_CCW );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );	

//draw a shadowing rectangle covering the entire screen
glColor4f( 0.0f, 0.0f, 0.0f, 0.4f );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL );
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
glPushMatrix();
glLoadIdentity();
glBegin( GL_TRIANGLE_STRIP );
	glVertex3f(-0.1f, 0.1f,-0.10f);
	glVertex3f(-0.1f,-0.1f,-0.10f);
	glVertex3f( 0.1f, 0.1f,-0.10f);
	glVertex3f( 0.1f,-0.1f,-0.10f);
glEnd();
glPopMatrix();
glPopAttrib();


glColor4f(0.7f, 0.4f, 0.0f, 1.0f);	// Set Color To An Orange
glDisable(GL_LIGHTING);		        // Disable Lighting
glDepthMask(GL_FALSE);			// Disable Depth Mask
glColor4f(0.75f, 0.0f, 0.0f, 1.0f);
glPushMatrix();
glTranslatef(LightPosition[0],LightPosition[1],LightPosition[2]);
gluSphere(sphere, 0.1f, 30, 30);        //draw a sphere with the light position
glPopMatrix();
glEnable(GL_LIGHTING);			// Enable Lighting
glDepthMask(GL_TRUE);		

glFlush();	



this is the code from the tutorial #27 on NeHe. Any advices?

Share this post


Link to post
Share on other sites
Advertisement
Is backface culling enabled ?
Do you set the stencil mask somewhere ?

BTW, instead of drawing a shadow quad, you should first render the scene with only ambient light draw shadow volumes, and then redraw the scene with diffuse and specular light (and this for all point lights). This will look much better.

Share this post


Link to post
Share on other sites
this is my InitGl function:


bool InitGL(void)
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glClearStencil(0); // Stencil Buffer Setup

glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
// glCullFace(GL_BACK); // Set Culling Face To Back Face
// glEnable(GL_CULL_FACE); // Enable Culling

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

float LightAmb[] = { 0.2f, 0.2f, 0.2f, 1.0f};
float LightDif[] = { 0.6f, 0.6f, 0.6f, 1.0f};
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmb); // Set Light1 Ambience
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDif); // Set Light1 Diffuse
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

glClearColor(0.1f, 1.0f, 0.5f, 1.0f); // Set Clear Color (Greenish Color)

return true;
}




if i enable backface culling nothing is rendered o_O

Share this post


Link to post
Share on other sites
i don't know if your using z-fail or not(you should). so here is the code for that

glFrontFace(GL_CCW);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
Quad.DrawShadowVolume(lpos);

glFrontFace(GL_CW);
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
Quad.DrawShadowVolume(lpos);


other than that, have you tried fiddeling with this line
glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL );

try
glStencilFunc( GL_EQUAL, 0, 0xFFFFFFFFL );
IF the entire screen isn't shadowed with this, then it's a problem with the rendering of the black shadow polygon

allso i see that the shadow polygon is renderd at z=-0.10f
what is your z near?
try to put glDisable(GL_DEPTH_TEST);
right before glBegin( GL_TRIANGLE_STRIP );

Share this post


Link to post
Share on other sites
but i've noticed that if i comment these lines:
/*glFrontFace(GL_CCW);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
Quad.DrawShadow(LightPos);*/
and do only this rendering pass:
glFrontFace(GL_CW);
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
Quad.DrawShadow(LightPos);
nothing changes. but if i do the inverse, the shadow isn't rendered..

Share this post


Link to post
Share on other sites
Quote:
Original post by b3rs3rk
it's happening something really wierd: instead of drawing the shadow rectangle, appears its CONTOUR o_O


Could be because you're drawing the shadow volume in line mode with depth write enabled.
Hmmm did you try the z-fail way (the z-pass way can give bad results when the camera is inside the shadow volume) ?

Share this post


Link to post
Share on other sites
Hmmm could you try you shadows step by step ?
- actually draw the shadow volume without the stencil stuff (and with blending) and see if its orientation is OK (draw front and back sides with different colors if necessary) ;
- test the incrementing pass alone for the shadow volume ;
- test the decrementing pass alone (initialize the stencil to 1).

This should help you figure what's wrong.

Share this post


Link to post
Share on other sites
the incrementing pass draws the contour of the shadow.

the decrementing pass instead, draws nothing:

glStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFFL );
glFrontFace(GL_CCW);
glStencilOp(GL_KEEP, GL_DECR , GL_KEEP);
Quad.DrawShadow(LightPos);

i'm slightly becoming mad...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!