OpenGL Transparency

Discussions regarding Materials, Material-Compounds or Shaders, etc.
Post Reply
Squizmek
Posts: 53
Joined: 11 Jul 2009, 13:13
Skype: squizmek

OpenGL Transparency

Post by Squizmek » 01 Dec 2009, 19:29

Hi all!

I'm trying to make an OpenGL shader that will allow drawing several polygons with alphamaps behind each other.
Transparency in OpenGL is a basic problem. Read more on it here: http://www.opengl.org/wiki/Transparency_Sorting
I think any of those tricks described on the wiki would be perfect!
Changing the texture modulation and the blending parameters of the OGLAlphaTrans node didn't give any good results.
I have tried adding some code snippets into a basic GLSL shader, but it just gives me errors, and I have no OpenGL experience :(
The fact that my netview is broken (only links to autodesk site) since XSI 7.0 doesn't help at all...

My question is: Can someone with a little OpenGL experience come up with (or direct me to) a shader that discards transparent pixels when writing to the z-buffer? Or any other fix for the transparency?
On the wiki this is mentioned:

Code: Select all

glAlphaFunc ( GL_GREATER, 0.1 ) ;
glEnable ( GL_ALPHA_TEST ) ;
Any help is much appreciated!
-Michael

Squizmek
Posts: 53
Joined: 11 Jul 2009, 13:13
Skype: squizmek

Re: OpenGL Transparency

Post by Squizmek » 03 Dec 2009, 14:43

Nobody able to help?
A DirectX shader would work too! I tried the "MaxViewportShader 1.1" and the shading works, but not the transparency :(

nassosy
Posts: 81
Joined: 02 Oct 2009, 23:50
Location: Greece
Contact:

Re: OpenGL Transparency

Post by nassosy » 03 Dec 2009, 15:41

to set the fragment color you can use something like this:

Code: Select all

gl_FragColor = texture2D(color_texture, gl_TexCoord[0].st);
and to set the depth based on the alpha use something like :

Code: Select all

if ( gl_FragColor.a < 1.0 )
{
   // set it to the greatest depth
   gl_FragDepth = gl_DepthRange.far;
}

nassosy
Posts: 81
Joined: 02 Oct 2009, 23:50
Location: Greece
Contact:

Re: OpenGL Transparency

Post by nassosy » 03 Dec 2009, 15:43

the "gl_FragColor", "gl_FragDepth" and "gl_DepthRange" are predefined

nassosy
Posts: 81
Joined: 02 Oct 2009, 23:50
Location: Greece
Contact:

Re: OpenGL Transparency

Post by nassosy » 03 Dec 2009, 15:45

I forgot to mention that the code i posted goes into a Fragment shader. :D

Squizmek
Posts: 53
Joined: 11 Jul 2009, 13:13
Skype: squizmek

Re: OpenGL Transparency

Post by Squizmek » 03 Dec 2009, 19:36

I found out that the polyons get sorted by their ID if they're all in one mesh, so the trick is to have the higher IDs near the camera and the lower IDs in the background.

It seems like XSI doesn't do any depth-sorting by itself.... what a pity :-w

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests