<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Blending mode for additive lighting</title>
		<link>http://www.allegro.cc/forums/view/617642</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 02 Dec 2018 00:09:55 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>HURRY. A.CC IS FAST. ANSWER MY QUESTION.</p><p>I draw all my tiles and then, I draw &quot;light&quot; rectangles for each tile with this blender:</p><p>	al_set_blender(ALLEGRO_BLEND_OPERATIONS.ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ALPHA);</p><p>In retrospect, I&#39;m almost certain I didn&#39;t even need it. (I think I&#39;m just inverting black and white.) </p><p>What&#39;s the right one (or steps) for creating a lighting pass, where unless I draw &quot;light&quot; to this buffer, I get complete darkness?</p><p>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?</p><p>I don&#39;t have relevant image examples but its like this left image:</p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/4/e43343cc13f700335b8b446467b03276-240.jpg" alt="Color_add_subtract_450.jpg" width="240" height="180" /></span></p><p>or maybe I should be using MULTIPLICATIVE lighting per this second image?:</p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/6/d65454164423691dc730a10473ba13cb-240.jpg" alt="2sHjXGr.png" width="240" height="192" /></span></p><p>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.</p><p>I wonder if shadows can be drawn the same way, or I should use a third pass / buffer for shadows?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Thu, 29 Nov 2018 09:41:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First draw a shadow mask buffer with additive lighting then draw your Shadow mask over your backbuffer with multiplicative blending.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 29 Nov 2018 10:05:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I read your post and it seems like techno babble.</p><p>Then I read a few hours of articles and I come back and go &quot;Hmm, yeah, basically.&quot;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sat, 01 Dec 2018 06:04:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For what it&#39;s worth, in my code it looks like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k2">[</span>draw stage here<span class="k2">]</span>
<a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ONE<span class="k2">)</span><span class="k2">;</span>
<span class="k2">[</span>draw shadows here<span class="k2">]</span>
<a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA<span class="k2">)</span><span class="k2">;</span>
<span class="k2">[</span>draw lighting here<span class="k2">]</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (princeofspace)</author>
		<pubDate>Sat, 01 Dec 2018 11:34:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="https://www.allegro.cc/forums/thread/617642/1040287#target">Chris Katko</a> said:</div><div class="quote"><p>
I read your post and it seems like techno babble.</p><p>Then I read a few hours of articles and I come back and go &quot;Hmm, yeah, basically.&quot;
</p></div></div><p>

Mathematically, it&#39;s the only thing that makes sense. The multiply blender ;<br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_ADD , ALLEGRO_DEST , ALLEGRO_ZERO<span class="k2">)</span><span class="k2">;</span></span><br />Takes src*dest + 0*dest and gives you src darkened by the dark areas in dest. Anywhere your shadow mask is white, it will &#39;show through&#39;. Anywhere it is colored, it will tint whatever is behind it.</p><p>Additive lighting is the only thing that can make things lighter.</p><div class="quote_container"><div class="title"><a href="https://www.allegro.cc/forums/thread/617642/1040289#target">princeofspace</a> said:</div><div class="quote"><p>
For what it&#39;s worth, in my code it looks like this:</p><p>[draw stage here]<br />al_set_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ONE);<br />[draw shadows here]
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA<span class="k2">)</span><span class="k2">;</span>
<span class="k2">[</span>draw lighting here<span class="k2">]</span>
</pre></div></div><p>
</p></div></div><p>
How does the premultiplied alpha blender draw lights? By drawing partially opaque white? That works.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 01 Dec 2018 19:22:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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&#39;t remember why I came to this process. I think I read about I here on this forum!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (princeofspace)</author>
		<pubDate>Sun, 02 Dec 2018 00:09:55 +0000</pubDate>
	</item>
</rss>
