Advertisement

Problem with volume shadow

Started by August 12, 2003 06:28 AM
-1 comments, last by Thor82 21 years, 6 months ago
Why this doesn''t work?? i am sure that createedgelist creates the RIGHT edges that project shadows, if i comment the glcolormask 0000 line the volume is drawed correctly but it flickers (is it the right term?) where am i wrong?

void clShadow::Cast(Light* L){

CreateEdgeList(L);


    glClearStencil(0);
	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( 0, 0, 0, 0 );		// Don''t Draw Into The Colour Buffer

	glStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFFL );

// First Pass. Increase Stencil Value In The Shadow

	glFrontFace( GL_CCW );
	
	glCullFace(GL_FRONT);
	glEnable(GL_CULL_FACE);

	glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
	DoShadowPass( L->Pos );
	// Second Pass. Decrease Stencil Value In The Shadow

	glFrontFace( GL_CCW );
	glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
	DoShadowPass( L->Pos );


	glDisable(GL_CULL_FACE);
	glFrontFace( GL_CCW );
	glColorMask( 1, 1, 1, 1 );	// Enable Rendering To Colour Buffer For All Components


	// 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, 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);
};

void clShadow::DoShadowPass(Coords3f LightPos){
  Coords3f Point3,Point4;

  for(int i=0;i<Edges_Count;i++){
	  Point3=VectSub(EdgeList[i]->A,LightPos);
	  Point4=VectSub(EdgeList[i]->B,LightPos);

	
	  Point3.x *=10;
	  Point3.y *=10;
	  Point3.z *=10;

	  Point4.x *=10;
	  Point4.y *=10;
	  Point4.z *=10;


	  glBegin( GL_TRIANGLE_STRIP);
			glVertex3f( EdgeList[i]->A.x, EdgeList[i]->A.y, EdgeList[i]->A.z );
			glVertex3f( EdgeList[i]->A.x+Point3.x, EdgeList[i]->A.y+Point3.y, EdgeList[i]->A.z+Point3.z );
		    glVertex3f( EdgeList[i]->B.x, EdgeList[i]->B.y, EdgeList[i]->B.z );
			glVertex3f( EdgeList[i]->B.x+Point4.x, EdgeList[i]->B.y+Point4.y, EdgeList[i]->B.z+Point4.z );
	  glEnd();
  };

};

There aren''''t problems that can''''t be solved with a gun...
There aren''t problems that can''t be solved with a gun...

This topic is closed to new replies.

Advertisement