TGE OpenGL Perfomance Issue!!!! (Alpha Testing)
by Prairie Games · in Torque Game Engine · 10/05/2002 (2:39 pm) · 8 replies
TGE isn't currently set up to do efficient GL_ALPHA_TESTING... there is also no option in the art pipeline to specify alpha testing for MESHES, INTERIORS, or PARTICLES..
For things like trees, grass, fencing, and other times when you have A LOT of alpha...
glDisable(GL_BLEND); //<---- DON'T USE BLENDING
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //<--- DON'T MODULATE
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST); //<---- DO ALPHA TEST
When blending is NEEDED and _ONLY_ then... use something like:
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//and if you want use an alpha test too ...usually a good idea :)
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);
-J
For things like trees, grass, fencing, and other times when you have A LOT of alpha...
glDisable(GL_BLEND); //<---- DON'T USE BLENDING
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //<--- DON'T MODULATE
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST); //<---- DO ALPHA TEST
When blending is NEEDED and _ONLY_ then... use something like:
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//and if you want use an alpha test too ...usually a good idea :)
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);
-J
#2
developer.nvidia.com/docs/IO/1313/ATT/Alphatest_tricks.pdf
From the document:
Alpha Test Definition
Alpha test is one operation in the Per-fragment Operations stage (See Fragment
Processing Overview diagram on Page 2) of the OpenGL pipeline that allows any further
processing of the fragment to be aborted based on the value of its alpha component. The
fragment's alpha component is compared with an application-specified reference value
using an application-specified comparison function. If the fragment passes the test, it will
be processed by the subsequent fragment operation, otherwise it will be discarded. Alpha
test does not incur any extra overhead even if all the fragments pass the test. Unlike
stencil testing, depth testing, texturing, and blending, alpha testing do not involve
fetching data from memories external to the GPU. Alpha Test is only available in RGBA
mode.
How does Alpha Test impact the rendering?
Alpha Test provides a great way to save fill rate. When used to draw alpha blended
textures, or to do additive blending in multi-pass, it provides a means to reject the
fragment as early as possible in order to reduce the memory traffic due to stencil, depth,
and color buffer reads and writes.
-J
10/05/2002 (10:03 pm)
Here is a good document on the matter, with some benhmark results on a GForce3... I have seen MASSIVE differences under varying hardware/driver combinations... this also affects D3D rendering... developer.nvidia.com/docs/IO/1313/ATT/Alphatest_tricks.pdf
From the document:
Alpha Test Definition
Alpha test is one operation in the Per-fragment Operations stage (See Fragment
Processing Overview diagram on Page 2) of the OpenGL pipeline that allows any further
processing of the fragment to be aborted based on the value of its alpha component. The
fragment's alpha component is compared with an application-specified reference value
using an application-specified comparison function. If the fragment passes the test, it will
be processed by the subsequent fragment operation, otherwise it will be discarded. Alpha
test does not incur any extra overhead even if all the fragments pass the test. Unlike
stencil testing, depth testing, texturing, and blending, alpha testing do not involve
fetching data from memories external to the GPU. Alpha Test is only available in RGBA
mode.
How does Alpha Test impact the rendering?
Alpha Test provides a great way to save fill rate. When used to draw alpha blended
textures, or to do additive blending in multi-pass, it provides a means to reject the
fragment as early as possible in order to reduce the memory traffic due to stencil, depth,
and color buffer reads and writes.
-J
#4
Though, I think I noticed you didn't turn blending off? Perhaps as an option? This may make a difference too... the more hints you can give the card/driver the better...
Most the time with foliage I would say a cutout without blending would be fine...
It would even be possible to autodetect this by examing the alpha component of a texture ... all (0.0,1.0) and you know you don't need to blend...
-J
10/06/2002 (7:06 am)
Yuppers..Though, I think I noticed you didn't turn blending off? Perhaps as an option? This may make a difference too... the more hints you can give the card/driver the better...
Most the time with foliage I would say a cutout without blending would be fine...
It would even be possible to autodetect this by examing the alpha component of a texture ... all (0.0,1.0) and you know you don't need to blend...
-J
#5
Blending is used for foliage fade-in/out and as such is required although it would be an easy modification to turn-blending off if the foliage item was not in a blend-in/out state.
The are so many little optimisations that could take place with my objects plus ones in the engine that it nearly keeps me up a night. 8)
- Melv.
10/06/2002 (10:33 am)
Joshua,Blending is used for foliage fade-in/out and as such is required although it would be an easy modification to turn-blending off if the foliage item was not in a blend-in/out state.
The are so many little optimisations that could take place with my objects plus ones in the engine that it nearly keeps me up a night. 8)
- Melv.
#6
I slapped in your patch for the particle engine, and disabled the original code. When I start the mission, everything looks right. Then, I select a weapon, and press fire - that's when everything breaks.
Here's what it looks like (compressed pic, so it's uglier than it really is - but, you'll notice that the black billowing clouds of the nuke are white, and the landscape HARFS completely.)
Modified Particle Rendering
So, what unintelligent thing did I do wrong here?
10/06/2002 (1:46 pm)
Ok, now I've got a really stupid question... ;-)I slapped in your patch for the particle engine, and disabled the original code. When I start the mission, everything looks right. Then, I select a weapon, and press fire - that's when everything breaks.
Here's what it looks like (compressed pic, so it's uglier than it really is - but, you'll notice that the black billowing clouds of the nuke are white, and the landscape HARFS completely.)
Modified Particle Rendering
So, what unintelligent thing did I do wrong here?
#7
@Davis ... restore your render state once you are done with it ... turn the alpha testing off etc... there are examples in the source...
Cheers,
-J
10/06/2002 (3:30 pm)
@Melv, indeed I wan't considering the blend in and out.. which is quite nice... at full blend in, just turn blend off :)@Davis ... restore your render state once you are done with it ... turn the alpha testing off etc... there are examples in the source...
Cheers,
-J
#8
Here is the change I made in particleEngine.cc:
03/10/2003 (3:58 pm)
When I tried to change this - I also got some weird looking particles as in the screenshot above. Here is the change I made in particleEngine.cc:
//glEnable(GL_BLEND); glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); glAlphaFunc(GL_GREATER,0.1f); glDepthMask(GL_FALSE);
Torque Owner Davis Ray Sickmon, Jr
Default Studio Name