PDA

View Full Version : Fragment shader + alpha bending problem...



wizardcoder
05-27-2017, 11:18 AM
Hi,

I have a problem, I use shader to mix 3 textures (YUV) to generate a RGBA color with A forced to 1.0 and I use an other shader to render texture with alpha RGBA.

If two triangles render with second shader is overlapped i have a pretty transparency.

if i have a triangle with transparency render over a triangle using YUV to RGB, the transparent is done on background (in my case black- i try to change black to red to verify).

Could you help me ?

Thanks,

PS: I can send screen shoot by e-mail if need, i don't have web server to host it...

The shader for YUV:
---------------------

uniform sampler2D texPlane0; // Y.
uniform sampler2D texPlane1; // U.
uniform sampler2D texPlane2; // V.
varying vec2 varTexCoord;
void main()
{
float fY = 1.164 * ( texture2D ( texPlane0, varTexCoord ).r - 0.0625 );
float fU = texture2D ( texPlane1, varTexCoord ).r - 0.5;
float fV = texture2D ( texPlane2, varTexCoord ).r - 0.5;
gl_FragColor = vec4 ( fY + 1.793 * fV, fY - 0.213 * fU + 0.533 * fV, fY + 2.112 * fU, 1.0);
}


I use this shader for other texture (RGBA):

uniform sampler2D texPlane;
varying vec2 varTexCoord;
void main()
{
gl_FragColor = texture2D ( texPlane, varTexCoord );
}


I use this code on OpenGL ( and OpenGLES with a different header) :
---------------------------------------------------------------------------

glEnable ( GL_DEPTH_TEST );
glEnable ( GL_CULL_FACE );
glFrontFace ( GL_CW );
glEnable ( GL_BLEND );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );


Render loop :
---------------

glClearColor ( 0.0F, 0.0F, 0.0F, 1.0F );
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

... render mesh ...