<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Tonight, there will be shadows</title>
		<link>http://www.allegro.cc/forums/view/615966</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 08 Feb 2016 12:07:34 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have a goal tonight to get real-time shadows into my 3D arsenal.</p><p>Specifically, I&#39;ll be running through <a href="http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/">this tutorial</a>.</p><p>I believe I have everything else setup and have a good shot. I&#39;ll be keeping an update log here, so please comment generously so I&#39;m not stuck updating my last post with edits? Thanks!</p><p>Ok, first order of business...  I need a nice simple &quot;world&quot; model that is good for checking shadows, so I&#39;m off to blender to throw something together.</p><p><b>EDIT 1</b><br />Alright, I&#39;ve got a little scene created: <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><br /><span class="remote-thumbnail"><span class="json">{"name":"609994","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/3\/1392ef2fa90a3440378ac3799f6ad9ee.png","w":1440,"h":900,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/3\/1392ef2fa90a3440378ac3799f6ad9ee"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/3/1392ef2fa90a3440378ac3799f6ad9ee-240.jpg" alt="609994" width="240" height="150" /></span></p><p><b>EDIT 2</b><br />Okie dokie, The model is now working correctly inside the program and a good camera angle.<br /><span class="remote-thumbnail"><span class="json">{"name":"609995","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/f\/0f0a2facd89010537ab74a4ec6d14d7c.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/f\/0f0a2facd89010537ab74a4ec6d14d7c"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/0/f/0f0a2facd89010537ab74a4ec6d14d7c-240.jpg" alt="609995" width="240" height="164" /></span></p><p><b>EDIT 3</b><br />To keep things focused on just-get-things-working, I grabbed the <span class="source-code">glm::</span> header files that are used in the tutorial to build the ortho transform for the light projection.  Thanks to <a href="https://www.allegro.cc/forums/thread/615958">Elias&#39; cool new feature</a>, I was able to peruse the code much more easily and skim-check if there were any conflicts between the <span class="source-code">glm</span> matrix and Allegro&#39;s <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a></span>.  So far no red flags. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p><b>EDIT 4</b><br />Alrightie, the difficulty curve has shot up.  There are conflicts between my OpenGL/GLSL/version_numbers/Allegro/the_tutorial/my_knowledge_of_anything.  For one reason or another, I am unable to create a framebuffer with this simple code (the <span class="source-code">glCheckFramebufferStatus</span> line keeps sending me to <span class="source-code"><span class="s">"glCheckFrambufferStatus == FALSE"</span></span>) <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> :
