Blending mode for additive lighting
Chris Katko

HURRY. A.CC IS FAST. ANSWER MY QUESTION.

I draw all my tiles and then, I draw "light" rectangles for each tile with this blender:

al_set_blender(ALLEGRO_BLEND_OPERATIONS.ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ALPHA);

In retrospect, I'm almost certain I didn't even need it. (I think I'm just inverting black and white.)

What's the right one (or steps) for creating a lighting pass, where unless I draw "light" to this buffer, I get complete darkness?

Should I have two separate buffers? A lighting buffer, and a tile buffer, draw to them both (allowing multiple lights) and then combine them at the end?

I don't have relevant image examples but its like this left image:

{"name":"Color_add_subtract_450.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/4\/e43343cc13f700335b8b446467b03276.jpg","w":450,"h":339,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/4\/e43343cc13f700335b8b446467b03276"}Color_add_subtract_450.jpg

or maybe I should be using MULTIPLICATIVE lighting per this second image?:

{"name":"2sHjXGr.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d65454164423691dc730a10473ba13cb.png","w":1280,"h":1024,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d65454164423691dc730a10473ba13cb"}2sHjXGr.png

Either way, the more I think about it, the more I believe I need a second lighting buffer, that is then combined together at the end.

I wonder if shadows can be drawn the same way, or I should use a third pass / buffer for shadows?

Edgar Reynaldo

First draw a shadow mask buffer with additive lighting then draw your Shadow mask over your backbuffer with multiplicative blending.

Chris Katko

I read your post and it seems like techno babble.

Then I read a few hours of articles and I come back and go "Hmm, yeah, basically."

princeofspace

For what it's worth, in my code it looks like this:

[draw stage here]
al_set_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ONE);
[draw shadows here]
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
[draw lighting here]

Edgar Reynaldo

I read your post and it seems like techno babble.

Then I read a few hours of articles and I come back and go "Hmm, yeah, basically."

Mathematically, it's the only thing that makes sense. The multiply blender ;
al_set_blender(ALLEGRO_ADD , ALLEGRO_DEST , ALLEGRO_ZERO);
Takes src*dest + 0*dest and gives you src darkened by the dark areas in dest. Anywhere your shadow mask is white, it will 'show through'. Anywhere it is colored, it will tint whatever is behind it.

Additive lighting is the only thing that can make things lighter.

For what it's worth, in my code it looks like this:

[draw stage here]
al_set_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ONE);
[draw shadows here]

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
[draw lighting here]

How does the premultiplied alpha blender draw lights? By drawing partially opaque white? That works.

princeofspace

Yeah, for the pixel art games I make, it gives me the look I want. It also makes it easier (for me, anyway) for drawing primitives as dynamic lighting sources. To be honest, though, I wrote this code a while back, and don't remember why I came to this process. I think I read about I here on this forum!

Thread #617642. Printed from Allegro.cc