I’m trying to place a partially transparent png texture on a 3d model of a white mug (openGL Material).
The scene has
openGL material that has default settings for white material (with alpha =1)
texture Env -> MODULATE
the texture is a standard 32bit png (photoshop) that has a couple of colored stripes and 1 transparent stripe behind the black text in the middle.
blending function used:
problem: as soon as there is transparency in the png, i loose my complete material and the background of the drawing area becomes visible. (light blue),
in the fully transperent part (see image, behind the black text) the material of the mug dissappears
How is this possible? If SrcAlpha=0 then it DestAlpha should be 1-0 = 1 ?
Also, in pink part, this is a 25% transparent layer in the png texture; again the material dissappears here; since you see the blue-ish background shining through the pink…
Somebody any idea what i’m missing?
Is it even possible to have a lighting+transparent texture+materials combined?
The source colour is the product of the texture colour and the lighting colour.
The destination colour is whatever was in the framebuffer immediately before rendering the primitive (e.g. the background colour).
Blending blends the source colour and the destination colour based (in this case) upon the source (i.e. texture) alpha.
If you want the texture to appear “over” the material, you need to either:
a) use two passes, first without the texture and without blending, then with the texture, with blending, using GL_MODULATE and a white material.
b) “bake” the material into the texture, so that the transparent pixels become the material colour and are opaque, then render without blending, or
c) use a fragment shader which blends the texture colour with the material colour based upon the texture’s alpha value, then uses the result as the material colour for the lighting calculation (or at least, for the diffuse lighting calculation; specular lighting should probably ignore both the material and texture colours).
Thanks that clarified a lot!
I went with a combination of option a & b.
- making the transparent pixels the material color (i.e. white or red) when i preprocess the texture
- then use MODULATE with a white material such that the color values transfer the lighting.
I have tested it with white as a material, but i think it should work for other colors as well with lighting