</p><div class="spoiler"><p>
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>GLuint FramebufferName <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  2</span>  <span class="k1">bool</span> initialize<span class="k2">(</span><span class="k2">)</span>
<span class="number">  3</span>  <span class="c">//bool make_shadow_texture()</span>
<span class="number">  4</span>  <span class="k2">{</span>
<span class="number">  5</span>    <span class="c">// The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.</span>
<span class="number">  6</span>    glGenFramebuffers<span class="k2">(</span><span class="n">1</span>, <span class="k3">&amp;</span>FramebufferName<span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>    glBindFramebuffer<span class="k2">(</span>GL_FRAMEBUFFER, FramebufferName<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"FramebufferName=="</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> FramebufferName <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>    <span class="c">// Depth texture. Slower than a depth buffer, but you can sample it later in your shader</span>
<span class="number"> 11</span>    GLuint depthTexture<span class="k2">;</span>
<span class="number"> 12</span>    glGenTextures<span class="k2">(</span><span class="n">1</span>, <span class="k3">&amp;</span>depthTexture<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    glBindTexture<span class="k2">(</span>GL_TEXTURE_2D, depthTexture<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"depthTexture=="</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> depthTexture <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 15</span>    glTexImage2D<span class="k2">(</span>GL_TEXTURE_2D, <span class="n">0</span>,GL_DEPTH_COMPONENT, <span class="n">1024</span>, <span class="n">1024</span>, <span class="n">0</span>,GL_DEPTH_COMPONENT, GL_FLOAT, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>    glTexParameteri<span class="k2">(</span>GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>    glTexParameteri<span class="k2">(</span>GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>    glTexParameteri<span class="k2">(</span>GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    glTexParameteri<span class="k2">(</span>GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span>    glFramebufferTexture<span class="k2">(</span>GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>    glDrawBuffer<span class="k2">(</span>GL_NONE<span class="k2">)</span><span class="k2">;</span> <span class="c">// No color buffer is drawn to.</span>
<span class="number"> 24</span>
<span class="number"> 25</span>    <span class="c">// Always check that our framebuffer is ok</span>
<span class="number"> 26</span><span class="p">###    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)</span>
<span class="number"> 27</span>    <span class="k2">{</span>
<span class="number"> 28</span>      std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"glCheckFrambufferStatus == FALSE"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 29</span>      <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 30</span>    <span class="k2">}</span>
<span class="number"> 31</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"glCheckFrambufferStatus == TRUE"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 32</span>    <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 33</span>  <span class="k2">}</span>
</div></div><p>
</p></div><p>To keep moving what I might have to do is just create a shader on an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a></span> that draws the depth in RGB.  more investigation to continue...</p><p><b>EDIT 5</b><br />Also, to anybody who&#39;s interested, the tutorial&#39;s shaders have <span class="source-code"><span class="p">#version 330 core</span></span> at the top, and upon compiling the shader I get the message &quot;ERROR: version 330 is unavailable&quot;</p><p><b>EDIT 6</b><br />Wooohf!  I finally made some headway.  This whole time I was having difficulty drawing to an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a></span>; It was coming out blank.  It turns out it was because the object(s) I was trying to draw (the scene model from earlier) was not being drawn in both views, despite me having created the infrastructure.  The static world model was considered a &quot;special case&quot; in the engine and not included in the list of entities to render in all views.  Good news is, now I have 2 projections with different rendering methods working simultaniously. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Camera View:<br /><span class="remote-thumbnail"><span class="json">{"name":"609996","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/8\/a8c99f72a570e25a16f175efc680c5df.png","w":1920,"h":1200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/8\/a8c99f72a570e25a16f175efc680c5df"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/8/a8c99f72a570e25a16f175efc680c5df-240.jpg" alt="609996" width="240" height="150" /></span><br />Light Projection View:<br /><span class="remote-thumbnail"><span class="json">{"name":"609997","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/d\/ad607aced189ead5c93e1a1f58029b56.png","w":1920,"h":1200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/d\/ad607aced189ead5c93e1a1f58029b56"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/d/ad607aced189ead5c93e1a1f58029b56-240.jpg" alt="609997" width="240" height="150" /></span><br />Depth is right around the corner. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 03 Jan 2016 10:47:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s going on here... <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /><img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 03 Jan 2016 13:53:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A cacophony of stream-of-concious efforts. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>When attempting to render to my depth-view, the depth test is somehow exactly flipped.<br /><span class="remote-thumbnail"><span class="json">{"name":"609998","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/f\/8f41682a891e29552ab1a2b433c82782.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/f\/8f41682a891e29552ab1a2b433c82782"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/f/8f41682a891e29552ab1a2b433c82782-240.jpg" alt="609998" width="240" height="164" /></span></p><p>I&#39;m even at the point now where I&#39;m getting glitch art: <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /><br /><span class="remote-thumbnail"><span class="json">{"name":"609999","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac088e791935043a4c1d615704677eed.png","w":1044,"h":706,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac088e791935043a4c1d615704677eed"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/c/ac088e791935043a4c1d615704677eed-240.jpg" alt="609999" width="240" height="162" /></span></p><p>It looks like the shadows won&#39;t arrive for another day.  Perhaps my weary body will be better equipped after a nights rest.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 03 Jan 2016 14:54:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If this turns out to be good, we should put it on the wiki.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gideon Weems)</author>
		<pubDate>Mon, 04 Jan 2016 13:37:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So, the challenge continues!</p><p>In discouragement at being unfamiliar with rendering to a strict depth buffer, I decided to just create a simple shader that would draw depth to an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a></span>.  What I did was pass into the shader the real-world-position of the camera, and calculate <span class="source-code">distance<span class="k2">(</span><span class="k2">)</span></span> to the real-world-position of the vertex.  It worked... ish:<br /><span class="remote-thumbnail"><span class="json">{"name":"610003","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/c\/5c5a4fe173e1b736e52c3676515892b8.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/c\/5c5a4fe173e1b736e52c3676515892b8"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/c/5c5a4fe173e1b736e52c3676515892b8-240.jpg" alt="610003" width="240" height="164" /></span><br />Darker colors represent being closer to the camera, while lighter colors are further.</p><p>But why is the floor white?  My theory is that since I was calculating the distance to each <i>vertex</i>, glsl was calculating that the four corners of the bottom plane were at a far distance from the camera, and then interpolating those values to fill in the rest of the geometry.</p><p>At that point I realized that the camera&#39;s position is already (0,0,0) in the shader after the <span class="source-code">al_porjview_matrix</span> is multiplied to the object in the shader, and I could avoid having to calculate a million <span class="source-code">distance<span class="k2">(</span><span class="k2">)</span></span> formulas, which are really slow.  <i>And</i> the depth value that I need is already in the 4th component of the shader&#39;s <span class="source-code">gl_Position</span>.</p><p>I coded it in, and it worked!<br /><span class="remote-thumbnail"><span class="json">{"name":"610004","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/0\/2001f9c79772db6044463ddb07d8f73e.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/0\/2001f9c79772db6044463ddb07d8f73e"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/0/2001f9c79772db6044463ddb07d8f73e-240.jpg" alt="610004" width="240" height="164" /></span><br />This is the actual depth data that I need (but to make it more visible, I had to multiply it by 0.05 because my view frustum is verrrrry deep.  When I make it a frustum for the light projection, it probably won&#39;t need to be nearly as deep)</p><p>So much more to do! <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 04 Jan 2016 23:05:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That stuff is pretty cool Mark !
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Tue, 05 Jan 2016 03:26:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Ok, it looks like I have run into a problem.  When drawing to an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a></span> <b>that is not the backbuffer</b> (or a subbitmap of the backbuffer), the depth sorting gets all messed up.  This is what the scene looks like when drawn per the usual way:</p><p><b>Normal</b>:<br /><span class="remote-thumbnail"><span class="json">{"name":"610013","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/4913504c602951bba4ca578bd0e2597b.png","w":1920,"h":1200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/4913504c602951bba4ca578bd0e2597b"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/4/9/4913504c602951bba4ca578bd0e2597b-240.jpg" alt="610013" width="240" height="150" /></span></p><p><b>Depth Shader When Drawn On Backbuffer</b>: - Looks good, everything appears to work out.<br /><span class="remote-thumbnail"><span class="json">{"name":"610014","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/3\/33555fec41d7a9b9a45bdf7da92db8a0.png","w":1920,"h":1200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/3\/33555fec41d7a9b9a45bdf7da92db8a0"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/3/33555fec41d7a9b9a45bdf7da92db8a0-240.jpg" alt="610014" width="240" height="150" /></span></p><p><b>Depth Shader On A Target Bitamp (that is NOT a Backbuffer)</b>: - EEKS!<br /><span class="remote-thumbnail"><span class="json">{"name":"610015","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/b\/fb200f6810fbbe86d5dd3af9b9dc2457.png","w":1920,"h":1200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/b\/fb200f6810fbbe86d5dd3af9b9dc2457"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/b/fb200f6810fbbe86d5dd3af9b9dc2457-240.jpg" alt="610015" width="240" height="150" /></span></p><p>I&#39;m not sure what&#39;s causing this problem.  Any ideas?  I&#39;ll try it without using a shader.</p><p><b>EDIT 1</b><br />Oh well interesting, it also has the same problem when not using the shader.</p><p><b>Normal Drawing on a Target Bitmap (that is NOT a Backbuffer)</b>: - Also EEKS!<br /><span class="remote-thumbnail"><span class="json">{"name":"610016","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/2\/3265897c395bce43dd6e5a87da48da33.png","w":1920,"h":1200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/2\/3265897c395bce43dd6e5a87da48da33"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/2/3265897c395bce43dd6e5a87da48da33-240.jpg" alt="610016" width="240" height="150" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 05 Jan 2016 06:33:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m guessing it&#39;s because only the backbuffer has a Z-buffer.  A regular bitmap is just a flat matrix of pixels, where would you store the depth info?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Tue, 05 Jan 2016 09:22:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s possible for a bitmap to have a z buffer, but Allegro provides no means to create this. See <a href="https://github.com/liballeg/allegro5/issues/477">https://github.com/liballeg/allegro5/issues/477</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 05 Jan 2016 13:47:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615966/1018778#target">Bruce Pascoe</a> said:</div><div class="quote"><p>I&#39;m guessing it&#39;s because only the backbuffer has a Z-buffer. A regular bitmap is just a flat matrix of pixels, where would you store the depth info?</p></div></div><p>
Did not know that.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615966/1018784#target">SiegeLord</a> said:</div><div class="quote"><p>It&#39;s possible for a bitmap to have a z buffer, but Allegro provides no means to create this. See <a href="https://github.com/liballeg/allegro5/issues/477">https://github.com/liballeg/allegro5/issues/477</a>.</p></div></div><p>
Would use!  I was wondering why offscreen bitmaps don&#39;t have multi-sampling.</p><p>Either way...
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>backbuffer<span class="k2">)</span><span class="k2">;</span>
setup_projection<span class="k2">(</span>light<span class="k2">)</span><span class="k2">;</span>
draw_the_depth_pass<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>depth_pass_surface<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>backbuffer<span class="k2">)</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>backbuffer<span class="k2">)</span><span class="k2">;</span>
<span class="c">// ... continue on as if nothing happened</span>
</pre></div></div><p>
Nothing will stop me! &gt;:E</p><p>---</p><p>Also, incidentally, I noticed something wrong with the depth image:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610019","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5ed9bfd99b90353c0d61df97ea97252e.png","w":941,"h":575,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5ed9bfd99b90353c0d61df97ea97252e"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/e/5ed9bfd99b90353c0d61df97ea97252e-240.jpg" alt="610019" width="240" height="146" /></span></p><p>I thought there was something wrong with my depth algorithm, so I looked into it and it turns out the geometry was messed up. The cone was hovering above the plane by about 0.2:<br /><span class="remote-thumbnail"><span class="json">{"name":"610021","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/6\/96cb22eaf7ad1c7e8e38bcd800cd3e14.gif","w":396,"h":211,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/6\/96cb22eaf7ad1c7e8e38bcd800cd3e14"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/6/96cb22eaf7ad1c7e8e38bcd800cd3e14-240.jpg" alt="610021" width="240" height="127" /></span></p><p>So I fixed that:<br /><span class="remote-thumbnail"><span class="json">{"name":"610022","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/acce09e40629957190cb98e10404bfb6.png","w":727,"h":473,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/acce09e40629957190cb98e10404bfb6"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/c/acce09e40629957190cb98e10404bfb6-240.jpg" alt="610022" width="240" height="156" /></span></p><p>---</p><p>Ok. I&#39;m excited to finally have a (sort of) depth map!  Next up we should see <i>some</i> semblance of shadows. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 05 Jan 2016 21:22:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That hovering cone reminds me of old 90s CGI cartoons (e.g. Beast Wars) where it often looked like the characters were walking just above the ground.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Wed, 06 Jan 2016 03:52:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I owe you guys an update <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><p>I have achieved semblance of shadows!</p><p>This was the very first time where all the components are accounted for!</p><p><span class="remote-thumbnail"><span class="json">{"name":"610023","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/b\/3bdde501683c89772d8f8f4ddb782497.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/b\/3bdde501683c89772d8f8f4ddb782497"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/b/3bdde501683c89772d8f8f4ddb782497-240.jpg" alt="610023" width="240" height="164" /></span></p><p>Everything&#39;s all out of wack, but it&#39;s all in there.  All that&#39;s left is to work out the math <i>just inside the shader</i>.  I added a bunch of little floating objects to make the depth more palatable.  Note that this is not actual shadows mapped, rather it&#39;s the depth image just plastered onto the models as if it were a regular plain old texture map.<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/8/18766165b7bcee012843f2230e294082.gif" alt="610024" width="240" height="148" /><br />The floating things are just reflective AllegroFlare logos.</p><p>It&#39;s cool &#39;cause if you look at the floor you can see that the rotating logos have &quot;shadows&quot; that are also rotating as well.</p><p>That&#39;s where it all started.</p><p>After that, I needed to make sure the <span class="source-code"><span class="n">0</span>.<span class="n">05</span></span> that I multiplied to the depth wouldn&#39;t be a problem.</p><p><span class="remote-thumbnail"><span class="json">{"name":"610025","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/5\/5581400a6160bb752680d37874f00768.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/5\/5581400a6160bb752680d37874f00768"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/5/5581400a6160bb752680d37874f00768-240.jpg" alt="610025" width="240" height="164" /></span><br />^This is me checking that the light depth and camera depth data are not being confused with each other.  In this image, the darker pixels represent smaller distance to the <i>light source</i>.  So this shows that the light source is on the other side of the camera and that data is separate from the active viewing angle.  It also shows that the value ranges for the light depth and camera depth are (essentially) the same.</p><p>Good. Everything is in order.</p><p>Now it&#39;s time to calculate an <i>actual</i> shadow map onto the scene.</p><p>And finally, without further ado, here is the <b>first</b> image showing an actual shadow projection:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610026","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/5\/653de59d8f8b43741cf4b39030ce9efe.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/5\/653de59d8f8b43741cf4b39030ce9efe"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/5/653de59d8f8b43741cf4b39030ce9efe-240.jpg" alt="610026" width="240" height="164" /></span></p><p>All screwed up. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><p>If you look carefully, you can see that the texture is looping for some reason.  So somewhere the UV mapping coordinates are scaled incorrectly.  So I scale them by some multiple:<br /><span class="remote-thumbnail"><span class="json">{"name":"610027","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/8\/f830b1d3919a5aa5396799de48bd3f77.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/8\/f830b1d3919a5aa5396799de48bd3f77"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/8/f830b1d3919a5aa5396799de48bd3f77-240.jpg" alt="610027" width="240" height="164" /></span><br />^ Oops! wrong direction. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> I multiplied when I should have divided.</p><p><span class="remote-thumbnail"><span class="json">{"name":"610028","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/47b33701eed38d4c6ef16abc33ef3f18.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/47b33701eed38d4c6ef16abc33ef3f18"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/4/7/47b33701eed38d4c6ef16abc33ef3f18-240.jpg" alt="610028" width="240" height="164" /></span><br />Cool, but the alignment is off, too.  So I put in 2 dials to let me offset the texture:<br /><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=C2pIBhIVbbA" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/0/1/01d50685f06ebd8646552d0ae34fd25d.jpg" border="0" alt="video" title="Click to play video" /></a></div></div></p><p>At this point I create a bunch of <a href="https://www.allegro.cc/files/attachment/610029">cool abstract art</a>. But it&#39;s still a little tough to se what&#39;s going on so I put in some crappy texturing to get a better sense of space and depth:</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=hZAx-6PYMGM" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/1/6/163fb89721f752c341a86ee257d0fe9f.jpg" border="0" alt="video" title="Click to play video" /></a></div></div></p><p>It&#39;s so close.  <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />  It looks like the depth calculation is correct - shadows are deforming onto the geometry correctly.  It&#39;s cool how it working and not working at the same time.  It&#39;s just that there is something amis with the actual <i>projection</i> itself.</p><p>... <i>until next time</i> ... <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 06 Jan 2016 13:41:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is a fun and interesting read! Please never stop ☺
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc ( Arvidsson)</author>
		<pubDate>Wed, 06 Jan 2016 13:46:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Moar ! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 06 Jan 2016 16:21:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is great and quite like the updates.  I would definitely support ($$) an Allegro 3D solution even if free or low cost alternatives exist.</p><p>Will you consider integrating <a href="https://github.com/assimp/assimp">https://github.com/assimp/assimp</a> for model loading?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ks)</author>
		<pubDate>Wed, 06 Jan 2016 18:49:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>On the other hand, you are 300% over schedule and not finished yet. <b>Work harder, Oates.</b> </p><p><img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Wed, 06 Jan 2016 18:57:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wanted to add that when trying to correctly align the light texture into the scene, one method I tried was to place the camera and the light at the exact same position.  In theory, this would allow me to tinker with the UV position and scale, and see when the shadow projection and scene were in sync:<br /><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=sS3UomSZJ-s" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/e/1/e19da4cc6184255596d5f081bd2cf50b.jpg" border="0" alt="video" title="Click to play video" /></a></div></div><br />^ This is the light and the camera placed and viewing the scene from the exact same position, both are rotating around the scene together in sync.<br /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> Looks cool <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />  Unfortunately, it didn&#39;t prove to be as useful as I had thought so I went back to separate locations.</p><p>Also, I found out that you cannot make your own variables in GLSL with a <span class="source-code">gl_<span class="k3">*</span></span> prefix.  I tried naming a variable <span class="source-code">gl_Position_from_light</span> and got this wonderful work of bow tie art:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610030","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/2\/c2f20f42e902ab1b24665329980c5306.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/2\/c2f20f42e902ab1b24665329980c5306"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/c/2/c2f20f42e902ab1b24665329980c5306-240.jpg" alt="610030" width="240" height="164" /></span></p><p>and an error message that read <span class="source-code">ERROR: <span class="n">0</span><span class="k2">:</span><span class="n">13</span><span class="k2">:</span> Identifier name <span class="s">'gl_Position_from_light'</span> cannot start with <span class="s">'gl_'</span></span></p><p>Anyway, that&#39;s all in the past.</p><p>---</p><p>This is where we are now.  As you can see by the end of the video, we&#39;re <b>so close</b>!<br /><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=0EUGhG0Ty5g" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/4/0/40e8ec0e7ce4f2061ae181582617c3e0.jpg" border="0" alt="video" title="Click to play video" /></a></div></div><br />Ahgh! So close you can almost taste it! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>If you look closely at how the shadows are distorting, you can see that all the shadows seem to be bending inward towards the back, rather than outward.  <b>I think the reason is because I am using a <i>perspective projection</i> for the light, when I should be using an <i>orthographic projection</i>.</b>  It&#39;s as if the shadows at the center are OK, but further on the edge of the camera, they seem to bend in and shrink towards the back, like what would happen in a <i>perspective projection</i>.</p><p>So, if I &quot;unproject&quot; that perspective distortion...</p><p>Eh? What do you think? <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 06 Jan 2016 21:46:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I dunno, if you&#39;re simulating nearby a point light, then a projective transformation makes sense. If you&#39;re simulating a far away light, then orthographic would be fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 10 Jan 2016 01:43:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615966/1018818#target">Mark Oates</a> said:</div><div class="quote"><p> ERROR: 0:13: Identifier name &#39;gl_Position_from_light&#39; cannot start with &#39;gl_&#39;</p></div></div><p>What sort of pre-processor magic makes this possible?  It reminds me of printf-related warnings.  The pre-processor sometimes comments about invalid format strings.</p><p>Will you be able to do <a href="https://en.wikipedia.org/wiki/Checker_shadow_illusion">this</a> in real time?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gideon Weems)</author>
		<pubDate>Wed, 13 Jan 2016 12:44:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I always assumed it was the compiler that generated the printf warnings.  In that case it&#39;s just a matter of looking at the arguments of a printf() call--since the compiler already knows how to read the grammar--and parsing the format string.  I would assume it&#39;s similar to how JS treats eval() differently depending on whether it&#39;s actually called as &quot;eval&quot; versus through an alias.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Wed, 13 Jan 2016 21:40:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>And he answered them not, but raised his eyes to the heavens, saying &quot;Tonight, there will be shadows, threads shall be locked, and Phipps shall return.&quot;</p></div></div><p>

<i>From the Gospel of St Mark of Oates, 12:28</i>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Thu, 14 Jan 2016 04:24:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Who is this Phipps guy anyway?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Thu, 14 Jan 2016 06:00:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK!  Just got back from a wedding cruise and have had time to work on this puppy.  I won&#39;t reveal to the end, but things are working and the shadows are straight up <i>sexy</i>.</p><p><span class="remote-thumbnail"><span class="json">{"name":"610039","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/1\/919015bc88e1531f2762f3b98e1d92c1.gif","w":320,"h":240,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/1\/919015bc88e1531f2762f3b98e1d92c1"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/1/919015bc88e1531f2762f3b98e1d92c1-240.jpg" alt="610039" width="240" height="180" /></span></p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615966/1018880#target">SiegeLord</a> said:</div><div class="quote"><p> I dunno, if you&#39;re simulating nearby a point light, then a projective transformation makes sense. If you&#39;re simulating a far away light, then orthographic would be fine.</p></div></div><p>A perspective transform <i>should</i> work.  In the tutorial, it uses a ortho transform, but there is another later section that says if you want to use a perspective transform then (...) and I didn&#39;t read that part.  So, I dove into trying to fix it by switching back to ortho and it worked.</p><p>Sort of.</p><h1>Part 1: Getting to the Orthographic Projection</h1><p>

It took awhile to get the ortho transform in place, since you can&#39;t just simply swap out <span class="source-code">al_perspective_transform</span> with <span class="source-code">al_orthographic_transform</span>.  Here&#39;s what it looked like when I just swapped them out:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610040","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/2\/325764e7f3f265cf3cedae492d098931.png","w":2088,"h":1412,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/2\/325764e7f3f265cf3cedae492d098931"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/2/325764e7f3f265cf3cedae492d098931-240.jpg" alt="610040" width="240" height="162" /></span></p><p>When I looked closer, I could see these tiiiiiiiiny pixels in the top left of the frame, which happens to be the whole scene:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610041","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/d\/3d9c20c9baa9479e8af8346d93921211.png","w":1761,"h":1184,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/d\/3d9c20c9baa9479e8af8346d93921211"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/d/3d9c20c9baa9479e8af8346d93921211-240.jpg" alt="610041" width="240" height="161" /></span></p><p>The whole scene be about 10 &#39;units&#39; wide in geometry, which in iso projection is about 10 pixels. So, I had to scale it up and center it to match the view I had previously:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610042","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/9\/29fd0732ac80de482dfc1f28147ae4c7.png","w":1072,"h":734,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/9\/29fd0732ac80de482dfc1f28147ae4c7"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/9/29fd0732ac80de482dfc1f28147ae4c7-240.jpg" alt="610042" width="240" height="164" /></span></p><p>Awesome.</p><p>I ended up using the exact same ortho projection for the light <i>and</i> the scene, but from different viewing angles.  That way I wouldn&#39;t have to worry about possible inconsistencies when merging the two projections for a shadow.</p><p>Ok, here&#39;s the interesting part.  Notice that in the upper right corner (that&#39;s the light&#39;s view depth map) that the entire scene is black?  This happened when I switched to ortho mode.</p><p>Something new is up with the depth z-values, so I tried a bunch of different things to see what I could get out of the pixel data.  I tried curving the brightness of the colors in a bunch of different ways...</p><p><span class="remote-thumbnail"><span class="json">{"name":"610045","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/0\/504d0ad0c7f3b899178d8f619cb611fd.png","w":390,"h":250,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/0\/504d0ad0c7f3b899178d8f619cb611fd"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/0/504d0ad0c7f3b899178d8f619cb611fd-240.jpg" alt="610045" width="240" height="153" /></span></p><p>...but found out that the z values were all flat <span class="source-code"><span class="n">0</span>.<span class="n">0</span></span>.</p><p>Not sure what to do next, I tried <i>just on a whim</i> drawing only using the <i>green</i> color component (e.g. <span class="source-code">rgba<span class="k2">(</span>color.g, color.g, color.g, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span></span> ) and this came out:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610043","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/1\/51736cd62cf09204188e0cbe1b2929b0.png","w":396,"h":250,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/1\/51736cd62cf09204188e0cbe1b2929b0"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/1/51736cd62cf09204188e0cbe1b2929b0-240.jpg" alt="610043" width="240" height="151" /></span></p><p>Well that&#39;s kinda strange.  Previously, I was only using the <span class="source-code">color.a</span> component, since the z-value for the pixel is stored in there (e.g. <span class="source-code">rgba<span class="k2">(</span>color.a, color.a, color.a, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span></span> ).  Why now, would the green value just produce a simple gradient?  So I investigated further and drew the image with proper colors <span class="source-code">rgba<span class="k2">(</span>color.r, color.g, color.b, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span></span>:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610044","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/2\/825b3b086a6f53e28185958cf2e761e6.png","w":386,"h":248,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/2\/825b3b086a6f53e28185958cf2e761e6"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/2/825b3b086a6f53e28185958cf2e761e6-240.jpg" alt="610044" width="240" height="154" /></span></p><p>Strange again, I&#39;m not sure what&#39;s going on in this picture... but... if you look reeeeeealy closely, you can see some very faint shapes in the RGBA render.  Very very faint, and they appear to be in the blue part of the image.</p><p><img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> It turns out, when using an <i>orthographic</i> projection, depth values are stored in the <i>3rd</i> color component - blue.  Instead of RGBA (or XYZD), it&#39;s RGB (XYD).  It makes sense; there&#39;s no need to transform a z value once it&#39;s in orthographic projection.  The only coordinates you would need are x, y, and depth.  So here&#39;s the light projection drawn using only the 3rd color component <span class="source-code">rgba<span class="k2">(</span>color.b, color.b, color.b, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span></span>.</p><p><span class="remote-thumbnail"><span class="json">{"name":"610046","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/1\/a14b6f39d7ecb193a1f67fbdbc024666.png","w":386,"h":248,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/1\/a14b6f39d7ecb193a1f67fbdbc024666"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/1/a14b6f39d7ecb193a1f67fbdbc024666-240.jpg" alt="610046" width="240" height="154" /></span></p><p>With a bit of texture position tweaking, the shadow mapping lines up! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /> <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><p><span class="remote-thumbnail"><span class="json">{"name":"610047","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/e\/dec51f7ad187aadb39c1fb90213509a8.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/e\/dec51f7ad187aadb39c1fb90213509a8"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/e/dec51f7ad187aadb39c1fb90213509a8-240.jpg" alt="610047" width="240" height="164" /></span></p><p>When everything is lined up there&#39;s really bad &quot;shadow acne&quot; but who cares!!  It works!!!</p><p><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><h1>Part 2: Getting Rid of the Noise</h1><p>

The hard part is over, from this point on it&#39;s a battle of filtering out shadow noise, and I ended up using a solution of my own (not mentioned in the tutorial).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Will you be able to do this [en.wikipedia.org] in real time?</p></div></div><p>Funny you mentioned that actually.  As I was trying to figure out shadows, it was a bit difficult to see what was going on with the checker texture (because of that exact &quot;checker shadow illusion&quot;) so I swapped out with a grass texture.</p><p>By filtering out for the &quot;shadow acne&quot; noise, at best I was able to get it to look like this:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610051","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/b\/9b45cb1f05ba2048a93c64e20f0df9c5.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/b\/9b45cb1f05ba2048a93c64e20f0df9c5"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/b/9b45cb1f05ba2048a93c64e20f0df9c5-240.jpg" alt="610051" width="240" height="164" /></span></p><p>and at worst it looked like this:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610050","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/c\/1cf54b72c86767024373f9bf21aef071.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/c\/1cf54b72c86767024373f9bf21aef071"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/c/1cf54b72c86767024373f9bf21aef071-240.jpg" alt="610050" width="240" height="164" /></span></p><p>If you look closely, the worst-case-scenario-stripes-pattern is isolated to geometry that is facing <i>away</i> from the light, so to catch this case I ended up using a combination of plain-old-school shading <i>combined</i> with the casted shadows.</p><p>Here&#39;s the scene rendered with plain-old-school shading.  This uses the light&#39;s point as the source and does not have a falloff for distance.  Essentially, a plane is brighter when it&#39;s facing the light, and darker as it turns away:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610049","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/d\/ad5d4226c6e0f5c52458447a0a3b668a.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/d\/ad5d4226c6e0f5c52458447a0a3b668a"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/d/ad5d4226c6e0f5c52458447a0a3b668a-240.jpg" alt="610049" width="240" height="164" /></span></p><p>Then I curve it, so it&#39;s either black or white.  Anything above <span class="source-code"><span class="n">0</span>.<span class="n">5</span></span> is pushed to <span class="source-code"><span class="n">1</span>.<span class="n">0</span></span> and anything below it is pushed to <span class="source-code"><span class="n">0</span>.<span class="n">0</span></span>.  Looks like this:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610052","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/1\/e1fd1a06674fadabb496d17469aad88e.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/1\/e1fd1a06674fadabb496d17469aad88e"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/1/e1fd1a06674fadabb496d17469aad88e-240.jpg" alt="610052" width="240" height="164" /></span></p><p>Then I combine this shading data with the previous shadow map, using only the darkest colors (works by simply multiplying <span class="source-code">color1 <span class="k3">*</span> color2</span>).  Looks like this:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610053","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/d\/ddf07087cf8e8fcc09def2f6e4e252d2.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/d\/ddf07087cf8e8fcc09def2f6e4e252d2"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/d/ddf07087cf8e8fcc09def2f6e4e252d2-240.jpg" alt="610053" width="240" height="164" /></span></p><p>All I have to do now is nicely blend the shadow with the normal shading of the scene and...</p><p><span class="remote-thumbnail"><span class="json">{"name":"610054","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/3\/a38c86de60c12dffc6dd73bc58d82de1.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/3\/a38c86de60c12dffc6dd73bc58d82de1"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/3/a38c86de60c12dffc6dd73bc58d82de1-240.jpg" alt="610054" width="240" height="164" /></span></p><p><b>...that is the first actual fully properly shadow mapped scene.</b>  And, it turns out that when I change the camera&#39;s projection to perspective, it worked without a hitch!! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p><span class="remote-thumbnail"><span class="json">{"name":"610055","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3e7e0f06aeee66f34b812a9cc7857c9e.png","w":2144,"h":1468,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3e7e0f06aeee66f34b812a9cc7857c9e"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/e/3e7e0f06aeee66f34b812a9cc7857c9e-240.jpg" alt="610055" width="240" height="164" /></span></p><p>(notice it renders the skybox now that the projection is perspective.)</p><h1>Part 3: The Future</h1><p>

I started combining the shadows with different colors, and several different materials and shaders:</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=6LOKdz_E8KM" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/4/1/4137732527e620a176ffc7f92b9ddfa7.jpg" border="0" alt="video" title="Click to play video" /></a></div></div></p><p>Things are starting to get serious:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610058","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/b\/1b9068ce0865585b9a43c2b6b38083b7.png","w":1642,"h":946,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/b\/1b9068ce0865585b9a43c2b6b38083b7"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/b/1b9068ce0865585b9a43c2b6b38083b7-240.jpg" alt="610058" width="240" height="138" /></span></p><p><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 17 Jan 2016 09:42:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That last shot looks awesome.  Who knew Allegro could do full 3D (as opposed to 2.5D)?  Not me! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 17 Jan 2016 11:42:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Mark you rock.</p><p>Edit: This really is awesome.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 18 Jan 2016 04:35:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>WOW, thats pretty awsome, any chance you could do a full idiots guide tutorial for it <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />. I would love to be able to do a lot of that stuff.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (duncan perham)</author>
		<pubDate>Thu, 21 Jan 2016 21:05:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This ^^</p><p>It would be awesome if you could write some kind of guide to creating shadows.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 22 Jan 2016 07:27:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Really really remarkable, as in Mark&#39;s standards.</p><p>That&#39;s some serious 3D!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (pkrcel)</author>
		<pubDate>Sat, 23 Jan 2016 04:07:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I&#39;m going to eventually need to do everything he&#39;s done so far. It&#39;d be great to see a tutorial / write-up. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sat, 23 Jan 2016 18:18:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s a nice little tutorial series.  Just checked it out myself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Fri, 29 Jan 2016 10:18:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nice work. Have you played around with Blender&#39;s water/soft body simulation physics? It&#39;s pretty neat. It takes a beast of a cpu to render, though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BitCruncher)</author>
		<pubDate>Mon, 01 Feb 2016 05:59:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I never really tried doing 3D with Allegro, but this makes me reconsider it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sun, 07 Feb 2016 08:22:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615966/1019734#target">Neil Roy</a> said:</div><div class="quote"><p>I never really tried doing 3D with Allegro, but this makes me reconsider it.</p></div></div><p>
Awesome! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>I want to create a nice clean tutorial that walks through Allegro in 3D.  Something where, by the end of the first 2 paragraphs or so you have a foolproof 3D view already setup.  The foundations are <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a></span> and <span class="source-code">al_perspective_transform<span class="k2">(</span><span class="k2">)</span></span>.  Wrapping all of that into a clean tutorial that&#39;s enjoyable and stupid easy would be a lot of fun.</p><p>I should listen to the sloth:<br /><span class="remote-thumbnail"><span class="json">{"name":"610165","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/f\/afa23a6dd56a0297faf6af2870a61e5d.gif","w":260,"h":146,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/f\/afa23a6dd56a0297faf6af2870a61e5d"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/f/afa23a6dd56a0297faf6af2870a61e5d-240.jpg" alt="610165" width="240" height="134" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 07 Feb 2016 09:33:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615966/1019736#target">Mark Oates</a> said:</div><div class="quote"><p>I want to create a nice clean tutorial that walks through Allegro in 3D. Something where, by the end of the first 2 paragraphs or so you have a foolproof 3D view already setup. The foundations are ALLEGRO_VERTEX and al_perspective_transform(). Wrapping all of that into a clean tutorial that&#39;s enjoyable and stupid easy would be a lot of fun.</p></div></div><p>

That would be really nice.  I have done some things with 3D, but none of it uses shaders, just the old style OpenGL stuff.  I just recently FINALLY learned how to use shaders and was surprised that they were simpler to use that I thought, it&#39;s just now I need to unlearn what I learned about opengl previously! <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>I done a simple, blocky style City3D (before Minecraft, I didn&#39;t know I was ahead of my time back then <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> )... I used Allegro for the simple 2D level editor for it.  The program itself is straight Windows + OpenGL code, nothing else, which i am sort of proud of. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p><span class="remote-thumbnail"><span class="json">{"name":"City3D.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/1\/81b50f96d8900c53034c26d4517fd16c.jpg","w":1280,"h":720,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/1\/81b50f96d8900c53034c26d4517fd16c"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/1/81b50f96d8900c53034c26d4517fd16c-240.jpg" alt="City3D.jpg" width="240" height="135" /></span></p><p>I also created a little test program to experiment with terrain generation years ago and every once in a while I putter around with it.  It&#39;s Glut + OpenGL.</p><p><span class="remote-thumbnail"><span class="json">{"name":"Test3D.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/3\/e3129f1100b6fbd5bdff0c0111f718c0.jpg","w":1280,"h":720,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/3\/e3129f1100b6fbd5bdff0c0111f718c0"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/3/e3129f1100b6fbd5bdff0c0111f718c0-240.jpg" alt="Test3D.jpg" width="240" height="135" /></span></p><p>Anyone is welcome to download them and play around with them (Windows).  They&#39;re all available here...</p><p><a href="http://home.cogeco.ca/~nroy15/programming_index.html">http://home.cogeco.ca/~nroy15/programming_index.html</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Mon, 08 Feb 2016 12:07:34 +0000</pubDate>
	</item>
</rss>
