I am using this masking texture for a dynamic lighting effect in my game: enter image description here

It looks beautiful until two lights begin to overlap:

edsmage description here

This is obviously because the textures are overlapping when I draw them to the light map FrameBuffer.


                for(Entity ent : entities){
                    if(ent instanceof Fireball)g.draw(light,ent.x - tlightSize / 2.5f,ent.y - tlightSize * 0.25f, tlightSize, tlightSize);
            if(p instanceof FireCharacter){
                g.draw(light,p.x - lightSize / 2.5f,p.y - lightSize * 0.25f, lightSize, lightSize);


I use the buffer texture from this map when I draw my actual game:'

lightFbo.getColorBufferTexture().bind(1); //u_lightmap
//draw things

I don't want these to overlap, I want the light circles to merge without the border cutting in front of them. I tried making the black transparent in GIMP on the light texture but that made no difference. Here is the lighting shader:

Vertex Shader

attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 vColor;
varying vec2 vTexCoord;

void main() {
    vColor = a_color;
    vTexCoord = a_texCoord0;
    gl_Position = u_projTrans * a_position;     

Fragment Shader

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#define LOWP

varying LOWP vec4 vColor;
varying vec2 vTexCoord;

//texture samplers
uniform sampler2D u_texture; //diffuse map
uniform sampler2D u_lightmap;   //light map (frame buffer texture)

//additional parameters for the shader
uniform vec2 resolution; //resolution of screen
uniform LOWP vec4 ambientColor; //ambient RGB, alpha channel is intensity 

void main() {
vec4 diffuseColor = texture2D(u_texture, vTexCoord);
vec2 lighCoord = (gl_FragCoord.xy / resolution.xy);
vec4 light = texture2D(u_lightmap, lighCoord);

vec3 ambient = ambientColor.rgb * ambientColor.a;
vec3 intensity = ambient + light.rgb;
vec3 finalColor = diffuseColor.rgb * intensity;

gl_FragColor = vColor * vec4(finalColor, diffuseColor.a);

My only ideas are using Gdx.gl.glSetBlendFunc(); and changing the blending source and dest values.


1 Answer 1


Okay so I solved it:

1. Make sure glEnable(GL20.GL_BLEND_COLOR); is on and the blend function is Gdx.gl.glBlendFunc(GL20.GL_BLEND_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA);

2. Edit the light texture in something like GIMP to double check that your background is transparent.

3. MOST IMPORTANT Make sure the lightFramebuffer is Format.RGBA4444 or Format.RGBA8888 to support transparency.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .