PDA

View Full Version : how to make shadowmaps from stencil shadow???



gamerixe
06-19-2003, 08:29 AM
I've merged the NEHE tutorials, about stencil shadow in my 3D engine.everything looks very good,but the frame rate drop at around 15 fps(GeForce 2 GTS+320 megs Ram).

I'm wondering if there could be a ways to "save" the shadow in a textures and to use it as a shadow maps(multitexturing)???

06-21-2003, 04:44 AM
If you use textures would the shadows be static and never change. Another idea is to precalculate the shadow volume, This will give the correct result for objects moving in out from the shadows but the light and shadow caster must be static.
Your fps seems to be low, are you sure that you are using a color depth that will give you a hardware stencil buffer?

gamerixe
06-22-2003, 05:32 AM
Im running in 32 bits,"the stencil buffer should be actvated".This the routine im using for shadow, mainly NEHE tuts midified to work with many object.

this is call each frame:
glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE);
glDepthFunc(GL_LEQUAL);

glEnable(GL_STENCIL_TEST);
glColorMask(0, 0, 0, 0);
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);

// first pass, stencil operation decreases stencil value
glFrontFace(GL_CCW);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
for(i=0;i<nbObject;i++)
glCallList(2000+i);


// second pass, stencil operation increases stencil value
glFrontFace(GL_CW);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);

for(i=0;i<nbObject;i++)
glCallList(2000+i);

glFrontFace(GL_CCW);
glColorMask(1, 1, 1, 1);

//draw a shadowing rectangle covering the entire screen
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
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();
glDisable(GL_BLEND);

glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glEnable(GL_LIGHTING);
glDisable(GL_STENCIL_TEST);
glShadeModel(GL_SMOOTH);

the for loop just do all the shadow volume(they are compiled once at loading this ways)
void DrawShadow(t3DObject *pObject,float *lp)
{
unsigned int i, j/*,k*/;
unsigned int p2;
sPoint v1, v2;

for (i=0; i<pObject->numOfFaces;i++)
{
if (object[i].visible)

for (j=0;j<3;j++)
{
//k = object[i].neigh[j];
//if ((!k) &#0124; &#0124; (!object[i].visible))
//{
// here we have an edge, we must draw a polygon

p2 =(j+1)%3;

//fprintf(fp,"%d\n",(j+1)%3);

//calculate the length of the vector
v1.x = (object[i].p[j].x - lp[0])*100;
v1.y = (object[i].p[j].y - lp[1])*100;
v1.z = (object[i].p[j].z - lp[2])*100;

v2.x = (object[i].p[p2].x - lp[0])*100;
v2.y = (object[i].p[p2].y - lp[1])*100;
v2.z = (object[i].p[p2].z - lp[2])*100;

//draw the polygon
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(object[i].p[j].x,
object[i].p[j].y,
object[i].p[j].z);
glVertex3f(object[i].p[j].x + v1.x,
object[i].p[j].y + v1.y,
object[i].p[j].z + v1.z);

glVertex3f(object[i].p[p2].x,
object[i].p[p2].y,
object[i].p[p2].z);
glVertex3f(object[i].p[p2].x + v2.x,
object[i].p[p2].y + v2.y,
object[i].p[p2].z + v2.z);
glEnd();
//}
}

}
}

06-24-2003, 06:30 PM
I havent looked closly at your code but if you are using the stuff from NeHe should it be OK. A simple test like making the window smaller will give some hints there the bottleneck is. If the fps almost double with a halfed window is it the fill rate.
My guess is that the generation of the shadow volumes is the explanation.

gamerixe
06-25-2003, 02:51 PM
Got 11 fps @ 1280*1024,31 fps @ 640*480 and 60 fps @ 320*240(yark!!).I have tried just to call all the gl functions without drawing the "shadowed" objets and the frame rate is still the same;must be normal since im using glCallList the do the shadow poly...


(sorry for my bad english http://www.opengl.org/discussion_boards/ubb/frown.gif,Im from Quebec and im trying to improve it.

06-28-2003, 02:02 AM
At least at higher resolutions does the speed seems to be limited by the fillrate. Not much can be done about it. Check that you dont clear the screen if you are redrawing it anyway.
I guess that if you want shadows at 1280*1024 do you have to upgrade your hardware or try something different than shadow volumes. Easy choice if you have the money... http://www.opengl.org/discussion_boards/ubb/smile.gif

English is not my native language but I dont see anything bad about your language.