Skip to main content
gamedev.net
🔒 Locked

Stencil decalling and performance

Started by RealityMonster 2 replies 750+ views
Original Post
RealityMonster
RealityMonster
Hi, wondering if you guys can give me some pointers (pun unintended , am using C#/CsGL) on this issue... My app renders a carpark scene with tons of pillars. Now, I need to add signs as decals to most of these pillar faces. The way im currently doin it is using Stencil Decaling.
quote:
GL.glEnable(GL.GL_STENCIL_TEST); GL.glStencilFunc(GL.GL_ALWAYS, 1, 1); GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_REPLACE);
Draw Poly to be stencilled
quote:
GL.glStencilFunc(GL.GL_EQUAL, 1, 1); GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ); GL.glEnable(GL.GL_BLEND);
Draw decal
quote:
GL.glDisable( GL.GL_BLEND ); GL.glDisable( GL.GL_STENCIL_TEST );
The problem is I have to clear the stencil buffer at the beginning of this code and this code has to be repeated for all pillars (~100). This drops my FPS from 60 to 30. If i dont clear, FPS is back up but got artefacts coz the stencil buffer now contains all the pillar faces as stencils. Any advice would be appreciated. Thnx.
lc_overlord
lc_overlord
sollution: don''t use the stencil buffer.

step 1. render the pillars
step 2. run this code
glPolygonOffset(0,-1);
glEnable(GL_POLYGON_OFFSET);
glDepthMask(GL_FALSE);
step 3. render the decals with full alphablending and all the stuff you require.
step 4. finaly run this
glPolygonOffset(0,0);
glDisable(GL_POLYGON_OFFSET);
glDepthMask(GL_TRUE);

my guess is that if this works it will run slightly faster then your current code.

---------------------------------
For an overdose of l33tness, flashbang.nu
Krohm
Krohm
quote:
Original post by lc_overlord
sollution: don''t use the stencil buffer.

I agree on that while I would point out that this is where multitexturing comes to the rescue instead of alpha blending.

By the way, polygon offset is not needed anyway since GL guarantees to be invariant. Poly off is needed when using different GL states (for example render-wire or xform to light-eye space). It should be not needed for a simple multitexturing task (unless something serious is changing in the GL state).
Previously "Krohm"
lc_overlord
lc_overlord
quote:
Original post by Krohm
By the way, polygon offset is not needed anyway since GL guarantees to be invariant.


Actualy, it's not, it has to do with the way 3d harware calcylate the z value.
It is normaly interpolated between the verices(the correct way is to derive the z value from the polygons plane, but they are to lazy), this may produce an roundoff error in some cases(normaly when two polygons share the same plane but different size), that round off error is normaly called z-fighting.
Polygon offset eliminates this problem by rendering the decals one unit infront of the allready renderd polygons.

Edit: note that two polygons sharing the same vertics allso produce the same round off errors and will thus not create z fighting.



---------------------------------
For an overdose of l33tness, flashbang.nu

[edited by - lc_overlord on May 7, 2004 9:14:31 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.