Triangle overlap + transparency

Started by
4 comments, last by V-man 13 years, 1 month ago
I am trying to solve an annoying problem with my transparency
I only need to have the main character fade out so I used glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Which works great to blend my character with the background over a period of 5 seconds
but you can clearly see individual triangles inside the characters back causing weird artifacts
I am guessing this is due to the fact that triangle order is messed up.

I am a bit confused at what I could try to do to solve this.

Order indpependant transparency? seems a bit too much to implement for a single transparent object

triangle sorting in shader somehow? I dont have access to triangles outside of shader due to the fact I am using a library that handles animation

Some unknown opengl setting that could fix it?

Orthographic projection?

Screw it and just delete the entire fading out code?

Anyone know what to do?
Advertisement
Do you have backface culling turned on? If not, that should eliminate most of the tris you are seeing thru the model. Otherwise you would need to sort the tri's from front to back and you mentioned you don't have access to these. Sorting would be really expensive anyway...
Render the character to a completely different texture by itself, apply that texture (on a quad) over the scene (don't render the character to the scene). You can then fade that single quad out without any sorting or messing with the character itself. So:

Render scene as normal (without the character)
Render character by themselves at full opacity to some render target (of screen texture).
Render that texture on a quad over the scene with the desired transparency.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Nanoha's method would work. Another way is you could draw the character once with a 0 alpha (you just want to write depth values), then draw the character again over top of that with GL_EQUAL as your depth test, this way you dont have to sort triangles as the 2nd drawing has to match the first one (only triangles you see anyway). Never tried it though.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

You can also do a two passes rendering. First you render the environment without your character, then only the character with backface culling as BuffaloJ has suggested.
I don't recommend ever using glEnable (GL_LINE_SMOOTH), glEnable (GL_POLYGON_SMOOTH) and glEnable (GL_POINT_SMOOTH), if you are using them.
http://www.opengl.org/wiki/Common_Mistakes#GL_POINTS_and_GL_LINES
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement