Reputation: 788
I'm using a simple shader to do a vignette transition effect in my game on each screen load (picked up from this book). I use this transition effect in my menu screens. All is well with the exception that my fadeIn , fadeOut animations that I apply to the buttons of the menu don't have any effect with this added shader; in fact no alpha value has any effect on any actor on the screen when I use this shader.
Here's the vertex shader:
...
gl_Position = u_projTrans * a_position;
v_texCoord = a_texCoord0;
v_color = a_color;
And the fragment shader:
...
vec4 texColor = texture2D(u_texture, v_texCoord);
...
gl_FragColor = vec4(texColor.r, texColor.g, texColor.b, texColor.a);
How can I fix the alpha issue so actors render the alpha properly with the shader ?
Maybe the fragment blow will work? But how do I set the alpha for every actor of the screen?
uniform float ALPHA;
...
gl_FragColor = vec4(texColor.r, texColor.g, texColor.b, texColor.a * ALPHA);
Upvotes: 0
Views: 149
Reputation: 93601
Fade animations utilize the alpha of the vertex color. This is passed into SpriteBatch which passes it to the vertex shader as a_color
. Your vertex shader already passes the color to the fragment shader as v_color
, so in your fragment shader, you need to multiply the final alpha by this fade value:
Fragment shader:
varying LOWP vec4 v_color;
//...
gl_FragColor = vec4(texColor.r, texColor.g, texColor.b, texColor.a * v_color.a);
Upvotes: 1