PDA

View Full Version : GL_ATI_separate_stencil



Marcos Zini
04-18-2003, 06:02 AM
I am trying to render shadow volumes in a single pass using ATI's separate stencil ext but it's currently not working. I am using the zpass approach.

Here's part of my rendering loop:

glDepthMask( GL_FALSE );
glEnable( GL_STENCIL_TEST );
glColorMask( 0, 0, 0, 0 );

glPushMatrix();
glMultMatrixf( lModel.mData );

if ( gSeparateStencilATI )
{
glStencilFuncSeparateATI( GL_ALWAYS, GL_ALWAYS, 1, 0xffffffff );

glStencilOpSeparateATI( GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR );
glStencilOpSeparateATI( GL_BACK, GL_KEEP, GL_KEEP, GL_DECR );
gModel.draw_shadow_volume( lLocalLight );
}
else
{
glStencilFunc( GL_ALWAYS, 1, 0xffffffff );

// First pass
glFrontFace( GL_CCW );
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
gModel.draw_shadow_volume( lLocalLight );

// Second pass
glFrontFace( GL_CW );
glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
gModel.draw_shadow_volume( lLocalLight );
}
glPopMatrix();

GLDrawScreenQuad();

And here's GLDrawScreenQuad...

///////////////////////////////////////////////////////////////////////
void
GLDrawScreenQuad()
{
// 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 );

glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glOrtho( 0, 640, 0, 480, -100, 100 );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

glBegin( GL_QUADS );
glVertex2d( 0, 0 );
glVertex2d( 640, 0 );
glVertex2d( 640, 480 );
glVertex2d( 0, 480 );
glEnd();

glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();

glDisable( GL_BLEND );
}


The two-pass path works but the extension path doesn't. It looks like it's trying to work but not quite. Can anybody help?

I thank you in advance

PH
04-18-2003, 06:12 AM
These should work...

glStencilOpSeparateATI( GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT );
glStencilOpSeparateATI( GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT );

Edit:
Oh, and disable face culling too...

[This message has been edited by PH (edited 04-18-2003).]

V-man
04-18-2003, 02:16 PM
I'm not familiar with this extension, but it looks like EXT_stencil_two_side.
Why not use that?

NitroGL
04-18-2003, 05:09 PM
Originally posted by V-man:
I'm not familiar with this extension, but it looks like EXT_stencil_two_side.
Why not use that?

Because ATI doesn't/can't support it.

Marcos Zini
04-18-2003, 05:50 PM
Thanks PH, you answer was dead on! I totally forgot to disable culling. It works like a champ now.

As for EXT_stencil_two_side, I do intend to add support for that. It's just that I've yet to lay my eyes on a GeforceFX card. I don't even know anybody that has one.

--Marcos