PDA

View Full Version : Transparent textures issue



VinceGL
06-30-2011, 02:49 AM
Hi, I currently have some problems with transparent textures, when I render the scene they hide some of my models and unit.

I think it's the same problem than here : viewtopic.php?f=43&t=3368 (http://www.khronos.org/message_boards/viewtopic.php?f=43&t=3368)

But the solution doesn't work in my case.

Here some examples:
http://img204.imageshack.us/img204/5787/transparentissue1.png
http://img811.imageshack.us/img811/6505/transparentissue2.png

And my code:

this.context = this.element.getContext("experimental-webgl",{
alpha: false,
depth: true,
stencil: false,
antialias: false,
premultipliedAlpha: false
});

gl.clearColor( 0.0, 0.0, 0.0, 1.0);
gl.clearDepth( 1.0 );

gl.enable( gl.DEPTH_TEST );
gl.depthFunc( gl.LEQUAL );

gl.enable( gl.BLEND );
gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );

For each frames:
gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT );


I will be very happy to fix this weird thing... Thanks in advance !

Radamanthe
07-02-2011, 11:57 PM
Try this.

Before rendering transparent stuffs:
gl.colorMask(true, true, true, false);And restore the state just after:
gl.colorMask(true, true, true, true);
This fixed my problem with semi-transparency, but it may be the same issue somehow. Please, let me know if it fixes your problem.

VinceGL
07-04-2011, 02:11 AM
Hi, thank you for the answer :)

I tested with the following code :

var textures = this.MODELS.textures;
for ( var i in textures ) {
if ( textures[i].alpha ) {
gl.colorMask(true, true, true, false);
gl.bindTexture( gl.TEXTURE_2D, textures[i].image );
gl.drawArrays( gl.TRIANGLES, textures[i].vertIndex, textures[i].vertLen );
gl.colorMask(true, true, true, true);
}
else {
gl.bindTexture( gl.TEXTURE_2D, textures[i].image );
gl.drawArrays( gl.TRIANGLES, textures[i].vertIndex, textures[i].vertLen );
}
}

But it doesn't fixed the bug.

Is it possible that this bug is due to the fact that i don't use Normal vectors ? ( I don't calculate them yet...).

VinceGL
07-04-2011, 02:30 AM
Well, I find a solution:

In the fragment shader:
if ( texture.a ) discard;
I don't think it's the better way to do this, but it work.

I'm allways open for other ways.