Page 1 of 1

Trying to get ambience on purely transparent polygons

Posted: Tue Apr 11, 2006 12:59 pm
by CuteAlien
Not sure if this is possible, because i failed so far doing it, but maybe someone has an idea:
I have a model with material type EMT_TRANSPARENT_ALPHA_CHANNEL. My textures have pixels where the r,g,b compontent is set to 0, so only the alpha component should be used. I'd like it to be shown with the color of the current ambient light, but slightly transparent (depending on the value of the alpha channel). Transparence itself does worked and so did ambience on non-transparent areas, but i couldn't get it to use the ambient color at transparent positions. Has someone of you done something similar already and can help me?

Posted: Tue Apr 11, 2006 1:16 pm
by Baal Cadar
Well, actually this should work with EMT_TRANSPARENT_ALPHA_CHANNEL, Material ambient set to white and the texture set to all white instead of all black.

Else this can be done easily with a pixel shader.
For instance GLSL (from the top of my head, might contain errors):

Code: Select all

uniform sampler2D alpha_tex;
void main()
{
    vec4 t = texture2D(alpha_tex, gl_TexCoord[0].st);
    gl_FragColor.rgb = gl_LightModel.ambient.rgb;
    gl_FragColor.a = t.a
}
Maybe I don't just understand you correctly. Provide pictures for what you want and what you get instead.

Posted: Tue Apr 11, 2006 2:26 pm
by CuteAlien
Thanks, that worked. I checked my code after that again and found out that my ambience colors where inverted when loading the .obj file and it does work now also in my code :)

Posted: Tue Apr 11, 2006 2:52 pm
by hybrid
Yes, obj files have inverted colors. Use my objmtl.patch to fix this problem.

Posted: Tue Apr 11, 2006 3:00 pm
by CuteAlien
hybrid wrote:Yes, obj files have inverted colors. Use my objmtl.patch to fix this problem.
Hm, i've posted to that already in the other thread ;). Somehowthe patch works for me only if i remove the part where the colors are inverted.

Posted: Tue Apr 11, 2006 3:11 pm
by hybrid
:lol: Oh, it was you :lol:
Ok, so maybe I have to change it then, and check if my example models were wrong?!