PDA

View Full Version : Capping problem



Frenz
07-16-2003, 10:55 PM
When drawing the objects cap I've this problem...they cast correctly their shadows but create some artifacts.
http://utenti.lycos.it/frenz1979/3d/0.895.jpg

Anyone may help me?

rgpc
07-16-2003, 11:55 PM
Where are the artifacts from (ie. are they from the "railing" or from the torus knot? It's a bit difficult to tell from the piccy you sent. Given their shape I'd guess from the railing, but they're in the wrong position with respect to the light.

How are you extruding your shadow volumes, and what are you using for your end caps? Plus what methods are you using (zFail/zPass - infinite frustum/not inifinite/NV_Depth_Clamp)?

Frenz
07-17-2003, 12:02 AM
Yes, they are from the capped Object (..i this case the railing!)
I post my code:




void __fastcall DrawShadows( int FLAG )
{
FLOAT4 v[4];
GLdouble InverseView[16];
invertMatrix( InverseView , Camera.ViewMatrix );

/* 1 ----------- 0
| |
| |
| |
2 ----------- 3

x 0 4 8 12
y 1 5 9 13
z 2 6 10 14
w 3 7 11 15 */

v[0][0] = v[3][0] = 1;
v[1][0] = v[2][0] = -1;
v[0][2] = v[1][2] = v[2][2] = v[3][2] = -1;
v[0][1] = v[1][1] = 1;
v[2][1] = v[3][1] = -1;

FLOAT4 t;
Set4F( t , v[0] );
v[0][0] = ( t[0]*InverseView[0] + t[1]*InverseView[4] + t[2]*InverseView[ 8] + InverseView[12]);
v[0][1] = ( t[0]*InverseView[1] + t[1]*InverseView[5] + t[2]*InverseView[ 9] + InverseView[13]);
v[0][2] = ( t[0]*InverseView[2] + t[1]*InverseView[6] + t[2]*InverseView[10] + InverseView[14]);
v[0][3] = ( t[0]*InverseView[3] + t[1]*InverseView[7] + t[2]*InverseView[11] + InverseView[15]);

Set4F( t , v[1] );
v[1][0] = ( t[0]*InverseView[0] + t[1]*InverseView[4] + t[2]*InverseView[ 8] + InverseView[12]);
v[1][1] = ( t[0]*InverseView[1] + t[1]*InverseView[5] + t[2]*InverseView[ 9] + InverseView[13]);
v[1][2] = ( t[0]*InverseView[2] + t[1]*InverseView[6] + t[2]*InverseView[10] + InverseView[14]);
v[1][3] = ( t[0]*InverseView[3] + t[1]*InverseView[7] + t[2]*InverseView[11] + InverseView[15]);

Set4F( t , v[2] );
v[2][0] = ( t[0]*InverseView[0] + t[1]*InverseView[4] + t[2]*InverseView[ 8] + InverseView[12]);
v[2][1] = ( t[0]*InverseView[1] + t[1]*InverseView[5] + t[2]*InverseView[ 9] + InverseView[13]);
v[2][2] = ( t[0]*InverseView[2] + t[1]*InverseView[6] + t[2]*InverseView[10] + InverseView[14]);
v[2][3] = ( t[0]*InverseView[3] + t[1]*InverseView[7] + t[2]*InverseView[11] + InverseView[15]);

Set4F( t , v[3] );
v[3][0] = ( t[0]*InverseView[0] + t[1]*InverseView[4] + t[2]*InverseView[ 8] + InverseView[12]);
v[3][1] = ( t[0]*InverseView[1] + t[1]*InverseView[5] + t[2]*InverseView[ 9] + InverseView[13]);
v[3][2] = ( t[0]*InverseView[2] + t[1]*InverseView[6] + t[2]*InverseView[10] + InverseView[14]);
v[3][3] = ( t[0]*InverseView[3] + t[1]*InverseView[7] + t[2]*InverseView[11] + InverseView[15]);

FLOAT4 Plane[6];
CalcPlane(Plane[0], Scene.Light[0].Position , v[0] , v[1]); // Up
CalcPlane(Plane[1], Scene.Light[0].Position , v[1] , v[2]); // Sx
CalcPlane(Plane[2], Scene.Light[0].Position , v[2] , v[3]); // Down
CalcPlane(Plane[3], Scene.Light[0].Position , v[3] , v[0]); // Rx
CalcPlane(Plane[4], v[0] , v[2] , v[1]); // Near
CalcPlane(Plane[5], v[0] , v[1] , v[2]); // "Far"
Plane[5][3] = -Dot3F( Plane[5] , Scene.Light[0].Position );

//-------------------------------------------------------------------------------------------------------
int i;
GLuint STENCIL_INCR = GL_INCR,
STENCIL_DECR = GL_DECR;

if(Render.StencilWrap)
{
STENCIL_INCR = GL_INCR_WRAP_EXT;
STENCIL_DECR = GL_DECR_WRAP_EXT;
}

FLOAT4 Light;
Set4F(Light , Scene.Light[0].Position );

// SETUP
glEnable (GL_STENCIL_TEST); // Abilito lo stencil test
glStencilFunc(GL_ALWAYS,0,~0);
glDepthFunc (GL_LESS);
glColorMask (GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); // Non scrivo sul buffer colore
glDepthMask (GL_FALSE); // Non scrivo sul buffer di profondita'
for( i=0; i<ShadowPipeSize; i++)
{
if (ShadowPipe[i]>=0)
{
if (Capping( Plane , Scene.Obj[ShadowPipe[i]].Center ))
{
glCullFace(GL_FRONT);
glStencilOp( GL_KEEP, STENCIL_INCR, GL_KEEP );
DrawShadowVolume( Scene.Obj[ShadowPipe[i]] , Light , TRUE);

glCullFace(GL_BACK);
glStencilOp( GL_KEEP, STENCIL_DECR, GL_KEEP );
DrawShadowVolume( Scene.Obj[ShadowPipe[i]] , Light , TRUE);
}

else{
glCullFace(GL_BACK);
glStencilOp( GL_KEEP, GL_KEEP, STENCIL_INCR );
DrawShadowVolume( Scene.Obj[ShadowPipe[i]] , Light , FALSE);

glCullFace(GL_FRONT);
glStencilOp( GL_KEEP, GL_KEEP, STENCIL_DECR );
DrawShadowVolume( Scene.Obj[ShadowPipe[i]] , Light , FALSE);
}
}
}
// FINAL
glColorMask (GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); // Scrittura del colore
glDepthFunc (GL_EQUAL); // Disegno solo cio' che e' uguale
glStencilOp (GL_KEEP,GL_KEEP,GL_KEEP); // Non modifico lo stencil
glStencilFunc (GL_LESS, 0, ~0);
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
// glColor4fv( Scene.Light[0].Color );
glEnable ( GL_BLEND);
// glBlendFunc ( GL_ONE, GL_ONE);
glBlendFunc ( GL_SRC_COLOR , GL_SRC_ALPHA );
glCullFace(GL_BACK);

//----------------------------------------------------------------------
_Object CObj;

for( i=0; i<PipeSize; i++)
{
if(Pipeline[i]>=0)
{
CObj = Scene.Obj[Pipeline[i]];
if ( CObj.Entity<0) Draw( CObj , DETAIL_GEOM );
}
}

glPushMatrix();
for( i=0; i<Scene.NEntity; i++)
{
if ( Scene.Entity[i].Visible )
{
glTranslatef( Scene.Entity[i].Trasl[0],
Scene.Entity[i].Trasl[1],
Scene.Entity[i].Trasl[2] );

glRotatef( Scene.Entity[i].Rot[1],0,1,0 );

for( int j=0 ; j<Scene.Entity[i].NObjPtr; j++)
{
if (Scene.Entity[i].ObjPtr[j]->Visible)
Draw( *Scene.Entity[i].ObjPtr[j] , DETAIL_GEOM );
}
}
}
glPopMatrix();
//----------------------------------------------------------------------

glCullFace(GL_BACK);
glDisable ( GL_BLEND);
glDisable(GL_STENCIL_TEST); // Ripristino la situazione
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}





void __inline DrawShadowVolume( _Object Obj , float *Light , BOOL DrawCap)
{
const register unsigned int *b = &amp;Obj.Profile[Obj.NProfile-1];
register unsigned int *a = &amp;Obj.Profile[0];
FLOAT4 L;
L[0] = -Light[0];
L[1] = -Light[1];
L[2] = -Light[2];
L[3] = -1;

glBegin( GL_TRIANGLES );
for( ;a<b; )
{
glVertex4fv( Scene.VBuffer[*a].Coord); a++;
glVertex4fv( Scene.VBuffer[*a].Coord); a++;
glVertex4fv(L);
}
glEnd();
if(!DrawCap) return;

int i = Obj.NTriangle;
glBegin( GL_TRIANGLES );
while(i--)
{
GLuint *j = Obj.Wire[i].Edge;

if (Obj.Plane[i].Light)
{
glVertex3fv( Scene.VBuffer[ *j ].Coord ); *j++;
glVertex3fv( Scene.VBuffer[ *j ].Coord ); *j++;
glVertex3fv( Scene.VBuffer[ *j ].Coord );
}
else{
glVertex4f( Scene.VBuffer[ *j ].Coord[0] - *Light,
Scene.VBuffer[ *j ].Coord[1] - Light[1],
Scene.VBuffer[ *j ].Coord[2] - Light[2],0);

glVertex4f( Scene.VBuffer[ *j ].Coord[0] - *Light,
Scene.VBuffer[ *j ].Coord[1] - Light[1],
Scene.VBuffer[ *j ].Coord[2] - Light[2],0);

glVertex4f( Scene.VBuffer[ *j ].Coord[0] - *Light,
Scene.VBuffer[ *j ].Coord[1] - Light[1],
Scene.VBuffer[ *j ].Coord[2] - Light[2],0);
}
}
glEnd();
}



ok..that's all! http://www.opengl.org/discussion_boards/ubb/smile.gif

Frenz
07-17-2003, 09:25 AM
Ok!! It was a problem with the projection matrix and the far plane..thanks to all!
Bye