I program as teachers NeHe Lesson27 told me, but this is the z-pass.When the algorithm is in the shadow, the shadow is gone. I was told that I can use the z-fail algorithm to solve this problem. therefore, I spend two days to explore the z-fail algorithm. Finally, I cannot figure it out. My program never starts, as I think.
The z-fail algorithm on the wiki list:
Depth Error Around the year 2000, several people discovered that the Heidman method could be made to work in all camera positions by changing depth. Instead of counting the surface of the shadows in front of the surface of the object, the surfaces behind it can be considered just as easily, with the same end result. This solves the problem that the eye is in the shadow, since the shadow volumes between the eye and the object are not taken into account, but it introduces the condition that the back end of the shadow volume should be closed, or there will be no shadow if the points of the volume are back to infinity.
Disable recording in depth and color buffers.
Use discarding the front panel.
Set the stencil operation to increase in depth (just mark the shadows behind the object).
Display shadow volumes.
Use knock back.
Set the stencil operation to a decrease in depth.
Display shadow volumes.
The main question that I think is a depth test. In steps 3 and 6, the stencil operation is based on a depth error. Although it can display a shadow, it can be obscured by the object in front of it (that is, an object whose buffer depth value is less than it). the shadow effect looks messy.
But in the z-pass algorithm, the stencil operation is based on a depth transition, which means that it can not only display the shadow, but also shade only the object behind it that matches the eye system.
therefore, how to solve this problem, to make my algorithm with a depth error, you can see the shadow on the correct objects.
here is my z-fail algorithm code (maybe somewhere, where please help me find out the shadow effect is terrible)
VECTOR vec; void shadowvolume(SECTOR &sec,float *lp) { unsigned int p1, p2; VECTOR v1, v2; int i, j, k, jj; for (i=0; i<sec.numplanes;i++) { if (sec.planes[i].visible) { for (j=0;j<3;j++) { k = sec.planes[i].neigh[j]; if ((!k) || (!sec.planes[k-1].visible))
the VECTOR class is as follows:
class VECTOR { public: float x,y,z; bool operator==(VECTOR vec) { if(x==vec.x && y==vec.y && z==vec.z) return true; return false; } };
SECTOR class and others such:
class PLANEEQ { public: float a,b,c,d; }; class PLANE { public: unsigned int p[3];
the DrawGLScene function in my main.cpp looks like this:
int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |GL_STENCIL_BUFFER_BIT); glLoadIdentity(); DrawGLRoom(); glLoadIdentity(); GLfloat xtrans = -xpos; GLfloat ztrans = -zpos; GLfloat ytrans = -ypos-1.2f; GLfloat sceneroty = 360.0f - yrot; glRotatef(lookupdown,1.0f,0,0); glRotatef(sceneroty,0,1.0f,0); glTranslatef(xtrans, ytrans, ztrans); brick_sec.build(); floor_sec.build(); //wall_sec.build(); //CastShadow(wall_sec,(float *)&lightgroup.lights[0].pos); CastShadow(brick_sec,(float*)&lightgroup.lights[0].pos); CastShadow(floor_sec,(float*)&lightgroup.lights[0].pos); lightgroup.build(); glColor4f(0.7f, 0.4f, 0.0f, 1.0f); glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glTranslatef(lightgroup.lights[0].pos.x, lightgroup.lights[0].pos.y, lightgroup.lights[0].pos.z); gluSphere(q, 0.2f, 16, 8); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); if(space_time>0) { ypos=sin(space_time*3.1415926/180); space_time-=4; } else { sp=false; } //glFlush(); return TRUE; // Everything Went OK }
Since my reputation is less than 10, I can’t capture the shadow effect to show how strong it looks! Pls help me i thanks u for ur attention and ur time!
thanks Najzero for giving me 5 rep, now I can capture the screen to show the effect. I will add a detailed description.
z-pass algorithm effect: when I’m not valid, it’s normal! (orange pot represents light) 
but when I am in wall_shadow, this is not normal! wall_shadow is gone, although brick_shadow is still there.

so I need a z-fail algorithm to solve this problem. But the last effect that my code implements looks like this:
the checkmark represents the effect of the shadow, it is correct, the cross means that the shadow should not appear on the object.
another screenshot 