libgdx god's ray shader effect blending function

817 views Asked by At

I am trying to create a god's ray effect from scratch using libgdx and opengl shader langage. To do this I use a background image as light source, then I apply another texture as a mask setting the spriteBatch color to full black.

background texture

original image

mask texture

mask

the mask is then rendered in full black over the background

mask over background

    Color batchColor = batch.getColor();
    fbo1.begin();
        batch.begin();
            batch.draw(textureBackground, 0, 0, w, h);
            batch.setColor(Color.BLACK);
            batch.draw(textureBar, 0, 0, w, h);
            batch.setColor(batchColor);
        batch.end();
    fbo1.end();

then the god's ray shader is applied

rendered ray

Sprite rayEffect = new Sprite(fbo1.getColorBufferTexture());
rayEffect.flip(false, true);

fbo2.begin();
    batch.setShader(shaderGodRay);
    batch.begin();
        rayEffect.draw(batch);
    batch.end();
    batch.setShader(null);
fbo2.end();

The rays are ok at this stage. Know I would like to blend the original mask color with the rendered rays in order to obtain the final image. Only rendering the mask again on top of the rays are totally overlapped by the colored mask

with color

    rayEffect = new Sprite(fbo2.getColorBufferTexture());
    rayEffect.flip(false, true);

    batch.begin();
        rayEffect.draw(batch);
        batch.draw(textureBar, 0, 0, w, h);
    batch.end();

I think alpha blending should do the trick, but on my ray rendered image, the opacity is full. Does someone know how I may blend the two texture together in order to obtain the desired final result?

0

There are 0 answers