<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>#AltDevBlogADay &#187; Jon Moore</title>
	<atom:link href="http://www.altdevblogaday.com/author/jon-moore/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.altdevblogaday.com</link>
	<description>Each day a little more #gamedev love</description>
	<lastBuildDate>Thu, 17 May 2012 03:06:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Skin Shading in Unity3d</title>
		<link>http://www.altdevblogaday.com/2011/12/31/skin-shading-in-unity3d/</link>
		<comments>http://www.altdevblogaday.com/2011/12/31/skin-shading-in-unity3d/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 05:42:39 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Arts]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[experimentation]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[modelling]]></category>
		<category><![CDATA[shaders]]></category>
		<category><![CDATA[skin shading]]></category>
		<category><![CDATA[skinning]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[texture]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=22093</guid>
		<description><![CDATA[<p>I&#8217;ve been away from AltDev for a while, a bit longer than I originally expected because after a period of crunch before IGF submission in late October, I went back to the comforts of getting a normal nights sleep, something that working a normal game development job this past summer spoiled me into enjoying. Now the Christmas holiday has given me not only the time to finally begin blogging again, but the chance to do a little side project in something I greatly enjoy: the rendering of human skin, which was also an excuse for giving the latest Unity3D 3.5 beta a whirl:</p>
<p><a href="http://www.altdevblogaday.com/2011/12/31/skin-shading-in-unity3d/" class="more-link">Read more on Skin Shading in Unity3d&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been away from AltDev for a while, a bit longer than I originally expected because after a period of crunch before IGF submission in late October, I went back to the comforts of getting a normal nights sleep, something that working a normal game development job this past summer spoiled me into enjoying. Now the Christmas holiday has given me not only the time to finally begin blogging again, but the chance to do a little side project in something I greatly enjoy: the rendering of human skin, which was also an excuse for giving the latest Unity3D 3.5 beta a whirl:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/FullHeadShot.jpg"><img class="aligncenter size-full wp-image-22235" src="http://altdevblogaday.com/wp-content/uploads/2011/12/FullHeadShot.jpg" alt="" width="526" height="395" /></a></p>
<p><strong>Motivation</strong></p>
<p>This has entirely been a hobby project for me, because I do not foresee its application into any project I&#8217;m involved with. However, I&#8217;ve realized that Unity is rapidly approaching the point where someone may want to use a more complicated skin shading model than just basic wrap lighting (an example of which is provided in the documentation). With this in mind, I thought it might be of interest to do a post pulling together some of the better resources I&#8217;ve found on the topic as well as posting some of my more useful code so that perhaps it might help serve as a jumping off point for a more serious endeavor.</p>
<p>The one issue that is always at the core of skin shading is that of Subsurface Scattering, which is the effect of light bouncing around underneath the surface of the skin and re-exiting elsewhere. A simply using a Lambert model causes very harsh edges, because the scattering is what gives skin its softer appearance. Here&#8217;s what the built-in &#8220;Bumped Diffuse&#8221; shader looks like, the basis that is trying to be improved:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/DiffuseBumped.jpg"><img class="aligncenter size-full wp-image-22206" src="http://altdevblogaday.com/wp-content/uploads/2011/12/DiffuseBumped.jpg" alt="" width="526" height="394" /></a></p>
<p><strong>Background: Texture Space Diffusion</strong></p>
<p>No discussion of skin rendering starts with anything other than mentioning the NVIDIA Human Head demo, which has <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch14.html" target="_blank">a detailed description of its implementation in GPU Gems 3</a>. The technique relies upon Texture Space Diffusion, where the lighting for the mesh is rendered into a texture and then blurred various amounts (based off of the scattering of light inside of human skin). The results of those blurs is combined together to form the actual diffuse lighting term. I actually played around with this technique in Unity around Christmas time last year, but this proved to be difficult given the nature of the TSD and the fact that Unity did not at the time easily support some nice features like Linear Space lighting.</p>
<p>There have been some very useful resources on skin shading in since the publication of GPU Gems 3. There are <a href="http://advances.realtimerendering.com/s2010/index.html" target="_blank">some excellent Siggraph slides from John Hable</a> where he details what Naughty Dog did to attempt cheaper calculations than the NVIDIA techniques in Uncharted 2. There is also a technique by Jorge Jimenez detailed in GPU Pro that <a href="http://www.iryoku.com/screen-space-subsurface-scattering" target="_blank">does subsurface scattering calculations in screen space</a>, which removes the cost per mesh of TSD (a serious limitation for it&#8217;s use in an actual application). This seems to have garnered some adoption in game engines, but I understand that it is still a reasonably expensive technique (note: I&#8217;m less knowledgeable of Screen Space Subsurface Scattering, so take that comment with a grain of salt).</p>
<p>With regards to tools for doing Skin Rendering on your own time, a good quality head scan has entered into the <a href="http://www.ir-ltd.net/infinite-3d-head-scan-released" target="_blank">public domain from Lee Perry-Smith and Infinite Realities</a>. Also, Unity3d is much friendlier to doing some high quality rendering. There is now <a href="http://unity3d.com/unity/preview/" target="_blank">a public beta for Unity 3.5</a>, which now features Linear Space lighting and HDR rendering conveniently built into the engine.</p>
<p><strong>The Latest Hotness: Pre-Integrated Skin Shadding (PISS)</strong></p>
<p>I&#8217;ve been impressed with the quality articles in GPU Pro 2 since I picked it up this past summer, one of which is Eric Penner&#8217;s article detailing his technique &#8220;Pre-Integrated Skin Shading.&#8221; He also gave a talk describing it at Siggraph, <a href="http://advances.realtimerendering.com/s2011/" target="_blank">and the slides are available online</a>. There are three main parts to it: scattering due to curvature, scattering on small details (i.e. the bump map), and scattering in shadow falloff. I did the first two, no shadows yet for me, but I&#8217;ll do a follow up post if I get around to it.</p>
<p>The basic motivation is to pre-calculate the diffuse falloff into a look-up texture. The key to making the effect look good is that instead of having a 1-dimensional texture for NdotL, it is a 2D texture that encompasses different falloffs for different thicknesses of geometry. This will allow the falloff at the nose to differ from that in the forehead.</p>
<p>I&#8217;ve adapted the sample code to precompute the lookup texture into a little editor wizard for Unity. Simply make a folder titled &#8220;Editor&#8221; in Unity&#8217;s assets and drop it in, and you&#8217;ll have it extended to the editor (the function is added to the menu &#8220;GameObject/Generate Lookup Textures&#8221;). I&#8217;ve included the full script at the bottom of this blog post, which computes both a falloff texture that appears to be about the same as the one that Penner shows in GPU Pro 2. Here&#8217;s what my lookup texture looked like when I was all said and done, this is to be sampled with 1/d in the y, and NdotL in the x:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/DiffuseScatteringOnRing.jpg"><img class="aligncenter size-medium wp-image-22250" src="http://altdevblogaday.com/wp-content/uploads/2011/12/DiffuseScatteringOnRing-300x300.jpg" alt="" width="300" height="300" /></a></p>
<p>An important note: if you activate Linear Rendering in Unity 3.5, know that the texture importer has an option to sample a texture in Linear Space. <a href="http://developer.nvidia.com/node/181" target="_blank">GPU Gems 3 has an entire article about the importance of being linear</a>, I noticed that after I turned it on in Unity, the lookup texture had the effect of making the head look like it was still in Gamma Space. I then realized I needed to flip on that option in the importer. In fact you may notice that the lookup texture in GPU Pro 2 looks different than the one in Penner&#8217;s Siggraph slides, this is because the one in the slides is in linear space. The one in the book is not, which is also the case with the one pictured above.</p>
<p>The parameter 1/d is approximated with a calculation of curvature based on similar triangles and derivatives (there&#8217;s a great illustration of this in the slides), and I&#8217;ve included the snippet of GLSL from my shader. To see the output of curvature on my model (easily tuned with a uniform parameter in the shader to offset the calculation):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="glsl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Calculate curvature</span>
<span style="color: #000066; font-weight: bold;">float</span> curvature <span style="color: #000066;">=</span> <span style="color: #993333; font-weight: bold;">clamp</span><span style="color: #000066;">&#40;</span><span style="color: #993333; font-weight: bold;">length</span><span style="color: #000066;">&#40;</span>fwidth<span style="color: #000066;">&#40;</span>localSurface2World<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">2</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">0.0</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">1.0</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #000066;">&#40;</span><span style="color: #993333; font-weight: bold;">length</span><span style="color: #000066;">&#40;</span>fwidth<span style="color: #000066;">&#40;</span>position<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> _TuneCurvature<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></td></tr></table></div>

<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/Curvature.jpg"><img class="aligncenter size-full wp-image-22221" src="http://altdevblogaday.com/wp-content/uploads/2011/12/Curvature.jpg" alt="" width="524" height="393" /></a></p>
<p>This curvature calculation is actually a serious problem with implementing the technique in Unity. This is because ddx and ddy (fwidth(x) is just: abs(ddx(x)) + abs(ddy(x))) are not supported by ARB, which means Unity can&#8217;t use the shader in OpenGL. Those of you familiar with Unity, will know that CG is the shading language of choice, and it is then compiled for each platform. A thorny issue, that I have been stumped with in the past, especially because I do many of my side projects in OSX on my laptop. Tim Cooper (<a href="http://twitter.com/#!/stramit" target="_blank">@stramit</a>) came to my rescue with a solution that works decently: to write an OpenGL only shader directly in GLSL, which will support fwidth no problem. This is a *little* painful, especially because Unity seems to have dropped the glsl version of AutoLight.cginc (my 3.4 build has AutoLight.glslinc, but unfortunatey 3.5 beta 5 does not), which is going to make things like using the built-in light attenuation methods much more of a headache. In fact, the reason my sample images use a directional light is because I don&#8217;t currently have point light falloffs matching *exactly* the same as Unity&#8217;s. That being said, it hasn&#8217;t been problematic enough to cause me to just abandon OpenGL support and move to a Windows computer. Furthermore, there&#8217;s a nice wiki that served as a good jumping off point <a href="http://en.wikibooks.org/wiki/GLSL_Programming/Unity" target="_blank">for doing GLSL in Unity</a>.</p>
<p>(NOTE: Aras from Unity posted a suggestion down in the comments that might cause my choice to use GLSL directly to be un-needed. I will properly update the post after I try it out myself)</p>
<p><strong>Softening Finer Details</strong></p>
<p>As I mentioned, I&#8217;m sharing my experience with trying out 2 of the 3 techniques detailed by Penner. The second part is smoothing of small detailed bumps. While the pre-integrated texture will account for scattering at a broader sense, the fine details contained in the normal map are still much too harsh. Here&#8217;s what my model looks like with just the pre-integrated scattering:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/PreIntegratedSkinHardNormals.jpg"><img class="aligncenter size-full wp-image-22228" src="http://altdevblogaday.com/wp-content/uploads/2011/12/PreIntegratedSkinHardNormals.jpg" alt="" width="522" height="392" /></a></p>
<p>&#8220;Too Crispy&#8221; is my favorite way of describing the problem. Penner addresses this by proposing blending between a smoother normal map and the high detail normal map. The high detail is still used for specular calculations, but for the diffuse, you pretend that red, green, and blue all come from separate normals. This is very similar to what Hable details as the technique used in normal gameplay in Uncharted 2 in his Siggraph 2010 slides. By treating them separately the red channel can be made to be softer, Penner advises using the profile data from GPU Gems 3 to try to match real life.</p>
<p>In order to avoid the additional memory of having 2 normal maps, Penner uses a second sampler for the normal map that is clamped to a lower mip resolution (as opposed to using the surface normal like Uncharted 2). However, Unity does not allow easy access to samplers to my knowledge, so the only way to set up a sampler like that is to actually duplicate the texture asset, which won&#8217;t save any memory. So, my solution was to just instead apply a LOD bias to the texture lookup (an optional <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/texture.xml" target="_blank">third parameter in tex2D/texture2D</a> in case you&#8217;re not familiar). Here&#8217;s what the same shot from above looks like with the blended normals applied using a mip bias of 3.0:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/PreIntegratedSkin.jpg"><img class="aligncenter size-full wp-image-22229" src="http://altdevblogaday.com/wp-content/uploads/2011/12/PreIntegratedSkin.jpg" alt="" width="524" height="393" /></a></p>
<p><strong>Specular</strong></p>
<p>While many articles on skin shading focus almost entirely on the scattering of diffuse, the GPU Gems 3 article provides a good treatment of using a specular model that is better than Blinn-Phong. The authors chose the Kelemen/Szirmay-Kalos Specular BRDF, which relies on a precomputed Beckmann lookup texture and takes into account <a href="http://en.wikipedia.org/wiki/Fresnel_equations" target="_blank">Fresnel</a> with the <a href="http://en.wikipedia.org/wiki/Schlick%27s_approximation" target="_blank">Schlick approximation</a>. Being that I had played around with that model a year ago when I was experimenting with TSD in Unity, I simply rolled that code into Penner&#8217;s work. Here&#8217;s the resulting specular:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/SpecularOnly.jpg"><img class="aligncenter size-full wp-image-22233" src="http://altdevblogaday.com/wp-content/uploads/2011/12/SpecularOnly.jpg" alt="" width="525" height="395" /></a></p>
<p>A shot before applying specular:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/WithOutSpecular.jpg"><img class="aligncenter size-full wp-image-22236" src="http://altdevblogaday.com/wp-content/uploads/2011/12/WithOutSpecular.jpg" alt="" width="525" height="392" /></a></p>
<p>And finally the specular and diffuse combined together:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/12/WithSpecular.jpg"><img class="aligncenter size-full wp-image-22237" src="http://altdevblogaday.com/wp-content/uploads/2011/12/WithSpecular.jpg" alt="" width="523" height="392" /></a></p>
<p><strong>Concluding Thoughts / Future Work</strong></p>
<p>This has been a fun little side project for me, and I think it turned out decently well. I&#8217;ve made and fixed a few stupid mistakes along the way, and I wonder if I&#8217;ll find a few more yet, don&#8217;t be afraid to point out anything terrible if you spot it. My two main goals left are tighter integration with Unity : proper point/spot calculations that match CG shaders in Unity, and shadow support. When it comes to shadows I&#8217;m at a but of a crossroads between trying to hook into Unity&#8217;s main shadow support vs. rolling some form of my own. I suspect rolling my own would be less useful in the effort to make the skin shader completely seamless with unity, but might be less of a headache to accomplish. Either way, if I do make make any drastic improvements, I promise I&#8217;ll do a follow up post :)</p>
<p>Finally, if you&#8217;re interested in the IGF project, Dust, that I mentioned as the root cause of my hiatus from AltDev, you can check out the project on it&#8217;s website at <a href="http://www.adventureclubgames.com/dust/" target="_blank">www.adventureclubgames.com/dust/</a>, and the trailer for it if clicking a link is too much effort:</p>
<span style="text-align:center; display: block;"><a href="http://www.altdevblogaday.com/2011/12/31/skin-shading-in-unity3d/"><img src="http://img.youtube.com/vi/TJ5dLSh8PC0/2.jpg" alt="" /></a></span>
<p><strong>Source Code</strong></p>
<p>As I promised, here is the source for my Unity script that generates my lookup textures:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// GenerateLookupTexturesWizard.cs</span>
<span style="color: #008080; font-style: italic;">// Place this script in Editor folder</span>
<span style="color: #008080; font-style: italic;">// Generated textures are placed inside of the Editor folder as well</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEditor</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">class</span> GenerateLookupTexturesWizard <span style="color: #008000;">:</span> ScriptableWizard <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> width <span style="color: #008000;">=</span> <span style="color: #FF0000;">512</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> height <span style="color: #008000;">=</span> <span style="color: #FF0000;">512</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> generateBeckmann <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> generateDiffuseScattering <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008000;">&#91;</span>MenuItem <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;GameObject/Generate Lookup Textures&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> CreateWizard <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        ScriptableWizard<span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayWizard</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>GenerateLookupTexturesWizard<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PreIntegrate Lookup Textures&quot;</span>, <span style="color: #666666;">&quot;Create&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">float</span> PHBeckmann<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> ndoth, <span style="color: #6666cc; font-weight: bold;">float</span> m<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #6666cc; font-weight: bold;">float</span> alpha <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Acos</span><span style="color: #008000;">&#40;</span>ndoth<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">float</span> ta <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Tan</span><span style="color: #008000;">&#40;</span>alpha<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">float</span> val <span style="color: #008000;">=</span> 1f<span style="color: #008000;">/</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">*</span>m<span style="color: #008000;">*</span>Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Pow</span><span style="color: #008000;">&#40;</span>ndoth,4f<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Exp</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #008000;">&#40;</span>ta <span style="color: #008000;">*</span> ta<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span>m <span style="color: #008000;">*</span> m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> val<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	Vector3 IntegrateDiffuseScatteringOnRing<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> cosTheta, <span style="color: #6666cc; font-weight: bold;">float</span> skinRadius<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// Angle from lighting direction</span>
		<span style="color: #6666cc; font-weight: bold;">float</span> theta <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Acos</span><span style="color: #008000;">&#40;</span>cosTheta<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		Vector3 totalWeights <span style="color: #008000;">=</span> Vector3<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
		Vector3 totalLight <span style="color: #008000;">=</span> Vector3<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #6666cc; font-weight: bold;">float</span> a <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #008000;">&#40;</span>Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">PI</span><span style="color: #008000;">/</span>2<span style="color: #008000;">.</span>0f<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">float</span> inc <span style="color: #008000;">=</span> 0<span style="color: #008000;">.</span>05f<span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>a <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> <span style="color: #008000;">&#40;</span>Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">PI</span><span style="color: #008000;">/</span>2<span style="color: #008000;">.</span>0f<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #6666cc; font-weight: bold;">float</span> sampleAngle <span style="color: #008000;">=</span> theta <span style="color: #008000;">+</span> a<span style="color: #008000;">;</span>
			<span style="color: #6666cc; font-weight: bold;">float</span> diffuse <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Clamp01</span><span style="color: #008000;">&#40;</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Cos</span><span style="color: #008000;">&#40;</span>sampleAngle<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// Distance</span>
			<span style="color: #6666cc; font-weight: bold;">float</span> sampleDist <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span> 2<span style="color: #008000;">.</span>0f <span style="color: #008000;">*</span> skinRadius <span style="color: #008000;">*</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Sin</span><span style="color: #008000;">&#40;</span>a <span style="color: #008000;">*</span> 0<span style="color: #008000;">.</span>5f<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// Profile Weight</span>
			Vector3 weights <span style="color: #008000;">=</span> Scatter<span style="color: #008000;">&#40;</span>sampleDist<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			totalWeights <span style="color: #008000;">+=</span> weights<span style="color: #008000;">;</span>
			totalLight <span style="color: #008000;">+=</span> diffuse <span style="color: #008000;">*</span> weights<span style="color: #008000;">;</span>
			a<span style="color: #008000;">+=</span>inc<span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		Vector3 result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>totalLight<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">/</span> totalWeights<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span>, totalLight<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">/</span> totalWeights<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span>, totalLight<span style="color: #008000;">.</span><span style="color: #0000FF;">z</span> <span style="color: #008000;">/</span> totalWeights<span style="color: #008000;">.</span><span style="color: #0000FF;">z</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">float</span> Gaussian <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> v, <span style="color: #6666cc; font-weight: bold;">float</span> r<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> 1<span style="color: #008000;">.</span>0f <span style="color: #008000;">/</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">&#40;</span>2<span style="color: #008000;">.</span>0f <span style="color: #008000;">*</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">PI</span> <span style="color: #008000;">*</span> v<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Exp</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #008000;">&#40;</span>r <span style="color: #008000;">*</span> r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span> <span style="color: #008000;">*</span> v<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	Vector3 Scatter <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> r<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// Values from GPU Gems 3 &quot;Advanced Skin Rendering&quot;</span>
		<span style="color: #008080; font-style: italic;">// Originally taken from real life samples</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> Gaussian<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>0064f <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>414f, r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>233f, 0<span style="color: #008000;">.</span>455f, 0<span style="color: #008000;">.</span>649f<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">+</span> Gaussian<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>0484f <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>414f, r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>100f, 0<span style="color: #008000;">.</span>336f, 0<span style="color: #008000;">.</span>344f<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">+</span> Gaussian<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>1870f <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>414f, r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>118f, 0<span style="color: #008000;">.</span>198f, 0<span style="color: #008000;">.</span>000f<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">+</span> Gaussian<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>5670f <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>414f, r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>113f, 0<span style="color: #008000;">.</span>007f, 0<span style="color: #008000;">.</span>007f<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">+</span> Gaussian<span style="color: #008000;">&#40;</span>1<span style="color: #008000;">.</span>9900f <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>414f, r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>358f, 0<span style="color: #008000;">.</span>004f, 0<span style="color: #008000;">.</span>00001f<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">+</span> Gaussian<span style="color: #008000;">&#40;</span>7<span style="color: #008000;">.</span>4100f <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>414f, r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">new</span> Vector3<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>078f, 0<span style="color: #008000;">.</span>00001f, 0<span style="color: #008000;">.</span>00001f<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">void</span> OnWizardCreate <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// Beckmann Texture for specular</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>generateBeckmann<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
	        Texture2D beckmann <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Texture2D<span style="color: #008000;">&#40;</span>width, height, TextureFormat<span style="color: #008000;">.</span><span style="color: #0000FF;">ARGB32</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> height<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>j<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> width<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
					<span style="color: #6666cc; font-weight: bold;">float</span> val <span style="color: #008000;">=</span> 0<span style="color: #008000;">.</span>5f <span style="color: #008000;">*</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Pow</span><span style="color: #008000;">&#40;</span>PHBeckmann<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">/</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span> width, j<span style="color: #008000;">/</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>height<span style="color: #008000;">&#41;</span>, 0<span style="color: #008000;">.</span>1f<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					beckmann<span style="color: #008000;">.</span><span style="color: #0000FF;">SetPixel</span><span style="color: #008000;">&#40;</span>i, j, <span style="color: #008000;">new</span> Color<span style="color: #008000;">&#40;</span>val,val,val,val<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
			beckmann<span style="color: #008000;">.</span><span style="color: #0000FF;">Apply</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> bytes <span style="color: #008000;">=</span> beckmann<span style="color: #008000;">.</span><span style="color: #0000FF;">EncodeToPNG</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			DestroyImmediate<span style="color: #008000;">&#40;</span>beckmann<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			File<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteAllBytes</span><span style="color: #008000;">&#40;</span>Application<span style="color: #008000;">.</span><span style="color: #0000FF;">dataPath</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;/Editor/BeckmannTexture.png&quot;</span>, bytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Diffuse Scattering</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>generateDiffuseScattering<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
	        Texture2D diffuseScattering <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Texture2D<span style="color: #008000;">&#40;</span>width, height, TextureFormat<span style="color: #008000;">.</span><span style="color: #0000FF;">ARGB32</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> height<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>j<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> width<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
					<span style="color: #008080; font-style: italic;">// Lookup by:</span>
					<span style="color: #008080; font-style: italic;">// x: NDotL</span>
					<span style="color: #008080; font-style: italic;">// y: 1 / r</span>
					<span style="color: #6666cc; font-weight: bold;">float</span> y <span style="color: #008000;">=</span> 2<span style="color: #008000;">.</span>0f <span style="color: #008000;">*</span> 1f <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>j <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span> height<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					Vector3 val <span style="color: #008000;">=</span> IntegrateDiffuseScatteringOnRing<span style="color: #008000;">&#40;</span>Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Lerp</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span>1f, 1f, i<span style="color: #008000;">/</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span> width<span style="color: #008000;">&#41;</span>, y<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					diffuseScattering<span style="color: #008000;">.</span><span style="color: #0000FF;">SetPixel</span><span style="color: #008000;">&#40;</span>i, j, <span style="color: #008000;">new</span> Color<span style="color: #008000;">&#40;</span>val<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span>,val<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span>,val<span style="color: #008000;">.</span><span style="color: #0000FF;">z</span>,1f<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
			diffuseScattering<span style="color: #008000;">.</span><span style="color: #0000FF;">Apply</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> bytes <span style="color: #008000;">=</span> diffuseScattering<span style="color: #008000;">.</span><span style="color: #0000FF;">EncodeToPNG</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			DestroyImmediate<span style="color: #008000;">&#40;</span>diffuseScattering<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			File<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteAllBytes</span><span style="color: #008000;">&#40;</span>Application<span style="color: #008000;">.</span><span style="color: #0000FF;">dataPath</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;/Editor/DiffuseScatteringOnRing.png&quot;</span>, bytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">void</span> OnWizardUpdate <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        helpString <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Press Create to calculate texture. Saved to editor folder&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I haven&#8217;t included the actual shader because it&#8217;s a little messy still and currently only supports the OpenGL path. The numerous resources that I&#8217;ve mentioned should guide you in the right direction though.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/12/31/skin-shading-in-unity3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Games about Yetis&#8230; Proof You Can Never Win?</title>
		<link>http://www.altdevblogaday.com/2011/10/02/games-about-yetis-proof-you-can-never-win/</link>
		<comments>http://www.altdevblogaday.com/2011/10/02/games-about-yetis-proof-you-can-never-win/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 01:20:41 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=17683</guid>
		<description><![CDATA[<p>Earlier this week I had my mind completely blown when I saw something that was almost unbelievable: a game that at first glance seemed like a clone of a game several of my friends made as students a few years back.</p>
<p><a href="http://www.altdevblogaday.com/2011/10/02/games-about-yetis-proof-you-can-never-win/" class="more-link">Read more on Games about Yetis&#8230; Proof You Can Never Win?&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Earlier this week I had my mind completely blown when I saw something that was almost unbelievable: a game that at first glance seemed like a clone of a game several of my friends made as students a few years back.</p>
<p>The game that my friends made was called Yeti Tracks. The premise of the game is that your character has crashed his plane in a blizzard and you have to use your rifle to both hunt a rabbit for food and fend off a Yeti that is hunting you. You win by successfully hunting the rabbit and returning to your plane. It&#8217;s a small, unpolished student game:</p>
<span style="text-align:center; display: block;"><a href="http://www.altdevblogaday.com/2011/10/02/games-about-yetis-proof-you-can-never-win/"><img src="http://img.youtube.com/vi/6ilqrdfZrVM/2.jpg" alt="" /></a></span>
<p>What&#8217;s interesting is that indie developer Vlambeer showed off a new project of theirs at Fantastic Arcade recently. The game is titled Yeti Hunter&#8230; and it looks exactly like what most people would call a clone, but I don&#8217;t think that was Vlambeer&#8217;s intention. It&#8217;s worth noting that they say this game may never find it&#8217;s way to a formal release, but it&#8217;s certainly gotten more attention than the Yeti Tracks did. The key difference as far as I can tell, is that the point is to hunt yetis instead of staving them off, but the gameplay is eerily similar in this small, unpolished indie game:</p>
<span style="text-align:center; display: block;"><a href="http://www.altdevblogaday.com/2011/10/02/games-about-yetis-proof-you-can-never-win/"><img src="http://img.youtube.com/vi/KmnUGb_Qpxo/2.jpg" alt="" /></a></span>
<p>You may have noticed Vlambeer in the news recently, their game Radical Fishing got cloned on iOS before they could release the actual iOS version of the game, Ridiculous Fishing. It seems relatively certain that the clone was intentional, and it made my blood boil when I read about the whole incident. But the Yet Tracks / Yeti Hunter similarities also made my jaw drop, and then I realized that it was highly unlikely that the developers found an obscure student game and decided to clone and polish the gameplay.</p>
<p>So what does that leave us? Does it make it alright? If Yeti Hunter&#8217;s existence is acceptable, then does that mean that we also have to find Ninja Fishing to be acceptable?</p>
<p>Or can we really have the criteria be based on what the intention of the developer was, so that the similarities in the Yeti games are alright, but an intentional fishing game rip-off is not? Using that distinction is incredibly hard to do. Consider the sciences and engineering: keeping a log of your work can be just as important to prove your work was developed originally, as it is to validate the methods used.</p>
<p>If we want game design to be an art form, wanting that sort of proof that an idea is original would be ludicrous, never mind that it would be infinitely harder to &#8220;verify&#8221; as well. The whole dilemma seems like a tangled mess, and the thing that really makes me sour is that the student that had the original idea for the game admitted that the existence of Yeti Hunter meant that he could never release a polished version of Yeti Tracks without people constantly making comparisons.</p>
<p>In fact, I wonder if he did a more public release of the game (say, on iPhone), if the community would attack him for &#8220;ripping off&#8221; Vlambeer, considering their unfortunate situation with Radical Fishing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/10/02/games-about-yetis-proof-you-can-never-win/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3 Years Later: Year Three</title>
		<link>http://www.altdevblogaday.com/2011/09/17/3-years-later-year-three/</link>
		<comments>http://www.altdevblogaday.com/2011/09/17/3-years-later-year-three/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 02:49:11 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=16490</guid>
		<description><![CDATA[<p>This post is drawing to a close my little series on how I went from not knowing the first thing about game development to being a programmer that eats rendering code for breakfast (as all good graphics programmers should). Here are links to my posts about <a href="http://altdevblogaday.com/2011/08/18/3-years-later-year-one/" target="_blank">Year 1</a> and <a href="http://altdevblogaday.com/2011/09/02/3-years-later-year-two/" target="_blank">Year 2</a>.</p>
<p><a href="http://www.altdevblogaday.com/2011/09/17/3-years-later-year-three/" class="more-link">Read more on 3 Years Later: Year Three&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This post is drawing to a close my little series on how I went from not knowing the first thing about game development to being a programmer that eats rendering code for breakfast (as all good graphics programmers should). Here are links to my posts about <a href="http://altdevblogaday.com/2011/08/18/3-years-later-year-one/" target="_blank">Year 1</a> and <a href="http://altdevblogaday.com/2011/09/02/3-years-later-year-two/" target="_blank">Year 2</a>.</p>
<p><strong>Olympus</strong></p>
<p>After finishing out my second year of college, I spent my Summer working on what would become the longest running project I&#8217;ve ever been a part of. <a href="http://gel.msu.edu/olympus/" target="_blank">Olympus</a> is a project from the MSU Games for Entertainment and Learning Lab developed to study the effectiveness of exercise in motion games in the context of a game intended primarily for entertainment.</p>
<p>The design was that of an action adventure game set in Greek mythology. It not only required us to support toggling everything from dialog options to whether the game was played with a 360 Controller or a Wii-mote/Dance pad combination for various research groups, but it also demanded that we deal with the problems of maintaining a codebase over the course of a long-term project.</p>
<p>The lessons here were invaluable. There were only ever two main programmers on Olympus at a time, with <a href="http://twitter.com/#!/qtbon" target="_blank">Shawn Henry Adams</a> and myself moving into those roles as the original two graduated. It very quickly became apparent to us that the code base was riddled with quick fixes, lack of proper tools, and poor software engineering. In other words- it was made by students, and not bad students at that. The fact that students are rarely have to revisit class projects in the future is something that I think should be fully realized when doing a student based project.</p>
<p>I&#8217;m not sure when students are supposed to learn the life lessons of the dangers of ignoring an attempt at good software design, but I certainly learned it from Olympus. It was also the most fun I ever had making a game for the GEL lab, working with my coworkers to get through the challenges of developing hours of gameplay and adapting existing, and often messy, systems to new designs. So as a student if you have the chance to work on or take a class that involves a project that lasts at least a semester, don&#8217;t let it pass you by.</p>
<p><strong>Becoming Nocturnal</strong></p>
<p>When school actually started up, I was enrolled in two classes that changed me forever. One was the portfolio class for the game development track at MSU, and I threw myself into that class like there was no tomorrow. There was not an all-nighter that I wouldn&#8217;t pull for the sake of my games, and looking back now I&#8217;m pretty sure I know why I had that mentality. The number one thing that I&#8217;ve ever heard about getting a job in game development is that a stellar portfolio is essential. Worthwhile? Yes. Although, as I lamented in my last post, a passing grade is not enough incentive to have people create amazing games. For me, feeling like I&#8217;m the only one working on a project is a lot more troubling than a difficult technical challenge. I&#8217;ll always help and vouch for the kids that throw themselves at their work, because with a little direction, they&#8217;ll always do great things. But in a portfolio class, it was always frustrating to deal with kids that had already let their enthusiasm slide to the point of no longer pursuing game development seriously.</p>
<p>I also took <a href="http://www.cse.msu.edu/~ytong/" target="_blank">Yiying Tong&#8217;s</a> graduate level graphics programming class that Fall, and it was perhaps both the greatest and hardest class I&#8217;ve ever taken. There&#8217;s a different lesson to be learned here than working hard to make a good game: it&#8217;s worth it to go way over your head in a subject you enjoy. While a lot of it was beyond my comprehending at the time, I&#8217;ve come to learn that not being afraid of material you don&#8217;t fully understand can help you out in the long run. Maybe the first time or the second time it doesn&#8217;t make sense, but eventually, it all comes around.</p>
<p><strong>On My Way Out</strong></p>
<p>The Spring of junior year brought along my first serious attempt hunting for a job in the industry beyond Michigan State University&#8217;s game development research projects. It also brought about the beginning of my writing for AltDev, the beginnings of a stint writing tutorials for Shaders in Unity, and my first semester as a TA for the introductory Game Design course. This was a bit of a tipping point for me and draws my story to a close.</p>
<p>I never had a good gauge for whether or not I was on track to make games professionally after college. When I seriously started teaching others how to make games, and people actually seemed to be improving as a consequence of my effort, I began to realize I was probably doing alright. My hunt for a game development internship landed me at <a href="http://www.irongalaxystudios.com/" target="_blank">the mighty Iron Galaxy Studios</a>, and maybe someday after what I was working on gets announced I&#8217;ll talk a little about my experiences as an intern there (spoiler: it was great!), but it certainly reaffirmed my suspicions that I had gone from someone wanting to learn game dev to someone that could competently contribute to a substantial game.</p>
<p>A final word on my efforts to contribute to helping others learn about game development: it&#8217;s very rewarding. If you find yourself in a position to help others out, seriously consider it, whether it&#8217;s teaching a class or writing a blog post or even giving a presentation at a local club or IGDA chapter meeting. I know that the reason I enjoy spending so much of my time trying to give back to the game development program at MSU and the development community as a whole is because a younger version of myself would have loved to be on the receiving end of any of the information I&#8217;ve shared. Many people helped me along the way to understanding what I&#8217;ve learned and experienced, it&#8217;s all I can do to continue that effort now that I&#8217;m in their shoes as one of the more experienced individuals at MSU.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/09/17/3-years-later-year-three/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3 Years Later: Year Two</title>
		<link>http://www.altdevblogaday.com/2011/09/02/3-years-later-year-two/</link>
		<comments>http://www.altdevblogaday.com/2011/09/02/3-years-later-year-two/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 00:27:18 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=15279</guid>
		<description><![CDATA[<p>This is part two of my little series about what I&#8217;ve done in the past 3 years of my life to take myself from a kid that had never made a 3D game in his life to someone who lives and breathes game programming on several projects (commercial and otherwise). Here&#8217;s a link to <a title="Year One" href="http://altdevblogaday.com/2011/08/18/3-years-later-year-one/" target="_blank">the first post in the series.</a></p>
<p><a href="http://www.altdevblogaday.com/2011/09/02/3-years-later-year-two/" class="more-link">Read more on 3 Years Later: Year Two&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is part two of my little series about what I&#8217;ve done in the past 3 years of my life to take myself from a kid that had never made a 3D game in his life to someone who lives and breathes game programming on several projects (commercial and otherwise). Here&#8217;s a link to <a title="Year One" href="http://altdevblogaday.com/2011/08/18/3-years-later-year-one/" target="_blank">the first post in the series.</a></p>
<p><strong>Getting Paid to make a Game</strong></p>
<p>During the academic semesters for my first two years of college, I got paid by a scholarship to work for the Games for Entertainment and Learning Lab (an incentive to have first and second year students involved in research labs on campus). However, part of the way through the summer leading up to my second year of college, I got pulled on to a project as a second programmer, and being paid outside of the academic year by the Lab&#8217;s actual budget was exciting for me. However, the project went anything but smoothly (and had been a mess well before I was brought on).</p>
<p>I&#8217;ve noticed that sometimes game devs talk about getting jaded or disillusioned after getting into game development professionally. If there was ever a project that did it for me it was this one, a serious game about power plant management. It was continually misdirected by a client that didn&#8217;t understand game design or development. The project got extended into the Fall semester as the development continued to be a mess. Eventually this culminated into the client asking us to add back as many of the features the Lab had attempted to add to make the game more fun, finally realizing that the direction they had been steering it was keeping it from being fun for the target audience.</p>
<p>For as unfortunate as that was, I think something really important came from this, the knowledge that programming, not game design, was what I loved no matter how badly a project was going. Level design in particular came hard for me, realizing that it really just couldn&#8217;t hold my interest like a programming challenge. I think most people can find a lot of glamour in more than one discipline of game development, and for me I thought that maybe game design was as an enjoyable as coding. Clearly I was wrong, and it proved to me that even a bad project can have a lot of value, giving me a better sense of direction of what I wanted to do moving forward.</p>
<p><strong>Greener Pastures</strong></p>
<p>While the power management game was wrapping up, two much more promising projects were just starting up. One was a competition hosted by Ford Credit between Michigan State University and University of Michigan&#8217;s game development clubs (Ford is headquartered in Michigan, thus the localness of the competition). The goal was to make an serious/adver game to teach potential Ford customers about car financing. The target audience was people in their early 20&#8242;s, so having college students make a Flash game seemed like a great way for Ford Credit to go about it and was probably a fun PR stunt at the same time.</p>
<p>While the content of the game might not sound amazing, Ford Credit was very hands off about the development, which was a breath of fresh air compared to the project I was coming off of. The real kicker though was the prize: all expenses covered for GDC with all-access passes. I threw myself into that project like there was no tomorrow, and it ended up being the first project I seriously crunched on as the team streaked towards our relatively aggressive deadline (I believe we had 3 or 4 months of development, and many of us had never done a Flash game before). It wasn&#8217;t uncommon for me to be up at 2 am rolling in features and artwork that probably should have been cut for scope reasons, and even then I was fixing bugs right up to the deadline. And when I say &#8220;right up to,&#8221; I mean that I did the submission build of the game on a laptop in the back of a van as we drove to present the game to the judges in Dearborn. You can <a title="Dealertown Ford" href="http://gel.msu.edu/dealertownford/" target="_blank">check out the game here.</a></p>
<p>The result was that we won, and getting to go to sessions at GDC 2010 blew my mind. While I know many devs that have been in the industry go to GDC as much for the socializing as the sessions, as a student I&#8217;d say that the talks are infinitely valuable. Especially compared to the Career Pavilion, which I&#8217;d wager is what the majority of students attend GDC for. It was also then that I realized that the allure of rendering and engine code was ever so tantalizing, with <a title="Uncharted 2 rendering" href="http://filmicgames.com/archives/6" target="_blank">John Hable&#8217;s talk about HDR lighting in Uncharted 2</a> convincing me to drown myself in graphics programming in my spare time. This was a big jump for someone that thought they might still want to be a game designer less than a year earlier.</p>
<p>Lesson here? Student competitions are important, teaching more about deadlines and quality game development than any class could, because to be honest, student projects often are only a fraction of a someone&#8217;s grade. The project for Ford Credit had that extra mile of polish that can only come from really wanting to make the best game possible. Getting in that extra stretch of polish and bug fixes before a class deadline lacks incentive because it probably won&#8217;t budge someone&#8217;s grade unless it&#8217;s worth at least half the student&#8217;s grade. I&#8217;ll be revisiting that theory of mine in my next article.</p>
<p><strong>Enter: Olympus</strong></p>
<p>I mentioned that their were two projects in the wake of the power plant management game. The second one was a motion controlled action adventure about Greek Mythology. The purpose of the game was to be used to study the effectiveness of aggressive motion controls in an entertainment game (as opposed to a game like Wii Fit, where exercise is the consumer&#8217;s intent).</p>
<p>I started as what I would probably refer to as a &#8220;junior programmer&#8221; handling basic gameplay tasks while I was still heavily involved in the Ford project and my first class about game design and development. However, I would inherit the role of leading up the player and motion control code when the original programmer graduated, continuing into the summer. I&#8217;ll pick up on that story in my next post about lessons from my third year of learning game dev.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/09/02/3-years-later-year-two/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3 Years Later: Year One</title>
		<link>http://www.altdevblogaday.com/2011/08/18/3-years-later-year-one/</link>
		<comments>http://www.altdevblogaday.com/2011/08/18/3-years-later-year-one/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 04:49:13 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=14447</guid>
		<description><![CDATA[<p>A while back, someone on Twitter (I can&#8217;t find the original conversation), asked me if I would consider writing up how I learned to program video games. I&#8217;m going to split this into several articles (for better or for worse) based around each year, and then one wrapping everything up with a big dump of the tools, articles, and books I&#8217;ve found incredibly helpful along the way. I thought splitting them up would be good because I&#8217;m only *a little* busy with moving back to Michigan and getting up to full steam on a project for IGF. </p>
<p><a href="http://www.altdevblogaday.com/2011/08/18/3-years-later-year-one/" class="more-link">Read more on 3 Years Later: Year One&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A while back, someone on Twitter (I can&#8217;t find the original conversation), asked me if I would consider writing up how I learned to program video games. I&#8217;m going to split this into several articles (for better or for worse) based around each year, and then one wrapping everything up with a big dump of the tools, articles, and books I&#8217;ve found incredibly helpful along the way. I thought splitting them up would be good because I&#8217;m only *a little* busy with moving back to Michigan and getting up to full steam on a project for IGF. </p>
<p>I think very few people will disagree that it&#8217;s a lot harder to get into the games industry than it used to be, being that there are so many more people interested in getting into the industry these days. I&#8217;ve been happily interning for these past months at <a href="http://www.irongalaxystudios.com/" target="_blank">Iron Galaxy Studios</a> where I do programming work commercial games, so I&#8217;d say that I at least got some important bits right. I think a lot of what I&#8217;ve done can manifest itself in a slightly different way for other prospective game developers, so hopefully these are helpful in some way to them.</p>
<p><strong>Year One</strong></p>
<p>When I started college, I knew I wanted to make video games for a living. However, like most college freshmen, I didn&#8217;t know how to make video games, but I did know that getting into the games industry was no cakewalk. One of my scholarships paid a stipend in exchange for working 10 hours a week under a professor, essentially a way for the university to get underclassmen involved in research without putting strain on a lab&#8217;s budget. Due to my interest in game development, I joined the MSU Games for Entertainment and Learning (GEL) Lab to work under Professor Brian Winn, but I suppose it was not the most opportune time to be a GEL Lab professorial assistant.</p>
<p>There was very little going on in the lab that year other than a small game design conference that we helped organize called Meaningful Play. However, beyond helping prepare for the conference, there was very little concrete game development work to hand me. Besides the lack of projects, I didn&#8217;t know a whole lot about game development. I can still remember not having a good answer about what part of developing games I actually liked doing when I first started in the lab. All I knew was that I liked programming in general from the few classes I had in High School, although game design still seemed like &#8220;the cool thing&#8221; at that point, and I thought that I would probably enjoy design more if I was given the chance (spoiler alert: programming is actually way cooler, but this won&#8217;t be discovered until year 2).</p>
<p>Contrary to what one might think, something very good came out of the lull of activity in the GEL. My commitment to GEL Lab was for 2 years, so Brian had me begin to teach myself how to use Unity with the hope that I&#8217;d be able to use it for future projects, being that the department had just adopted into the curriculum as its 3D engine of choice. As a result I had a conscious reason to teach myself game development, putting in at least 10 hours a week towards a small 3D project. I started with the standard tutorials, which are only really helpful for learning the menu flow. As with any first 3D game, the learning curve still felt steep even though I was using a fairly user-friendly engine like Unity. However, if you get a jolt of excitement from getting a cube to move back and forth across the screen for the first time in your life, then you know that game programming might actually be your thing. The project evolved into a small game that I presented at the end of my Spring semester. </p>
<p>It was <a href="http://jonmoore.squarespace.com/cabbage-quest-screenshots/" target="_blank">an action-adventure game about a manatee</a>. It was terrible, and my code base was even worse, but to this day I still love it (and amazingly its poster presentation won an award). What&#8217;s important here? I did everything, even the art, and I committed to spend at least a minimum amount of time on it each week. I learned so much, and I didn&#8217;t have things like fears of letting team members down, because I was the whole team.</p>
<p>Speaking of teams, I did get involved with Spartasoft, the student game development club, which was another important step toward being able to program a half-decent game. The club served a few primary purposes at that point, such as hosting a games party occasionally and getting alumni to come back and present to the club about their experiences in the games industry. However, the most important function for me was the 48 hour Game Jams that were hosted every few months. If you&#8217;re not familiar with the concept of a game jam, we basically split into small teams on a Friday evening, a theme is announced, and then each team makes a game about that theme over the course of 48 hours. It often results in a lot of terrible games, but inevitably there&#8217;s something new that&#8217;s learned, new game ideas explored, and a lot of friendships built with game developers that you might not otherwise get to know. I cleared my schedule for these as a Freshman, and participated in every single one.</p>
<p>It&#8217;s how I got connected with a couple of seniors, and I ended up putting in more than just 10 hours a week on one project in the Spring. I started meeting with them in between game jams to polish some of our better ideas. The fact that upperclassmen like Bert, a programmer that now works with me at Iron Galaxy, and Marie, an amazing artist that&#8217;s now a grad student at SCAD, wanted to work with some freshman was amazing. I had gotten past the hump for being able to contribute to a game at all. I could help make their games better, and because I was more than ready to step up to the task, I ended up learning a lot back from them.</p>
<p><strong>Conclusion</strong></p>
<p>So what can be learned from my first year making games? First, don&#8217;t be afraid to go it alone and force yourself to spend at least a minimum amount of time each week working on it. Secondly, game jams are great, especially if you don&#8217;t know very many people to collaborate with. Between the manatee game and the game jams, I had worked on 6 different games by the time I finished my first year of college. How many games had I worked on for class? Zero, and Michigan State even has a game development curriculum! If you have the opportunity to work on  *any* game when you&#8217;re just starting out, even a game jam game, you&#8217;d better have a damn good reason if you pass on it. Failing any opportunities for collaboration, the only person keeping you from making your own game is yourself. Don&#8217;t be the asshole that&#8217;s keeping you from learning how to make video games. I got lucky that I didn&#8217;t do that, it&#8217;s easy to be lazy when you&#8217;re an 18 year old college freshman.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/08/18/3-years-later-year-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backface culling 101</title>
		<link>http://www.altdevblogaday.com/2011/08/03/backface-culling-101/</link>
		<comments>http://www.altdevblogaday.com/2011/08/03/backface-culling-101/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 03:35:22 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Arts]]></category>
		<category><![CDATA[Backface Culling]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=12915</guid>
		<description><![CDATA[<p>This post is for artists, designers, and anyone else who has had backface culling shoddily explained to them. Perhaps I should have checked the Venn Diagram of AltDev readership before writing about a rendering technique specifically with non-programmers in mind. I know I&#8217;ve gotten embarrassingly confused by forgetting what&#8217;s important as little as 2 months ago.</p>
<p><a href="http://www.altdevblogaday.com/2011/08/03/backface-culling-101/" class="more-link">Read more on Backface culling 101&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This post is for artists, designers, and anyone else who has had backface culling shoddily explained to them. Perhaps I should have checked the Venn Diagram of AltDev readership before writing about a rendering technique specifically with non-programmers in mind. I know I&#8217;ve gotten embarrassingly confused by forgetting what&#8217;s important as little as 2 months ago.</p>
<p><strong>The &#8220;Simple&#8221; Answer is Misleading</strong></p>
<p>Backface culling comes up all the time when people are first becoming acquanted with 3D game dev. All it takes is deleting half of a cylinder in Maya and dropping it inside of an easy to use engine like Unity. Then they&#8217;re suddenly be trying to figure out what got screwed up that&#8217;s causing the inside of it to be invisible. Inevitably the answer given is that those faces are backface culled to avoid rendering the inside of 3D models. That&#8217;s true to some extent, but in my opinion very misleading.</p>
<p>The other part of the common answers is that backface culling works by only drawing the side with outward facing normals. This part, is not actually right and it leads to a lot of misunderstandings. I think this answer comes up because people like artists and designers are used to thinking of meshes in 3D space, rarely do people think about the process that turns it into a 2D image unless they get into rendering programming.</p>
<p><strong>The Triangles are not Drawn twice</strong></p>
<p>First off, understand that you have a big mess of triangles that you are using to represent your piece of art. One of the simplest representations of this is to have all the vertices in a big long list, and then to have a big long list of triangles defined from those points. Your computer is taking those triangles and transforming them into the 2D space that is displayed to you. That triangle is so simply defined to expedite rendering that it has no concept of &#8220;front&#8221; or &#8220;back&#8221; (well it does, but I&#8217;m getting to that). The vertices may have normal information, but that&#8217;s used for lighting, not culling. Consider a camera pointed at a half-cylinder that renders properly in the first case, with the following badly drawn diagram taken from above. The green lines are normals:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram1.jpg"><img src="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram1.jpg" alt="" width="440" height="320" class="aligncenter size-full wp-image-13239" /></a></p>
<p>Now consider the *exact same* list of triangles with the only change being to flip the normals at each vertex. If you try this on your own, it is probably best done by modifying your vertex list in the rendering code, for reasons that will be explained shortly.</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram2.jpg"><img src="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram2.jpg" alt="" width="440" height="320" class="aligncenter size-full wp-image-13242" /></a></p>
<p>With backface culling turned on, you will still see the cylinder in each image, except the lighting will be flipped in the second one. And if you turn off backface culling then the same images will be rendered, and it will be done so with the same number of triangles, because there are no backfacing triangles in the given example. Don&#8217;t think that the GPU is rendering the backside and then going over it a second time when you have backface culling turned off for the front side, unless you actually did specify two triangles in that big list of triangles with vertices in the exact same locations.</p>
<p>Assuming you understand that what I described is not what typically happens, let me now explain the point that I&#8217;m making. When you flip the normals in a 3D modeling package it&#8217;s doing more than just changing the vertex information, it&#8217;s also changing that triangle list. This is because the front and back face of a triangle are determined through the novel concept of winding order, which is quite simply that the front of a triangle is the side of the face where vertices are viewed counterclockwise. Suppose you have a mesh with no normal data, just positions in 3D space for vertices. You can still use backface culling just fine as long as your triangle list is specified in the proper order, a point that I think is often missed by designers and artists when trying to understand backface culling.</p>
<p>If you want the proof in the pudding, here&#8217;s the OpenGL call to specify culling:</p>
<p><em>glFrontFace(GLenum mode);</em></p>
<p>Where mode is either GL_CW or GL_CCW, standing for clockwise and counterclockwise, notice that this has nothing to do with vertex normals!</p>
<p>And here&#8217;s a diagram to illustrate which side is the front for a triangle by default (you could assume that triangles are front clockwise as your standard if you really want to, but the default is counterclockwise). If the points defining your triangle are listed in an order that would cause the diagram on the left to be true after transformed into screen-space, then that triangle is front facing:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram3.jpg"><img src="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram3.jpg" alt="" width="440" height="320" class="aligncenter size-full wp-image-13243" /></a></p>
<p><strong>So what are we culling again?</strong></p>
<p>We&#8217;re culling triangles <em>facing away from the camera</em>, which are going to be obstructed by the forward facing polygons on a closed mesh. Those triangles that would be drawing the inside of that cylinder are just going to be covered up by the front-facing triangles that you would actually see. With the winding order in hand, the triangle&#8217;s face normal can be determined and checked against the camera. I made this little diagram (insipred by the great explanation for backface culling in <em>Real-Time Rendering</em>). The triangles on the backside of the full cylinder are facing away from the camera, so they are culled (indicated by the dotted part).</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram4.jpg"><img src="http://altdevblogaday.com/wp-content/uploads/2011/08/Diagram4.jpg" alt="" width="440" height="320" class="aligncenter size-full wp-image-13246" /></a></p>
<p>So on a closed mesh like a full cylinder, you can avoid doing the work of rendering all of those triangles that you already know are going to be obscured. This is why disabling backface culling is typically not the correct answer when you have triangles culled that you didn&#8217;t intend to, and it&#8217;s also bad because that usually means that the backfacing triangles are being shaded incorrectly with backwards normals.</p>
<p>If you do intentionally cut that cylinder in half, the easy fix is to add front facing triangles along the inside of the mesh. I believe there is functionality these days (DX10 maybe?) to figure out which side of the triangle is being rasterized. Theoretically you could have the shader flip the normals based off of that information to still have correct lighting, but if you just read a post on the basics of backface culling, I bet that&#8217;s not what you&#8217;re looking to do.</p>
<p>Because 3D modeling programs are automatically adjusting the winding order for you based off of what direction your normals are, it&#8217;s easy to mistakenly think of backface culled triangles as triangles with incorrect normal information, when really it&#8217;s winding order that determines it. This is why sometimes you can really end up in weird situations while using a 3D modeling package. I know that as a Freshman in college, there were many models at game jams that had those stray triangles that artists just couldn&#8217;t get to show up, and maybe if they did the lighting got all weird. Perhaps thinking about what&#8217;s actually happening can help alleviate those pains.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/08/03/backface-culling-101/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obligatory FXAA Post</title>
		<link>http://www.altdevblogaday.com/2011/07/19/obligatory-fxaa-post/</link>
		<comments>http://www.altdevblogaday.com/2011/07/19/obligatory-fxaa-post/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 01:13:50 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[anti-aliasing]]></category>
		<category><![CDATA[FXAA]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=11529</guid>
		<description><![CDATA[<p>I did a quick search through AltDev and I don&#8217;t think anyone else has really talked about FXAA on AltDevBlogADay yet, but the time is long overdue. I&#8217;m a little late to the game trying out <a href="http://twitter.com/#!/TimothyLottes" target="_blank">Timothy Lottes</a>&#8216; post-process anti-aliasing technique, but I had been noticing people saying great things about it when I finally decided to give it a serious look over 4th of July weekend. I had already been thinking about writing about my experiences with it when I saw <a href="http://twitter.com/#!/pointinpolygon" target="_blank">Eric Haines</a> had posted up a <a href="http://www.realtimerendering.com/blog/fxaa-rules-ok/" target="_blank">glowing review of it over on realtimerendering.com</a>. So if you don&#8217;t trust the judgement of some intern that doesn&#8217;t even have a college degree completed, please refer to all the more qualified people that are having similar experiences to me.</p>
<p><a href="http://www.altdevblogaday.com/2011/07/19/obligatory-fxaa-post/" class="more-link">Read more on Obligatory FXAA Post&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I did a quick search through AltDev and I don&#8217;t think anyone else has really talked about FXAA on AltDevBlogADay yet, but the time is long overdue. I&#8217;m a little late to the game trying out <a href="http://twitter.com/#!/TimothyLottes" target="_blank">Timothy Lottes</a>&#8216; post-process anti-aliasing technique, but I had been noticing people saying great things about it when I finally decided to give it a serious look over 4th of July weekend. I had already been thinking about writing about my experiences with it when I saw <a href="http://twitter.com/#!/pointinpolygon" target="_blank">Eric Haines</a> had posted up a <a href="http://www.realtimerendering.com/blog/fxaa-rules-ok/" target="_blank">glowing review of it over on realtimerendering.com</a>. So if you don&#8217;t trust the judgement of some intern that doesn&#8217;t even have a college degree completed, please refer to all the more qualified people that are having similar experiences to me.</p>
<p><strong>The Problem at Hand</strong></p>
<p>For those of you that might be reading this and haven&#8217;t drank the graphics programming Kool-Aid, I&#8217;m going to fill you in a little bit as to why we care about anti-aliasing.</p>
<p>In our line of work, the end result of a rendered scene is typically a 2-dimensional array of colors that is displayed on the user&#8217;s monitor. Just like how audio (which is originally analog), is quantized when it is made digital, the image is built into a discrete number of pixels during the process of rasterization (i.e. filling in each triangle). The measure of how many pixels are used to display the image is of course known as the resolution, which is why things become increasingly blocky as you lower a game&#8217;s resolution, due to there being fewer dots per inch.</p>
<p>Even at high resolutions, individual pixels can still often be identified by the viewer, because the lines and edges of triangles form distracting &#8220;jaggies&#8221;. This is noticeable along the outline of an object being displayed due to rasterization, but can also occur on interior surfaces for other reasons such as shadows and texture map resolution. The user typically picks the resolution their monitors are set at, but most console games provide 720p or 1080p images to the TV, and monitors tend to follow suit (my laptop is set to ~720p). Other than relying on hardware to pack more pixels into the same physical area by increasing the dots per inch (which is something that Apple is claiming with it&#8217;s retina displays, but check out <a href="http://filmicgames.com/archives/698" target="_blank">this post for an interesting look at that</a>), we have to find ways to smooth the transition between pixels. Perhaps the simplest strategy to dealing with aliasing is to render into a texture twice as large as the target resolution and then downsampling it to actual output resolution. This allows you to take the average of every four pixels, softening out the boundaries by averaging the edge colors together. However, this also just straight up sucks for performance. You end up processing 4x as many fragments from the higher resolution, and you have 4x the memory usage for the buffer. This is way too high a cost to pay for some smooth edges.</p>
<p><strong>The Hardware Option</strong></p>
<p>There is a hardware accelerated method, MSAA (Multi-Sample Anti-Aliasing). This operates by computing additional samples when rendering the frame instead of rendering additional pixels and downsampling. The fragment shader is only run once for each group of samples. The problem is that it doesn&#8217;t work with the increasingly popular deferred rendering techniques, because you can&#8217;t really take more samples of a buffer you&#8217;ve already rendered. In short, the damage is already done, the data has been discretized to a particular resolution. Furthermore, I&#8217;ve always found that MSAA is still pretty expensive (but then again, the only way to make your rendering take 0 ms is to quite doing rendering and switch to a job in finance).</p>
<p><strong>New Maps of AA-land</strong></p>
<p>The desire to use deferred rendering has pushed alternate forms of anti-aliasing to get a lot of attention (I mean who doesn&#8217;t need more acronyms, right?). Perhaps the most prevalent that you may have heard of is MLAA, but most of the techniques that I&#8217;m referring to here are post-processing techniques that rely on detecting and softening edges. By doing anti-aliasing as a post-process, it will work seamlessly with deferred rendering, and pretty much anything else for that matter. If the technique only needs the color buffer access, then it can even be applied to video/screenshots/whatever of existing games, which I think researchers in this area have found as a great method of showing off how their work.</p>
<p>MLAA was originally a CPU based technique developed by Intel, that has since then been adopted to be done on the GPU. This has been outlined in GPU Pro 2, Game Developer Magazine, and around the net, but if you&#8217;re not familiar with it I&#8217;ll make a few brief points about it. It essentially boils down to storing edges in a texture with different colors indicating which side of the pixel the edge is located at, and an additional buffer is used to calculate the blending weights for the blurring.</p>
<p>Impressively, they found results falling somewhere between 4x and 8x MSAA, while being 11x faster than 8x MSAA. The memory footprint of the technique is 1.5x or 2x the size of the back buffer depending on the hardware (2x for the Xbox 360 for all you console devs who probably have already heard everything I&#8217;m saying). That&#8217;s pretty good for something that solves the problems encountered with deferred rendering at the same time. This is undoubtably why the technique has garnered so much attention, and I really recommend the article in GPU Pro 2 if you want a clear view of all of the details.</p>
<p><strong>Enter: FXAA</strong></p>
<p>As you may know from reading other posts, my big side-project/hobby/thing is that when I give a new technique a try, I do it in Unity because it <strong>a)</strong> is usually not straightforward and requires actually understanding the technique to get it working and <strong>b)</strong> can be evaluated using the many projects I&#8217;ve done in Unity previously. From looking over the details of MLAA, I knew it would probably take a full weekend to get it right, and I had been procrastinating quite a bit with getting around to doing it.</p>
<p>When the third iteration of FXAA rolled out I decided to take a look at what it entailed. I knew in the back of my mind that FXAA was a strictly luminosity based technique, which is interesting to me. The authors of MLAA recommend using depth to determine edges for best results and performance. However, luminosity based techniques offer the advantage/disadvantage of smoothing boundaries that exist in places other than depth, such as with aliasing on texture maps and with shadows. The downside is that this can produce results that are too blurry in places you don&#8217;t want blur, such as with text on a prop in 3D space. I once tried a very, very simple luminosity based AA filter, that resulted in too many cons (especially with blurry text) for me to seriously use. I was curious if FXAA would give me similar problems.</p>
<p>With the intention of just looking over the code briefly, I suddenly found myself staring at a very simple and easy to use code base offering a ton of well explained pre-processor options for target platform and quality. Being around midnight when I started looking, I quickly decided that porting the higher-quality PC version of the HLSL code to CG/Unity would be fun. There were two steps involved:</p>
<p><strong>1)</strong> At the end of all the other post-processing, calculate Luminosity and slam it into the alpha channel (super easy to do).<br />
<strong>2)</strong> Perform the FXAA pass. Porting mostly involved fixing texture look-up syntax.</p>
<p>No extra buffers involved. This cuts down on the extra memory needed for MLAA, and the code seemed simple enough that it would probably be pretty fast. I ported all the code within 2 hours and then went to sleep. The next morning I finished setting it up for use in Unity&#8230; and was blown away by the speed and the results. Here&#8217;s a breakdown of what I got running in the Unity editor at ~720p, using Dust, a previous project of mine, to test it. These are PNG&#8217;s cropped down at native resolution:</p>
<p><strong>Shot 1: No Anti-aliasing</strong></p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/SailNoAA.png"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/SailNoAA.png" alt="" width="440" height="320" class="aligncenter size-full wp-image-11650" /></a></p>
<p><strong>Shot 2: FXAA3</strong></p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/SailFXAA3.png"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/SailFXAA3.png" alt="" width="440" height="320" class="aligncenter size-full wp-image-11656" /></a></p>
<p><strong>Shot 3: 6x MSAA</strong></p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/Sail6xAA.png"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/Sail6xAA.png" alt="" width="440" height="320" class="aligncenter size-full wp-image-11657" /></a></p>
<p>It takes FXAA3 only ~1 ms [Note: corrected from an erroneous order of magnitude type when I first posted this article] on my laptop (MacBook Pro with an NVIDIA GeForce 320M) to be completed (including the luminosity calculation), and as I mentioned, no additional memory either. I&#8217;ll pay that millisecond any day of the week for that quality of anti-aliasing. Furthermore, the blurriness on text was much more acceptable than the fast blur I had tried previously. Note that this text is not really meant to be read, but rather recognized to match the voice over so the player can understand that the voice is that of the journal&#8217;s author. I wish I could credit the sources where I put together the fast blur from, but it&#8217;s been more than a few months since I implemented/ditched it. Here&#8217;s a comparison:</p>
<p><strong>Shot 1: No Anti-aliasing</strong></p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/TextNoAA.png"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/TextNoAA.png" alt="" width="440" height="320" class="aligncenter size-full wp-image-11658" /></a></p>
<p><strong>Shot 2: FXAA3</strong></p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/TextFXAA3.png"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/TextFXAA3.png" alt="" width="440" height="320" class="aligncenter size-full wp-image-11659" /></a></p>
<p><strong>Shot 3: Fast Blur</strong></p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/TextFastAA.png"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/TextFastAA.png" alt="" width="440" height="320" class="aligncenter size-full wp-image-11660" /></a></p>
<p>This is getting a bit more to the personal opinion end of things, but even though FXAA3 does blur the text, I feel like the fast blur makes it almost uncomfortable to look at. I get the sensation that I&#8217;m getting tested for a new prescription of glasses, and have to recognize out of focus letters. To me, that seems like a pretty good indication that your luminosity based AA technique isn&#8217;t up to snuff if you get that type of blurring. FXAA3 on the other hand seems acceptable enough that it&#8217;ll definitely be enabled in future builds of Dust that get pushed up onto my website.</p>
<p><strong>What did we learn?</strong></p>
<p>Hopefully we learned that FXAA is both fast and doesn&#8217;t require additional memory, and is trivially simple to implement or port. There are versions for the 360, PS3, and PC, as well as HLSL and GLSL variants. It&#8217;s a luminosity based solution, and comes with the associated pros/cons those techniques have, but I&#8217;ve found FXAA to minimize the cons. It should literally take you at most a few hours to get it up and running in your game and evaluate if it&#8217;s a good fit for what you&#8217;re doing. Furthermore, it is in the public domain (credit to the post by Eric Haines for this twitter snippet):</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/07/FXAAPublicDomain.jpg"><img src="http://altdevblogaday.com/wp-content/uploads/2011/07/FXAAPublicDomain.jpg" alt="" width="539" height="272" class="aligncenter size-full wp-image-11826" /></a></p>
<p>Although at this point, I&#8217;d the amount of quality you&#8217;re getting for the effort of implementation, it might as well be under <a href="http://en.wikipedia.org/wiki/Beerware" target="_blank">the beer license</a>. Finally, I would point out that Timothy Lottes is still improving on the code, and has already released version 3.9 in the time since I first touched it. You can find the latest source links and updates on his blog: <a href="http://timothylottes.blogspot.com/" target="_blank">http://timothylottes.blogspot.com/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/07/19/obligatory-fxaa-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Importance of a balanced Gamedev Curriculum</title>
		<link>http://www.altdevblogaday.com/2011/07/04/the-importance-of-a-balanced-gamedev-curriculum/</link>
		<comments>http://www.altdevblogaday.com/2011/07/04/the-importance-of-a-balanced-gamedev-curriculum/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 02:13:07 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://altdevblogaday.com/?p=10330</guid>
		<description><![CDATA[<p>I&#8217;m back in my hometown for the 4th of July, procrastinating on my Altdev post, which makes for the opportune time to put up another one complaining about improving gamedev education (it&#8217;s a past-time of mine). Well, maybe less whiny than some other posts I&#8217;ve done, this is really more advice for someone to value when choosing or building a curriculum at a university. I think I might have some insights for students, educators, and anyone else who just might be curious.</p>
<p><a href="http://www.altdevblogaday.com/2011/07/04/the-importance-of-a-balanced-gamedev-curriculum/" class="more-link">Read more on The Importance of a balanced Gamedev Curriculum&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back in my hometown for the 4th of July, procrastinating on my Altdev post, which makes for the opportune time to put up another one complaining about improving gamedev education (it&#8217;s a past-time of mine). Well, maybe less whiny than some other posts I&#8217;ve done, this is really more advice for someone to value when choosing or building a curriculum at a university. I think I might have some insights for students, educators, and anyone else who just might be curious.</p>
<p><strong>Motivation</strong></p>
<p>Chances are if you&#8217;re an educator at a University looking to start a gamedev curriculum, you have two routes to go.  One is to add game specific classes within your department, generally targeted at a specific discipline, so a computer science department adds a game programming class. The other, is to try to create inter-discipline courses, where designers, programmers, and artists can collaborate. At Michigan State University, we have both, and I&#8217;m the TA for the first class in our collaborative curriculum (which is set up a bit like a minor).</p>
<p>You might suspect that the collaborative environment is often the more desired, and I certainly am of that mindset. It adds much more value to an education to collaborate across disciplines on projects, because it offers opportunities that are much harder to get if you&#8217;re teaching yourself. I still value discipline specific classes teaching skills like graphics or mobile game design, but like I said, those things can be self-taught much more readily than collaborative game development.</p>
<p>However, one issue that I know we suffer from at MSU is a lack of balance among the disciplines. The four course collaborative track has served as a foundation for our game development curriculum, and additional programming and design specific classes have sprouted up to further grow the quality of gamedev education at MSU. However, our art program has not grown at nearly the same rate. This is largely due to reluctance of the Studio Art department to encourage non-traditional mediums. The 3D art/animation classes are taught through the same department that is the home of most designers, Telecommunications. That department is contains game design, film, audio production, television, and 3D art, so you can understand why it can be difficult for a program to flourish without strong backing from tenured faculty encouraging growth. However, we know that this is an issue and are encouraging improvement, I&#8217;m just going to take the opportunity in this post to explain why I think it&#8217;s so important to have a balanced curriculum.</p>
<p>This is something that was non-obvious to me when I was deciding where I would go to college, but if anyone asks me for advice on what to look for in a game development curriculum, this is the first thing I mention these days. I&#8217;d go so far as to say an opportunity to be in a program with at least mediocre programs for the other disciplines should have as much weight as the strength your specific discipline&#8217;s department.</p>
<p><strong>Distracting Flaws</strong></p>
<p>Projects are an important by-product of a collaborative curriculum. However, if one discipline is weak, it can be detrimental in all sorts of ways. It&#8217;s hard for students to showcase their amazing artwork if the game crashes constantly from poor programming, or for programmers to showcase their work when poor design causes players to lose constantly. The fact of the matter is that students are expected to invest a considerable amount of time into these projects, it&#8217;s unfortunate if they get they collapse quickly from a missing support. Not to say that working around limitations is not an important skill, but being able to create a well rounded game is important.  The University should see this as a problem as well, because even if students in the stronger disciplines are succeeding, there is a vacuum of publicity potential. If educators expect to be able to attract highly motivated and talented students, they need to show that their program empowers students to make quality work. The proof is in the pudding (yes I just used that phrase).</p>
<p><strong>A Lack of General Balance discourages Specialization</strong></p>
<p>I encourage people to specialize their focus as soon as possible, even if they change their mind about what they want to do. This complements small team collaboration, which often creates a more generalized environment. On a small team, there might only be one or two programmers. It&#8217;s entirely feasible for them to do an alright job on all of the core systems to make the game work, but when are they going to find the time to try out that cool pathfinding technique they learned about if they also have to find solutions for the fact that their artist hardly knows how to model let alone texture or animate?</p>
<p>Consistently weak team members creates a stressful work environment an can even shut off paths entirely for students. Why is someone going to learn to do quality game animations if the programmers repeatedly botch the animation control code? To me the best students are the ones that want to do the things that interest them most in addition to their core work. I hate to think that some might end up impeded from that if part of their team is failing to get its core work done.</p>
<p><strong>Concluding Thoughts</strong></p>
<p>I&#8217;m looking at this from the perspective of a student that has worked on some terribly balanced teams, but have also had the pleasure of working with some very talented artists at MSU, most notably the incredibly talented <a href="http://pixelbutterfly.com/">Marie Lazar (http://www.pixelbutterfly.com/)</a>. To be honest, the projects that I worked on at MSU that essentially had no designers or no artists, never even came close to making it into my portfolio. To me, that&#8217;s more than enough evidence to emphasize the importance of finding a place to learn where you have access to collaborate with decent individuals from disciplines from beyond your own. Missing links don&#8217;t go unnoticed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/07/04/the-importance-of-a-balanced-gamedev-curriculum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What do we really want from our rendering?</title>
		<link>http://www.altdevblogaday.com/2011/06/19/what-do-we-really-want-from-our-rendering/</link>
		<comments>http://www.altdevblogaday.com/2011/06/19/what-do-we-really-want-from-our-rendering/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 02:44:35 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=8643</guid>
		<description><![CDATA[<p>As of late on Twitter and elsewhere, I&#8217;ve had/read a few discussions about the goals of the time and energy poured into our pretty graphics, and I realized it might make an interesting blog post. I can still remember sitting in my first graphics programming class and hearing the professor talk about how it is the more often the goal to simulate film and photography than real life. This is a pretty broad generalization that I&#8217;ve found to actually hold true more often than not.</p>
<p><a href="http://www.altdevblogaday.com/2011/06/19/what-do-we-really-want-from-our-rendering/" class="more-link">Read more on What do we really want from our rendering?&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As of late on Twitter and elsewhere, I&#8217;ve had/read a few discussions about the goals of the time and energy poured into our pretty graphics, and I realized it might make an interesting blog post. I can still remember sitting in my first graphics programming class and hearing the professor talk about how it is the more often the goal to simulate film and photography than real life. This is a pretty broad generalization that I&#8217;ve found to actually hold true more often than not.</p>
<p>Even after I decided to write about this, I spotted this part of a fitting conversation between Emil Persson, John Carmack, and Stephen Hill:</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/06/Carmack1.jpg"><img class="aligncenter size-full wp-image-8644" src="http://altdevblogaday.com/wp-content/uploads/2011/06/Carmack1.jpg" alt="" width="361" height="328" /></a></p>
<p>This is actually a dilemma that is difficult to answer, and bears in mind questions about what other disciplines and groups have in mind. To me, the problem is that both approaches could be perfectly acceptable. In fact, I would go so far to argue that as broad generalization, that game players almost *want* to be put into a movie when they play a video game, often demanding increasingly cinematic experiences. On the other hand, I think a lot of gamers imagine the future as being &#8220;like you&#8217;re actually in the game,&#8221;  which strays more toward the argument that we want to mimic the human eye over the camera lens. Maybe thinking about what players want isn&#8217;t the right way to go about it, players want to have fun, and they don&#8217;t always want to understand why. I have a feeling designers would care even less about this issue, caring more about effectively immersing the player in their levels and plots, which is not entirely relevant here because though because this is more heavily dependent on the actual content of the game. We don&#8217;t care about content so much, we care about what the &#8220;eye&#8221; is.</p>
<p>The argument here is very much a discussion of whether or not rendering programmers are trying to simulate a film camera or a human eye, with a very significant part of that being the lens. If you&#8217;re not familiar, some effects used in video games such as depth of field and lens flares are largely due to issues with capturing images by using a camera, instead of directly with a human eye. Consider that these are some of the things that gamers rave about over every time a big title puts out a new trailer or demo, yet if it seems a little crazy that these things we sometimes try very hard to reproduce, are actually artifacts. I believe there are a couple factors at play here, a big one being that filmmakers have employed the classic &#8220;it&#8217;s not a bug, it&#8217;s a feature!&#8221; mentality and have often used these &#8220;flaws&#8221; to great effect, which ties directly into what Stephen Hill is arguing in that Twitter conversation. Depth of field in particular jumps to mind as an effect useful for storytelling, and even things like the poor film quality simulated in Tarantino and Rodriguez&#8217;s Grindhouse movies play a role in setting the mood, and I&#8217;m sure that such an effect could play a noticeable role in the right game. On the other hand, there&#8217;s this amusing little comparison between video games and photography that shows just how ridiculous this copying of camera flaws can get:</p>
<p style="text-align: center"><a href="http://altdevblogaday.com/wp-content/uploads/2011/06/HDR-in-video-games.jpg"><img class="aligncenter size-full wp-image-8777" src="http://altdevblogaday.com/wp-content/uploads/2011/06/HDR-in-video-games.jpg" alt="" width="480" height="499" /></a></p>
<p>Yet one has to admit that HDR bloom tends to get a good &#8220;wow&#8221; factor from players, which leads to programmers running around on the internet sarcastically shouting for &#8220;MOAR BLOOM.&#8221; After several experiences with team members boosting effects way too high (not to say I haven&#8217;t done this myself, the key is to expect to adjust it back down), I&#8217;ve begun to understand why so many graphics programmers hold the physical basis of what they are creating to be of upmost importance. That being said, is it a physical basis of a camera or a human eye? I&#8217;ve read papers that discuss the physical basis of how an effect occurs in a camera, and I&#8217;ve read papers that discuss how an effect occurs in an eye, so really either could apply. However, that reminds me of a similar discussion&#8230;</p>
<p><strong>Part 2: Reality or Art?</strong></p>
<p>A related and perhaps more interesting discussion, is whether what looks &#8220;good&#8221; or what is actually &#8220;correct&#8221; is more important. This is something that when I started making games, I wasn&#8217;t familiar with how technical this issue could get, but I think it stems from more than a few core deviations between artists and programmers. When it comes to visuals, everyone wants to have the &#8220;best,&#8221; but just like the debate of whether or not that means duplicating camera artifacts among rendering programmers, there is the question of whether or not the best result is the one that is most realistic or the one that the artists think is best.</p>
<p>In a simple world the answer is easy when both parties agree. However, as technology capabilities grow, there are many more chances for rendering programmers to implement systems that do a much better job of modeling how these effect happen in real life. As our graphics improve, art content may start to look different in fundamental ways. Shifting our techniques to draw from a more accurate physical basis can allow us to create even more stunning visuals, but when I was reading through the course notes for Naty Hoffman&#8217;s &#8220;<a href="http://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_b_notes.pdf">Crafting Physically Motivated Shading Models for Game Development</a>,&#8221; I wondered if suddenly changing the way the specular highlight behaves might have a traumatizing effects on artists. I can easily recall several artists and designers that I&#8217;ve worked with that would take the side that a physical basis is not nearly as important as achieving a &#8220;good look.&#8221; It doesn&#8217;t help that programmers are not artists, which I know can make a lot of artists doubt their credibility if they suddenly think an &#8220;improvement&#8221; makes their art look worse. And speaking as a programmer myself, it doesn&#8217;t help that sometimes we can be pretty stubborn ourselves, especially when the math has been proven out that the change makes for a more accurate simulation of real life.</p>
<p>This issue is something that I&#8217;ve become increasingly aware of from the excellent work of Naughty Dog&#8217;s John Hable, from which I&#8217;d like to draw a couple examples of where this debate can come into play. In Hable&#8217;s 2010 GDC presentation about some of the rendering techniques used in Uncharted 2, he discussed the importance of doing calculations in linear space. One consequence of this is that the diffuse falloff will be much sharper when calculations are done in the correct space. This is something that artists might initially might be turned off by, because have soft falloffs is supposed to be a good thing, right? But this is really just a case of not knowing what we really want, and Hable points out the lack of soft falloffs in the film Avatar, which as you may recall, was highly praised for its visual quality. In the realm of skin rendering, something that Hable is also involved in, it is often noted that as we account for subsurface scattering, we need to use detailed textures as input. Artists may have had the inclination to blur details in the textures themselves from wanting to account for the subsurface scattering. However, once programmers account for the scattering in code, they need to become aware that they no longer need to soften texture details to achieve the best results. If you&#8217;re interested in checking out some of Hable&#8217;s work for yourself, I highly recommend you visit his website <a href="http://filmicgames.com/" target="_blank">www.filmicgames.com</a>.</p>
<p>There will always be a great deal of approximations and fudge work involved in real-time rendering, but where the fudge work happens is a constantly moving target as graphics hardware continues expand the possibilities for what can be properly simulated. As this target moves, it also creates an environment that reminds me of something a graphic designer once told me about people that are truly pro status at using Photoshop: the people who really know what they&#8217;re doing can make a dozen smaller tweaks that are hard to notice on their own, but when put together the end result is stunning. I think the same can be said about the direction that rendering is going. Just remember that improvements are not always improvements in everyone&#8217;s eyes, let alone easy to notice, and it doesn&#8217;t help that we all mistakes and sometimes our &#8220;improvements&#8221; are actually in the wrong. It&#8217;s all fun and games until someone gets stabbed over chromatic aberration.</p>
<p><a href="http://altdevblogaday.com/wp-content/uploads/2011/06/carmack2.jpg"><img class="aligncenter size-full wp-image-8914" src="http://altdevblogaday.com/wp-content/uploads/2011/06/carmack2.jpg" alt="" width="359" height="179" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/06/19/what-do-we-really-want-from-our-rendering/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Death of a Project</title>
		<link>http://www.altdevblogaday.com/2011/06/04/death-of-a-project/</link>
		<comments>http://www.altdevblogaday.com/2011/06/04/death-of-a-project/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 04:27:19 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=7493</guid>
		<description><![CDATA[<p>This is actually the follow up to my article on my <a href="http://altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/" target="_blank">adventures with Off-Screen Particles in Unity</a>, but being that it ended with me deciding to kill the feature, I&#8217;ve decided that my process towards doing so would make a much more interesting post. I feel that knowing when to throw in the towel or radically change approaches is a good skill to have when developing any game, especially because this is the type of engineering endeavor where “seems right” and “ships on time” is so much more important than things like “is actually right” or “bridge you&#8217;re engineering doesn&#8217;t collapse when the wind blows”.</p>
<p><a href="http://www.altdevblogaday.com/2011/06/04/death-of-a-project/" class="more-link">Read more on Death of a Project&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is actually the follow up to my article on my <a href="http://altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/" target="_blank">adventures with Off-Screen Particles in Unity</a>, but being that it ended with me deciding to kill the feature, I&#8217;ve decided that my process towards doing so would make a much more interesting post. I feel that knowing when to throw in the towel or radically change approaches is a good skill to have when developing any game, especially because this is the type of engineering endeavor where “seems right” and “ships on time” is so much more important than things like “is actually right” or “bridge you&#8217;re engineering doesn&#8217;t collapse when the wind blows”.</p>
<p><strong>Context</strong></p>
<p>An important thing to keep in mind when you&#8217;re working on a feature is the context of why you&#8217;re doing it. This includes everything from how much time you can allocate for working on it to how much it impacts the user experience in your final product. In my case I was trying out a potential optimizations to hopefully allow an early prototype from a designer become feasible, which was not due to his heavy use of particles to create a dust storm, causing performance issues from heavy overdraw. This in itself is an important thing to keep in mind when doing an optimization, is whether  or not what you&#8217;re optimizing is actually a bottleneck in your game.</p>
<p>In my case, I knew the overdraw was becoming an issue because I: <strong>1)</strong> reviewed possible reasons why our tons of particles could hurt our performance (to be fair, I was already a little familiar with the issue: knowledge is power!), <strong>2) </strong>tested the effects of changing things like particle size, count, screen resolution, and <strong>3)</strong> attempted to kill the designer for not using Unity&#8217; nifty overdraw visualization in the first place (Side note: attempting to kill a designer should only happen if you work in a strictly unprofessional environment, like a University lab, and will rarely have a direct impact on perf).</p>
<p>After identifying the problem, the next thing to do was decide how I could address it. Because the particles had only a minor impact on gameplay, the team cut it at the time and focused our efforts elsewhere for our deadlines at the time. However, I knew that being able to ramp up the particle density would really enhance the look and feel of the game, so I kept the problem as a side project.</p>
<p><strong>Ramping Up</strong></p>
<p>The project was slow to get started, due to it being on the back burners for some time. I started to really make progress on it when we were transitioning to hopefully ramp up our work on the game once again after many other projects that had been distracting team members for some months began to wind down (this is a continual problem in a University setting, but that&#8217;s a story for a different day). I knew that the feature would be important if the proposed design changes happened, and that the work would be wasted if the designers went ahead and designed new zones without the feature at their disposal early on. With this in mind, the project quickly rose to a much higher level of significance. I spent a lot of time when I wasn&#8217;t with the team cracking away at my work, and putting extra hours in at this point can often pay off.</p>
<p>Putting in that extra effort at the right time can really pay off. I quickly began to see measurable results and progress. The implementation that I discussed last time does have a substantial impact on a scene I brewed that&#8217;s mostly particles at a density similar to what design wanted, resulting in a greater than 10 ms performance increase in my test scene at a 1280&#215;720 screen resolution when rendering particles to a buffer smaller by 2x. I could do even better than that when using a 4x smaller buffer. That clearly identified two things: <strong>1)</strong> that the feature warranted further refinement and <strong>2)</strong> that I was right about the bottleneck, as the increase in perf proved that I was not wasting time going down the wrong path. However, in my first post I detailed artifacts that are noticeable in our particular game, and that I intended to explore the mixed resolution rendering as a solution to those issues.</p>
<p><strong>Spotting the Wall</strong></p>
<p>I knew that going to mixed resolution would require substantially more resources for the rendering and compositing of multiple passes, but would also allow me to get away with using a 4x decrease in our smaller buffer. So I started out with the intention of laying it out as simply and as efficiently as possible, and then tune from there.</p>
<p>After a little more work, I had it: mixed resolution off-screen particles. They had some room for quality improvements, but they definitely did a lot to fix the artifacts from before. I had also gained something else: my offscreen particles rendered with almost <em>no </em>increase in perf. I had lost all of my savings from my earlier work, which also meant that I may have moved my bottleneck as well.</p>
<p>I had a couple options at this point: <strong>1)</strong> tediously work to increase perf and quality at the same time, <strong>2)</strong> scrap mixed resolution and try to find another solution, or <strong>3)</strong> kill it. The first option bears the weight of what would most likely be a lot of work on a project that I only have a limited amount of time to work on, and is especially difficult to do without source level access. I did try a couple quick and dirty thoughts on the second option, but going back to the drawing board has its own costs associated with it.</p>
<p><strong>So I Killed It</strong></p>
<p>It&#8217;s not easy to kill something, especially when early work shows promise. However, it&#8217;s an important thing to be able to do. I have other things to be poking around at in my spare time, and a feature that the game can live without is certainly not worth it. I had invested a reasonable amount of time into the feature already, but that didn&#8217;t mean it was worth further pursuit. I suspect further work on it would be roughly equivalent to doubling the scope of the feature. Your time is always one of your most valuable resources, especially when code familiarity in itself makes you a valuable asset to your team. Getting stuck with your wheels spinning on a feature that isn&#8217;t worth the benefits for the work isn&#8217;t going to help anything, no matter what discipline you&#8217;re in.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/06/04/death-of-a-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Game Programming Interviews and Tests: Entry Level Edition</title>
		<link>http://www.altdevblogaday.com/2011/05/20/game-programming-interviews-and-tests-entry-level-edition/</link>
		<comments>http://www.altdevblogaday.com/2011/05/20/game-programming-interviews-and-tests-entry-level-edition/#comments</comments>
		<pubDate>Fri, 20 May 2011 02:13:17 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=6190</guid>
		<description><![CDATA[<p>I&#8217;m starting to realize that most of my blog posts begin with me making excuses about something as well as linking to somebody else&#8217;s post or article. Spoiler alert, today will be no different. The excuse is that this post is not my follow-up to my last one about my <a href="http://altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/" target="_blank">initial adventures with off-screen particles</a>, due to a lack of time to work on it while moving into a new place and also some disappointing results with mixed resolution rendering. So what I&#8217;m talking about instead is my experiences with interviewing for programming intern positions throughout this past Spring. A while back, Jaymin did a great post <a href="http://altdevblogaday.com/2011/02/15/on-demos-and-programming-tests-rant-from-a-q-games-test-reviewer/" target="_blank">about programming tests and demos</a>, but I feel like I might have some insights for aspiring entry-level game developers.</p>
<p><a href="http://www.altdevblogaday.com/2011/05/20/game-programming-interviews-and-tests-entry-level-edition/" class="more-link">Read more on Game Programming Interviews and Tests: Entry Level Edition&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting to realize that most of my blog posts begin with me making excuses about something as well as linking to somebody else&#8217;s post or article. Spoiler alert, today will be no different. The excuse is that this post is not my follow-up to my last one about my <a href="http://altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/" target="_blank">initial adventures with off-screen particles</a>, due to a lack of time to work on it while moving into a new place and also some disappointing results with mixed resolution rendering. So what I&#8217;m talking about instead is my experiences with interviewing for programming intern positions throughout this past Spring. A while back, Jaymin did a great post <a href="http://altdevblogaday.com/2011/02/15/on-demos-and-programming-tests-rant-from-a-q-games-test-reviewer/" target="_blank">about programming tests and demos</a>, but I feel like I might have some insights for aspiring entry-level game developers.</p>
<p><strong>The Hunt</strong></p>
<p>I started my hunt for getting professional development experience by testing the water by sending out a few intern applications during my second year of college. The first step to getting any job is to actually apply for it. Typically this happens online these days, especially for intern positions. This brings me to my first point: looking good on paper counts for something. No matter what, you have to look appealing enough for a company to think about investing the time to actually talk to you. This was evident because, even though I was completely unqualified at the time, I scored a programming test for the Insomniac core team. I&#8217;m sure the only reason that happened was because I didn&#8217;t let my grades slip during my first two years of college (proving that even the most painful &#8220;general education&#8221; class in existence still counts for something), and I also had experience working on several game development projects around the University. In short, I looked good on paper. Having a well thought out resume and portfolio are crucial, and the evidence adds up both from responsiveness to online applications and responsiveness from studio representatives at job fairs, such as the annual career pavilion at GDC.</p>
<p>After making it past the first hurdle, there are typically a two things that happen next. You will almost always need to do a technical interview and a programming test, although the order that they happen can vary. The Insomniac test was proof that I wasn&#8217;t qualified yet, but at least it showed me what I needed to do to get past that initial challenge of getting noticed in the ever growing pool of fresh applicants looking for work in game development. So what exactly is in a programming test and how should you prepare?</p>
<p><strong>The Test</strong></p>
<p>For an intern, most tests are emailed to you, and you typically have a specified period of time to send it back. I&#8217;ve had several tests structured as a small programming project, in the style of typical work required to make a video game from the ground up. Anything that requires a substantial amount of work for a single problem is usually very generic in nature, so don&#8217;t expect heavy AI or Graphics problems if the position isn&#8217;t specifically for that discipline. Some of the more “small project” style questions that I&#8217;ve had have included memory management, binary file I/O, basic 2D collision detection, and string parsing. Almost every test requires C/C++ to be used, so make sure you&#8217;ve had practice! Also, take Jaymin&#8217;s advice about showing a smart answer instead of a correct answer. Most problems have many solutions, is yours clean and optimized, and does it handle a good spread of use cases?</p>
<p>Some tests are limited to just a few hours, and I tend to find those to be more towards the stressful end. Perhaps the hardest test that I ever took was a 17 page short answer onslaught crammed into the span of 3 hours. It had required sections on bug finding and solving (things like what to do if the game crashes in release only, in a soak test with no memory leaks, etc), short answer code writing (think bit twiddling, list reversing, basic assembly writing, etc), and math problems (involving vectors, matrices, and trig) together forming the first 12 pages, and then 4 optional sections on gameplay, graphics, core, and networking programming (the remaining 5 pages). For me, it highlighted just how different a test could be from the “small project” style test.</p>
<p><strong>Interviews</strong></p>
<p>A technical interview tends to feel different in nature than a programming test, which was surprising to me the first time I had one. One thing that you should know before any interview is the difference between a struct and a class in C++, this is a question that gets asked over and over again, partly to break the ice. More than three quarters of my interviews have started with that question. Be prepared to know about inheritance, virtual functions, dot products, cross products, const correctness, cache use, and game engine design. Also make sure that you&#8217;re prepared to talk about game projects you&#8217;ve worked on, especially those you have on your resume or portfolio. Typical questions about your work include asking about your individual contributions to group work, what kind of difficult problems have you overcome, and if what is something (maybe just part of a project) you&#8217;ve worked on that you wish you could go back and redo.</p>
<p>Something telling of being a programmer is that no one has <em>ever</em> asked me if I have played games made by their company, where as I know designers that have had tons of questions about redesigning games made by the company they were interviewing with. Don&#8217;t sweat it if you haven&#8217;t had a chance to pick up a company&#8217;s latest game, spend your time refreshing yourself about the details of multiple inheritance and less commonly used C++ keywords instead. If anything, you might be asked what games you&#8217;ve been playing recently, just to make sure you play <em>some</em> games.</p>
<p><strong>Rejection</strong></p>
<p>Be prepared to not have everything go smoothly the first couple jobs you interview for. I&#8217;ve botched tests and interviews alike, sometimes from things completely out of my control, but the important thing was that I kept working to improve myself as a programmer afterwards. Have you read Jason Gregory&#8217;s excellent <em><a href="http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/ref=sr_1_1?ie=UTF8&amp;qid=1305857076&amp;sr=8-1" target="_blank">Game Engine Architecture</a></em>? Do you have projects where you can show how you specifically contributed? Can you get involved with a mod group or a student club or a <em>something</em> to get experience working with others? Have you done projects completely on your own?</p>
<p>I&#8217;ve heard for a long time that game industry jobs require personal connections and luck, but to be honest you just have to be at a certain level of experience as programmer and be able to prove it. I&#8217;ve always maintained that the key is to get a feel for what that level is, and then set your goals accordingly. Make sure you feel like you&#8217;re continually getting closer to that end goal of landing a job (and in a work environment that suits you best!). If it seems hard, that&#8217;s because it&#8217;s certainly no cake walk to get there in 3 or 4 years time. This is especially because until you have a game development job, you usually have to spend time doing things like going to class or working a non-games related job. I attended a talk at my university last Fall about interviews and tests for general software engineering jobs, and I left knowing that non-game industry interviews are laughably easy in comparison, even for &#8220;top-tier&#8221; companies. It&#8217;s not easy, so keep at it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/05/20/game-programming-interviews-and-tests-entry-level-edition/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adventures with Off-Screen Particles</title>
		<link>http://www.altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/</link>
		<comments>http://www.altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/#comments</comments>
		<pubDate>Thu, 05 May 2011 03:10:19 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://altdevblogaday.org/?p=5168</guid>
		<description><![CDATA[<p>This is hopefully going to be a two part post because I didn&#8217;t get to fully explore it as much as I wanted to, as I&#8217;ve been losing my mind during another eventful week of final exams in college. I considered postponing this and pulling something out of my ass for today&#8230; but then I saw fellow contributor Wheezie had already stolen that spot with his post <a href="http://altdevblogaday.com/2011/05/03/what-did-i-do-today/" target="_blank">“What Did I Do Today?</a>” If you haven&#8217;t already, you should check it out to at least read the amazing comic that he put at the end of it. Especially because half of the time I don&#8217;t think people who aren&#8217;t designers understand what designers actually do. I mean, it&#8217;s pretty clear that graphics programmers spend all their time inventing new acronyms for anti-aliasing techniques except for when they&#8217;re tightening up the graphics on level 3, but designers- they&#8217;re a whole different mystery. Wait, what was I actually going to be talking about in this post? Particles, that&#8217;s right&#8230;</p>
<p><a href="http://www.altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/" class="more-link">Read more on Adventures with Off-Screen Particles&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is hopefully going to be a two part post because I didn&#8217;t get to fully explore it as much as I wanted to, as I&#8217;ve been losing my mind during another eventful week of final exams in college. I considered postponing this and pulling something out of my ass for today&#8230; but then I saw fellow contributor Wheezie had already stolen that spot with his post <a href="http://altdevblogaday.com/2011/05/03/what-did-i-do-today/" target="_blank">“What Did I Do Today?</a>” If you haven&#8217;t already, you should check it out to at least read the amazing comic that he put at the end of it. Especially because half of the time I don&#8217;t think people who aren&#8217;t designers understand what designers actually do. I mean, it&#8217;s pretty clear that graphics programmers spend all their time inventing new acronyms for anti-aliasing techniques except for when they&#8217;re tightening up the graphics on level 3, but designers- they&#8217;re a whole different mystery. Wait, what was I actually going to be talking about in this post? Particles, that&#8217;s right&#8230;</p>
<p><strong>Particles</strong></p>
<p>Particle systems are cheap, flexible, and easy to set up, especially if you&#8217;re using Unity3D, as is often the case with the projects happening at my University.  This is why on a lot of my projects that I&#8217;ve been on (small student projects with tight deadlines), a designer often picks up the task to reduce the workload of other team members. This was the case with one such project that I was working on the fall. That project was <em>Dust</em>.</p>
<p style="text-align: center"><a href="http://altdevblogaday.com/wp-content/uploads/2011/05/DustScreen.jpg"><img class="aligncenter size-full wp-image-5173" src="http://altdevblogaday.com/wp-content/uploads/2011/05/DustScreen.jpg" alt="" width="400" height="300" /></a></p>
<p>As you might guess from the name, there&#8217;s a lot of dust in Dust. So much so that it takes place in a desert. Some of the designers on the project were tasked with helping to build the ambience for the game with some particle systems. An innocent enough task, but when it came time to integrate the work into our initial prototype, it was clear something was awry. </p>
<p>The problem with video game content creation is that people often have to learn the hard way how their work can impact performance. In this case, we wanted substantially more particles than anything other than a top of the line computer could accommodate (like the one we had been working on). And to be fair, a game like Dust should have as many particles as we can manage to have without blowing perf. One of the biggest impacts on performance from large numbers of particles is overdraw, especially when the particles are filling large sections of the screen:</p>
<div id="attachment_5183" class="wp-caption aligncenter" style="width: 494px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/05/Overdraw.jpg"><img class="size-full wp-image-5183  " src="http://altdevblogaday.com/wp-content/uploads/2011/05/Overdraw.jpg" alt="" width="484" height="268" /></a><p class="wp-caption-text">Massive overdraw from dust particles</p></div>
<p>This is a shot of the Unity editor&#8217;s visualizer for overdraw.  The bright areas are spots where many pixels are being drawn over and over again. This is particularly an issue with particles because the system contains many overlapping quads, where pixels will be drawn over many times. Keep in mind that the given shot is from the current version of Dust, his systems were originally much, much heavier on overdraw.</p>
<p><strong>Doing it Offscreen</strong></p>
<p>A solution to this particular consequence of particle effects is presented in the fabulous <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch23.html" target="_blank">GPU Gems 3 by Iaian Cantlay</a>. The technique boils down to reducing the number of pixels being rasterized by rendering the particles to a texture that is then composited back into the main image. The rendering   is done after a depth buffer has been formed, so that the pixels in the particles that fail the depth test can be discarded properly as you render them. This means that the color can be applied directly back into the scene, which is especially easy if your particles are additive like ours were.</p>
<p>I started considering it as a possible solution to allow for thicker particles in future iterations of the project when I read through Shawn White&#8217;s <a href="http://technology.blurst.com/off-screen-particle-optimization/" target="_blank">post on his implementation in Unity</a> for Off Road Raptor Safari HD. It didn&#8217;t take too long for me to adapt my own implementation a week or so ago, but there are definitely several issues that come to light very quickly (many of which are discussed in the GPU Gems 3).</p>
<p><strong>Problems / Solutions</strong></p>
<div id="attachment_5189" class="wp-caption aligncenter" style="width: 460px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/05/SailCracks.jpg"><img class="size-full wp-image-5189" src="http://altdevblogaday.com/wp-content/uploads/2011/05/SailCracks.jpg" alt="" width="450" height="265" /></a><p class="wp-caption-text">Zoomed in view of cracks from point sampled depth</p></div>
<p>Some of the issues that I immediately encountered were visible halos between solid objects (notably the boat that the player controls in Dust) and particles after compositing. One solution to this problem is to have the depth buffer, which is being down-sampled due to the low-res target, take the minimum or maximum depth to be used when downsampling. As noted in the gems article, this is really just a rule of thumb, but it did indeed fix issues with cracks.</p>
<div id="attachment_5190" class="wp-caption aligncenter" style="width: 460px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/05/DepthFarthest.jpg"><img class="size-full wp-image-5190" src="http://altdevblogaday.com/wp-content/uploads/2011/05/DepthFarthest.jpg" alt="" width="450" height="318" /></a><p class="wp-caption-text">Zoomed in view of depth farthest heuristic</p></div>
<p>However, it made it apparent that the much more serious issue is the aliasing that occurs due to the buffer being a lower resolution. It&#8217;s very obvious along the edge of the sail in Dust. My goal was to get the particles to render at quarter res, but right now only half res comes close to an acceptable quality. One thing I could do is render the edges at full res in yet another pass, but the big question in my mind is whether or not two passes for particles would still result in a performance increase. We already have to create a depth buffer specifically for the purpose of the off-screen particles, because we don&#8217;t do deferred rendering, it&#8217;s not used for much else.</p>
<p><strong>Next Time</strong></p>
<p>Hopefully by the time my next post rolls around (and I&#8217;m done with finals), I&#8217;ll have some more results (and perf numbers) and give some insight onto whether or not we decide to actually use it in the game. On the plus side, we modified Dust&#8217;s design recently to be more separated, so potentially we can split it so that it&#8217;s only in effect where the particles are prevalent enough to warrant its use. Also, I&#8217;ll try to set up some fresh test scenes that show the effects better, considering that upsampling the in game shots went horribly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/05/05/adventures-with-off-screen-particles/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Give Blood</title>
		<link>http://www.altdevblogaday.com/2011/04/20/give-blood/</link>
		<comments>http://www.altdevblogaday.com/2011/04/20/give-blood/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 04:19:34 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=4502</guid>
		<description><![CDATA[<p>I started writing this post on my 21<sup>st</sup> birthday (this past Sunday), so it&#8217;s going to be pretty frivolous and might not teach you anything-but hey, you&#8217;ve been warned. Because it&#8217;s my birthday, I&#8217;ve been thinking about my successes and failures that I&#8217;ve had growing into the game developer that I am today. A bit of a postmortem of going from being a kid that loved video games and math to heading into my final year of college with more than a few games under my belt.</p>
<p><a href="http://www.altdevblogaday.com/2011/04/20/give-blood/" class="more-link">Read more on Give Blood&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I started writing this post on my 21<sup>st</sup> birthday (this past Sunday), so it&#8217;s going to be pretty frivolous and might not teach you anything-but hey, you&#8217;ve been warned. Because it&#8217;s my birthday, I&#8217;ve been thinking about my successes and failures that I&#8217;ve had growing into the game developer that I am today. A bit of a postmortem of going from being a kid that loved video games and math to heading into my final year of college with more than a few games under my belt.</p>
<p>I decided I wanted to be a game developer when I was in 7<sup>th</sup> grade, which is now 8 years in the past (I&#8217;m a junior in college now). This decision was met with resistance from most people that I knew, but I was really serious about it. Most people thought I&#8217;d grow out of it and choose to do something that “made a difference”, especially those who knew that up until that point I was a kid that wanted to make use of my love of math and science at NASA working as a researcher.</p>
<p>Clearly, I didn&#8217;t grow out of it. I suppose that it didn&#8217;t help that I was already very aware that it was “nearly impossible” to get into the games industry. With this in mind, I managed to get a bunch of scholarship money at a private school on the other side of town for one reason: computer science classes. I didn&#8217;t make games in high school (and I&#8217;m glad I didn&#8217;t – I needed to be a kid), but getting serious about programming years before college was one of the best things to happen to me. Exposure to code before college helps so much farther down the line (by the way check out Brett Douville&#8217;s awesome post about <a href="http://altdevblogaday.com/2011/03/18/the-apprentice/" target="_blank">teaching his son about programming</a>). But still, I knew that I had a great deal of work was ahead of me because I knew how hard it was to get a job.</p>
<p>Not that long ago, this video surfaced about game development:</p>
<!--YouTube Error: bad URL entered-->
<p>To put my thoughts at the time into perspective, I acted a bit like I had that video running on repeat in my head (even though that particular video didn&#8217;t exist yet). I made the decision to attend Michigan State University largely for financial reasons, but also because of job opportunities with the game development lab I currently work for. Attending a large university was a bit worrisome to me, given that I didn&#8217;t think a diverse program could compete with a specialized school like Digipen or Full Sail. I felt like I had to work my ass off to make up to what I would probably be missing from class. I got involved with Spartasoft, MSU&#8217;s game development club, and vigilantly attended every game jam that year. By the time the year closed, I had worked on no fewer than six games of varying sizes, and was starting to get interested in writing shader code. To say the least, I was working hard and was perhaps overreacting a bit to my worries that I might be getting a “lesser” education.</p>
<p>Freshman year was also the year that I watched many of the seniors that mentored me fail to get jobs.  The industry was starting to feel the pains of the recession and things were rough, and it scared the shit out of me. No matter how hard I was working that year, I pushed myself into overdrive the next year. I was involved with a team in a game development competition that ended up winning a trip to GDC paid for by Ford Credit. Being an underclassmen on the team as well as the primary programmer, it would be the first project I seriously crunched for, but I&#8217;m glad I did because going to GDC that Spring changed my perspective about everything.</p>
<p>Up until that year, I suffered from something that I suspect afflicts many young programmers. <em>I thought I could be both programmer and designer</em>. I mean design gets all of the glory right? Every kid wants to be the next Miyamoto or the next Ken Levine, and I still reveled in the thought. But that year I would finally get enough experience to realize that design is really hard and you might kill yourself if you try to be both a good programmer and a good designer. Still, I thought maybe gameplay code was the place for me, or a scripting heavy design position. And then GDC hit me like a train hitting a chicken, blowing apart all my thoughts about game development as a career. The fact of the matter is that engine code is really cool, tool development is incredibly important, and hand optimizing assembly code makes you a badass. I had started to become interested in graphics and rendering, and John Hable&#8217;s presentation about HD rendering in Uncharted 2 convinced me that I wanted to do graphics code professionally. If you get the chance, check out some of his presentations and <a href="http://filmicgames.com/" target="_blank">his website</a>, there&#8217;s some great stuff there.</p>
<p>Going along with these newfound desires to work on lower level systems, I once again decided I wasn&#8217;t working hard enough and hurled myself further into my work for the next year. I had the portfolio development class for MSU&#8217;s game specialization that fall, and I began pulling tons of late nighters and all nighters for my games. I look back on college and realize having a laptop and being able to take my work everywhere with me was both a blessing and a curse. I got to the point where I got a feature implemented into a game while in the back seat of a car on a coffee run. I was out of control, wanting to learn and accomplish so much, so fast. So was it worth it? Now that you&#8217;ve read through several paragraphs of me admitting to crunching increasingly more throughout college, I&#8217;m going to finally get to my point.</p>
<p>For the first Spring in a long time, I don&#8217;t feel like college is a time bomb with only so much time left. Three years of increasingly stepping up my dedication to learning the art of game development has finally lead me to become the programmer I want to be. Maybe I worked too hard at times, but it&#8217;s no small task to become a programmer cut out for game development in just four years time. The way I viewed life, if you want to get a job in the games industry, you have to become a good game developer, and the only way that that will happen is if you love making games and learning how to make even better games. I went back to GDC this year, and I&#8217;ll be back again next year, because I love learning about all the crazy techniques people are developing and trying. People talk about how you have to have connections to make it as a game dev (what are we, <em>film?</em>), but I honestly think that&#8217;s bull shit. I don&#8217;t want your card because I want a job, I want your card because I want to be friends with people riding the edge of what games can do (speaking of which, props to <a href="http://www.youtube.com/watch?v=2zw8SmsovJc">the Battlefield 3 team</a>). If you want to make games throw yourself at it, because only <em>you</em> can make yourself a crack game developer.</p>
<p>When I&#8217;m walking to the lab and I feel like I&#8217;d rather go home and sleep through the afternoon, I listen to one song consistently. It&#8217;s called “Ali vs. Frazier 1” by a Massachusetts hardcore band named Bane. I think it summarizes my view&#8217;s on what it takes to become successful at anything worthwhile, including game development:</p>
<p style="text-align: center"><em>(rumble, young man, rumble)</em><br />
<em>how many more days will you sit</em><br />
<em>and talk about your ambitions</em><br />
<em>all that you can be</em><br />
<em>the person you are dying to be</em><br />
<em>the place you want to get to </em><br />
<em>but always out of reach</em><br />
<em>before that fury swells inside of you </em><br />
<em>grows so big that it forever quiets you</em><br />
<em>stand up to your demons</em><br />
<em>make a run at your goliath</em><br />
<em>find the best, find the worst</em><br />
<em>waiting in both of you</em><br />
<em>it&#8217;s not the who or the what that is lasting</em><br />
<em>but how you fight</em><br />
<em>that is the fight</em><br />
<em>the only mark that will not leave you </em><br />
<em>and I will feel my heart drum its final beat</em><br />
<em>if it meant that I have given this my all</em><br />
<em>there&#8217;s nothing left for me to believe in</em><br />
<em>if not your, if not this&#8230;</em><br />
<em>what else is there but death?</em><br />
<em>(it&#8217;s your call&#8230;it&#8217;s all on you)</em><br />
<em>give more</em><br />
<em>give everything</em><br />
<em>give blood </em></p>
<p><em><span style="color: #000000"><span style="font-family: ArialMT, sans-serif"><span style="font-size: medium"> </span></span></span></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/04/20/give-blood/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Image Space for Beginners</title>
		<link>http://www.altdevblogaday.com/2011/04/04/image-space-for-beginners/</link>
		<comments>http://www.altdevblogaday.com/2011/04/04/image-space-for-beginners/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 23:56:13 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=3046</guid>
		<description><![CDATA[I’m doing a relatively simple post today because I’ve had way too many milestones and sleepless nights in the past 7 days. This is why I’m going to talk about a very basic concept for graphics programming: doing image space calculations and effects. I realize that there are many seasoned game developers that frequent this blog, but this one is for the ones who are just getting started.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m doing a relatively simple post today because I&#8217;ve had way too many milestones and sleepless nights in the past 7 days. This is why I&#8217;m going to talk about a very basic concept for graphics programming: doing image space calculations and effects. I realize that there are many seasoned game developers that frequent this blog, but this one is for the ones who are just getting started.</p>
<p><strong>Tools and Motivation</strong></p>
<p>As a developer of a real-time graphics technology (video games), you are almost certainly going to be making use of a GPU to accelerate your graphics processing.  The GPU exploits high parallelization of rendering to speed up its work, and is responsible for transforming your 3D world into a 2D plane that is displayed to the player on their computer scene. However, not all effects are easy to simulate in a 3 dimensional space.  Thats where leveraging further work on the GPU to perform additional image space calculations can come in handy. Some of these are quite obvious, such as depth of field calculations, being that depth of field is an artifact of lenses. Other popular image space effects include motion blur, color correction, and anti-aliasing.  Image space calculations are also the foundations of deferred shading and lighting, rendering techniques that are becoming increasingly popular to handle a large number of lights in a scene.</p>
<p><strong>The Actual Technique</strong></p>
<p>Image space calculations can be performed on the CPU, but as with most things in graphics that would slow and booorrrriiinng (unless you&#8217;re playing with SPUs, in which case carry on). The main point is that iterating over an image in the main thread while performing per-pixel calculations on the CPU would most likely be in bad taste. Instead you might consider the following GPU based solution:</p>
<ol>
<li><em>Render your scene normally, except to a texture if you are not 	already.</em></li>
<li><em>Render a quad that covers the entire screen, with the texture 	from the previous step as a texture applied across the quad.</em></li>
<li><em>Perform your calculations in the shader code used to render that 	full screen quad, modifying the how the texture is applied.</em></li>
</ol>
<p>There are several catches with this that you have to keep in mind. First and foremost, each fragment&#8217;s calculations cannot be too dependent on other locations on the screen. If you have to sample your frame many times, then those texture accesses will quickly add up, which is one of the big considerations that comes into play when performing screen space blurs. Secondly, while this might provide an effect for much cheaper than trying to model a similar effect in 3 dimensional space, keep in mind the actual performance is dependent on the resolution of the screen, which may be less than desirable. As resolution increases, so does the number of fragments being processed. In the end, it&#8217;s all about picking when and where to perform different calculations in your game.</p>
<p><strong>An Example</strong></p>
<p>Here&#8217;s a sample of a very simple post-processing fragment shader, written in CG. It does a simple screen space distortion based off of the x and y channels of a texture. The vertex shader doesn&#8217;t do anything particularly special other than set up uvs that are interpolated from 0 to 1 across the quad. In general, most of the action happens in the  fragment shader when doing post-processing.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="glsl" style="font-family:monospace;"><span style="color: #333399; font-weight: bold;">uniform</span> <span style="color: #000066; font-weight: bold;">sampler2D</span> _MainTex<span style="color: #000066;">;</span>
<span style="color: #333399; font-weight: bold;">uniform</span> <span style="color: #000066; font-weight: bold;">sampler2D</span> _DistortionMap<span style="color: #000066;">;</span>
<span style="color: #333399; font-weight: bold;">uniform</span> <span style="color: #000066; font-weight: bold;">float</span> _Distortion<span style="color: #000066;">;</span>
&nbsp;
float4 frag <span style="color: #000066;">&#40;</span>v2f i<span style="color: #000066;">&#41;</span> <span style="color: #000066;">:</span> COLOR
<span style="color: #000066;">&#123;</span>
    float2 distortedOffset <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>tex2D<span style="color: #000066;">&#40;</span>_DistortionMap<span style="color: #000066;">,</span> i<span style="color: #000066;">.</span><span style="color: #006600;">uv</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">xy</span> <span style="color: #000066;">*</span> <span style="color: #0000ff;">2</span> <span style="color: #000066;">-</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    distortedOffset <span style="color: #000066;">*=</span> _Distortion<span style="color: #000066;">;</span>
&nbsp;
    float2 distortedUV <span style="color: #000066;">=</span> i<span style="color: #000066;">.</span><span style="color: #006600;">uv</span> <span style="color: #000066;">+</span> distortedOffset<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> tex2D<span style="color: #000066;">&#40;</span>_MainTex<span style="color: #000066;">,</span> distortedUV<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000066;">&#125;</span></pre></td></tr></table></div>

<p>The shader itself is really only a few lines of code! So easy! Here&#8217;s what is happening a little more in depth. The float2 “distortedOffset” is simply the interpolated uv coordinate plus a lookup into the normal map which is then unpacked to fit into the range [-1,1] instead of the [0,1] range returned by tex2D(sampler2D, float2), which is then finally multiplied by _Distortion to control the strength of the distortion. Finally, a lookup into sampler2D MainTex is performed, where _MainTex is the previously rendered image. If there is no distortion, then the call would be equivalent to tex2D(_MainTex, i.uv), which would just copy the source image&#8217;s color to the new target. Speaking of targets, you might consider rendering this post-processing pass  into a texture as well, besides just your initial rendering of your 3D scene. This is so that you can pump the output of this post-processing into another post process you are implementing to be able to stack effects on top of each other.</p>
<p>Here is a sample of this particular distortion shader in action.<br />
The original rendered scene:</p>
<div id="attachment_3193" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/04/DistortionOff.jpg"><img class="size-full wp-image-3193 " src="http://altdevblogaday.com/wp-content/uploads/2011/04/DistortionOff.jpg" alt="" width="500" height="375" /></a><p class="wp-caption-text">Before Post-Processing</p></div>
<p>Texture that the distortion is calculated from in the shader:</p>
<div id="attachment_3202" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/04/water_normal2.jpg"><img class="size-full wp-image-3202" src="http://altdevblogaday.com/wp-content/uploads/2011/04/water_normal2.jpg" alt="" width="500" height="500" /></a><p class="wp-caption-text">Distortion Map</p></div>
<p>The final result:</p>
<div id="attachment_3197" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/04/DistortionOn.jpg"><img class="size-full wp-image-3197 " src="http://altdevblogaday.com/wp-content/uploads/2011/04/DistortionOn.jpg" alt="" width="500" height="375" /></a><p class="wp-caption-text">After Post-Processing</p></div>
<p><strong>Conclusion</strong></p>
<p>Great success!  The important question here should always be: how hard/expensive would it be to achieve the same effect in a different space? What do you gain/lose by doing it in image space? And also important is the question of whether or not this actually makes your game look any better. In the end, I personally think that post processing is great fun, especially used in terrible crazy ways on personal projects. You never know what you&#8217;ll come up with when you play around with ideas in a different space, for example here&#8217;s one paper exploring the possibility of moving skin rendering into screen space: <a href="http://jbit.net/~sparky/subsurf/cbf_skin.pdf">http://jbit.net/~sparky/subsurf/cbf_skin.pdf</a>. Finally, fun fact of the day: I modeled and textured that fish in the sample images way back when I was a Freshman, which is why it&#8217;s so shoddy and terrible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/04/04/image-space-for-beginners/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Moving beyond the Linear Bezier</title>
		<link>http://www.altdevblogaday.com/2011/03/21/moving-beyond-the-linear-bezier/</link>
		<comments>http://www.altdevblogaday.com/2011/03/21/moving-beyond-the-linear-bezier/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 03:59:25 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=2158</guid>
		<description><![CDATA[<p>Every beginner game programmer becomes familiar with the concept of needing to move from a value between point A to point B.  It comes up all the time in game programming, especially as you sit there trying to figure out how to do something as simple as move a box across the screen.  It is then that they learn about the linear interpolation (abbreviated to &#8220;lerp&#8221;) as a way to smoothly fade between two values, finding any point between them with a simple [0,1] <em>t</em> value.  The formula is simple:</p>
<p><a href="http://www.altdevblogaday.com/2011/03/21/moving-beyond-the-linear-bezier/" class="more-link">Read more on Moving beyond the Linear Bezier&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Every beginner game programmer becomes familiar with the concept of needing to move from a value between point A to point B.  It comes up all the time in game programming, especially as you sit there trying to figure out how to do something as simple as move a box across the screen.  It is then that they learn about the linear interpolation (abbreviated to &#8220;lerp&#8221;) as a way to smoothly fade between two values, finding any point between them with a simple [0,1] <em>t</em> value.  The formula is simple:</p>
<p style="text-align: center"><em>Lerp(t) = (1 &#8211; t) * StartPoint + t * EndPoint</em></p>
<p>And before you know it, those beginner programmers are Lerping all over the place, using it to help overcome all sorts of challenged in game development from moving an object in 3D space to fading between two audio clips.  In reality, this is actually just accomplishing one thing- it is just a straight line segment, reworked into a form that makes it easy to sample any point on that line.  Anyone that&#8217;s taken high school level math knows that there is more to life than just straight lines.  What if we need a curve?</p>
<p>So let&#8217;s consider how we might go about making this curve.  An approach that I&#8217;ve seen many beginner programmers, including myself, to try to get around the problem by stringing several lines together as an approximation.  This might be alright in some situations, but it fails in many.  For one, it requires the placement of a lot of points and then storage of that data, which can be painful.  Secondly, and perhaps more importantly, it will suffer from being jagged.  Maybe at a certain distance we will have enough points that it will appear smooth enough, but when examined closely enough the lack of smoothness will always become apparent (unless the number of points approach infinity).</p>
<p><strong>Enter: Bezier Curves</strong></p>
<p>Moving to a more complex equation can allow us to overcome these difficulties.  We know we can create curved functions with polynomial equations, but does this actually help us?  We can write these as parametric equations much like the linear interpolation equation shown above, but we don&#8217;t want to write a new equation each time we want to generate a curve.  We want to generate different curves between points, not just the same curve between them each time. Before this was not an issue, as we only ever used a straight line.  What we can do is store additional data that factors into our equation with additional data points beyond just the start and end points of the curve.  This is where quadratic and cubic bezier curves come into play.</p>
<p>If you&#8217;re new to bezier curves, you may find them a little intimidating due to the implication that there is some more complex math happening.  I used to think they were outside my league of math just because Adobe has released entire applications based around drawing with bezier curves.  Little did I know that I already used the 1st-degree, linear bezier equation all the time.  Here it is:</p>
<p style="text-align: center"><em>LinearBezier(t) = (1 &#8211; t) * StartPoint + t * EndPoint</em></p>
<p style="text-align: left">As you can probably tell, the linear bezier is actually just the linear interpolation equation.  Higher degree bezier curves introduce control points into their equations and the math only gets a <em>little</em> bit worse, but the similarities are still very visible to our friend linear interpolation.</p>
<p style="text-align: left">These 2nd and 3rd degree bezier curves can be defined as:</p>
<p style="text-align: center"><em>QuadraticBezier(t) = (1 – t)^2 * StartPoint + 2(1 – t) * t * ControlPoint + t^2 * EndPoint</em></p>
<p style="text-align: center"><em>CubicBezier(t) = (1 – t)^3 * StartPoint + 3(1 – t)^2 * t * ControlPoint1 </em></p>
<p style="text-align: center"><em>+ 3(1 – t) * t^2 * ControlPoint2 + t^3 * EndPoint</em></p>
<p>Let&#8217;s look at what happened.  Our computations are a bit more expensive, but can now craft more intricate curves.  These equations allow for the manipulation of continuously defined curves between the start point and end point by adjusting our control points.  Take a look at a couple of shots showing examples of these:</p>
<div id="attachment_2161" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/03/QuadraticCurve.jpg"><img class="size-full wp-image-2161 " src="http://altdevblogaday.com/wp-content/uploads/2011/03/QuadraticCurve.jpg" alt="" width="500" height="333" /></a><p class="wp-caption-text">A Quadratic Bezier Curve</p></div>
<div id="attachment_2165" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/03/CubicCurve.jpg"><img class="size-full wp-image-2165 " src="http://altdevblogaday.com/wp-content/uploads/2011/03/CubicCurve.jpg" alt="" width="500" height="333" /></a><p class="wp-caption-text">A Cubic Bezier Curve</p></div>
<p>The interface for modifying these curves is quite simply the same as the start and end points of a line, being that a control point is just another point in the same vector space as our start and end points.  Increasingly complex curves can be generated with higher degree bezier curves, but we don&#8217;t actually want that because the computation becomes increasingly expensive and the increases in control points can become cumbersome.  This is where turning to piecewise equations becomes a good solution.</p>
<p><strong>B-Splines</strong></p>
<p>Quadratic and cubic bezier curves do offer a lot more flexibility, but they also offer something else, the ability to be chained together without losing continuity, forming a piecewise function for your curve.  So instead of using higher degree equations to create more intricate curves, we can create a series of cubic bezier curves and restrict them a bit to meet continuity requirements.  Just as a refresher, a function meets different levels of continuity based depending on how many derivatives of the function are continuously defined.  The previously mentioned chain of straight lines only has a continuity of C0, meaning that all points along the spline are defined, but because it lacks C1 continuity, the first derivative is not continuously defined. The more derivatives that are continuously defined, the smoother our curve will be, but it will also result in less and less control over the spline as a consequence.</p>
<p>Now that we have moved to a chain of cubic bezier curves, we can easily obtain C1 continuity by requiring that the line formed between an end point and the second control point, is the equal and opposite of the start control point on the curve that is being transitioned to.  This looks like this:</p>
<div id="attachment_2189" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/03/CubicCurveC1.jpg"><img class="size-full wp-image-2189 " src="http://altdevblogaday.com/wp-content/uploads/2011/03/CubicCurveC1.jpg" alt="" width="500" height="333" /></a><p class="wp-caption-text">Piecewise Bezier with C1 Continuity</p></div>
<p>However, even with that restriction we can still have relatively sharp corners occur.  If we require a smoother curve, we can convert our piecewise curve to a B-spline. This will allow us to achieve C2 continuity, meaning that the second derivative is continuously defined. Our bezier control points are now moved to being controlled by a new set of points known as deBoor points. A cubic bezier curve that always has C2 continuity will be defined by these deBoor points.  Perhaps the biggest drawback is that the start and endpoints of a segment are no longer directly controllable either, but it is still relatively easy to work with from just the control points. Here are the equations for the generating the cubic bezier from the deBoor points, note that I name the variables based off of examining a particular segment in the spline:</p>
<p style="text-align: center"><em>CubicControlPoint1 = (2 * deBoorStartPoint + deBoorEndPoint) / 3</em></p>
<p style="text-align: center"><em>CubicControlPoint2 = (2 * deBoorEndPoint + deBoorStartPoint) / 3</em></p>
<p style="text-align: center"><em>CubicStartPoint = (deBoorPreviousStartPoint + 4 * deBoorStartPoint + deBoorEndPoint) / 6</em></p>
<p style="text-align: center"><em>CubicEndPoint = (deBoorStartPoint + 4 * deBoorEndPoint + deBoorNextEndPoint) / 6</em></p>
<p style="text-align: left">We can then build our cubic bezier with these values.  These relationships are a lot easier to visualize in a picture:</p>
<div id="attachment_2193" class="wp-caption aligncenter" style="width: 510px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/03/BSpline.jpg"><img class="size-full wp-image-2193 " src="http://altdevblogaday.com/wp-content/uploads/2011/03/BSpline.jpg" alt="" width="500" height="333" /></a><p class="wp-caption-text">A B-spline defined with deBoor Points</p></div>
<p>As you can probably see, these are a bit more mathematically involved than just a bezier curve. They are still relatively easy to manipulate through the deBoor points, and they have the added benefit of not requiring any additional data beyond that of a bezier curve and any bezier code that you currently have can be fit to work as a B-spline. This is exactly what I did when I most recently used B-splines to obtain C2 continuity on a project, I took advantage of the fact that the deBoor points could control the cubic curve entirely tool-side, while my in-game bezier code functioned exactly the same.</p>
<p><strong>Conclusion</strong></p>
<p>As you can see, math is fun and can lead to better better solutions to the engineering challenges in game development. Bezier curves naturally extend into many areas, and many useful uses have been cooked up for them. For a really great example of bezier curves at work, check out this article from GPU Gems 3 about rendering vector graphics on the GPU: <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html">http://http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html</a>.  Keep in mind that all this awesomeness comes with the cautionary wisdom that moving to higher degree curves is not always worth the increased computational complexity.  As always, make sure you evaluate what the right tool is to get the job done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/03/21/moving-beyond-the-linear-bezier/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Students and Quality of Life</title>
		<link>http://www.altdevblogaday.com/2011/03/07/students-and-quality-of-life/</link>
		<comments>http://www.altdevblogaday.com/2011/03/07/students-and-quality-of-life/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 02:34:33 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=1595</guid>
		<description><![CDATA[<p>The basis for this post is partly me realizing that I rant about bits and pieces of being a game development student on a semi-frequent basis, and partly because GDC is keeping me from fully fleshing out a more technical post.  So as a result, I decided to compile together some of my thoughts about what being a student is like these days and what sorts of possible implications it might have for the future.  I met up with <a href="http://twitter.com/#!/mike_acton" target="_blank">@MikeActon</a> and a few other #AltDevBlogADay contributors at a cigar bar earlier this week in the gigantic blur that was another GDC.  Myself and Shawn (<a href="http://twitter.com/#!/qtbon" target="_blank">@qtbon</a>), the other half of the programming team in the GEL lab, were the only current students in attendance.</p>
<p><a href="http://www.altdevblogaday.com/2011/03/07/students-and-quality-of-life/" class="more-link">Read more on Students and Quality of Life&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The basis for this post is partly me realizing that I rant about bits and pieces of being a game development student on a semi-frequent basis, and partly because GDC is keeping me from fully fleshing out a more technical post.  So as a result, I decided to compile together some of my thoughts about what being a student is like these days and what sorts of possible implications it might have for the future.  I met up with <a href="http://twitter.com/#!/mike_acton" target="_blank">@MikeActon</a> and a few other #AltDevBlogADay contributors at a cigar bar earlier this week in the gigantic blur that was another GDC.  Myself and Shawn (<a href="http://twitter.com/#!/qtbon" target="_blank">@qtbon</a>), the other half of the programming team in the GEL lab, were the only current students in attendance.</p>
<p>Shortly after we arrived the conversation turned to quality of life, something that Mike has been talking about quite a bit as of late, including an excellent <a href="http://www.nordmedia.de/content/digitale_medien/digital_media_cluster/game_forum_germany/veranstaltung/mediathek/index.html" target="_blank">presentation at Game Forum Germany</a>.  One of the points brought up was that the huge influx of students interested in game development allows companies to basically burn through their employees and easily refresh themselves from a deep pool of people desperately looking for work.  I didn&#8217;t end up contributing my thoughts on the subject from a student perspective, but I later realized that maybe I did have a relevant perspective to add to the discussion.  Especially because I&#8217;m currently in the weird spot in my life where I&#8217;ve found myself fitting into many different sides of the fence dividing developers and those aspiring to become developers, which as a warning, might make me sound like I jump perspectives a few times throughout this.  I might be wrong about some of this, so feel free to flame me in the comments in that case :)</p>
<p><strong>When Start-ups are “Safe”</strong></p>
<p>I attended GDC with a handful of other Michigan State students this week, many of which are actively in the hunt for jobs.  However, Shawn and a couple others weren&#8217;t looking for work because as their current projects wrap up and they begin to graduate, they&#8217;ve decided to form <a href="http://adventureclubgames.com/">Adventure Club Games</a>, a start-up, doing a combination of contract work and smaller independent projects.  They&#8217;ve already landed a few serious games related contracts through the professors with grants at the university, so they may be well on their way to surviving the first year as a start-up.</p>
<p>What worries me is that some of the students looking for jobs have told me this week that they feel that the guys involved in Shawn&#8217;s company have the “safe bet.”  This is quite honestly one of the most terrifying things that I have ever heard students say.  I&#8217;m intentionally not letting myself get roped into Shawn&#8217;s company, even though they&#8217;re all great guys and I know they&#8217;d be excited to have me on board.  I&#8217;ve been involved in two start-ups in the past (not all game related), and I think that the stress that comes along with that could quite honestly kill me at this point in my life.  Going into an industry where a start-up feels like a safer bet than finding a job is just&#8230; unbelievable.</p>
<p>Let&#8217;s circle back real quick to what I mentioned earlier, this conversation started because we were talking about <em>crunch</em>, and the thought that there is an endless pool of fresh talent ready to get killed in a vicious cycle of burnout is quite troubling.  These kids would work well over 80 hours a week and throw themselves under a bus for the opportunity to work on “game X,” and they <em>still</em> feel like it would be easier to get involved in a start-up.  In my experience, being in a start-up is a whole different devil, it&#8217;s a world where the crunch is endless because the sole determinant of success is yourself.  The amount of time you spend on your work is a bottomless pit of stress, business, and development, but the reward is that you get ownership and control.  People at Mike&#8217;s get together mentioned staying with a death march development because of loyalty to the studio or loyalty to the project, but think about it, in a start-up,  you <em>are</em> the entire show.  You either rise or die, and it&#8217;s a very difficult thing to do.  To see students thinking starting a business as a more secure temptation than sticking through the hurdles of landing a job with an established studio- it shows just how crazy this all is.</p>
<p>I feel like students might be getting the wrong messages from the industry as to what should be expected of them.  After spending time in the career pavilion, several students told me that they basically felt like 4 years of college had absolutely no relevance to them getting a job.  Something is not right if people feel like that, especially if they&#8217;re part of a program that is apparently <a href="http://www.princetonreview.com/game-design-press-release.aspx" target="_blank">ranked among the top in North America</a>.  We don&#8217;t want people to drop out of school and try to make games in their basements. We want people to rise above their degrees and push their programs to new heights, even if the piece of paper you get at the end isn&#8217;t as important as what you learned along the way.  Game development education is still in its infancy, we need to be encouraging programs to grow and mature.</p>
<p><strong>To be a Student</strong></p>
<p>This all really gets to me because I think that this perception finding work as a student game developer being impossible might be having a negative impact on the the student culture as a whole.  This ties back into how uncomfortable it makes me when design students want to make games that are marketable instead of games that are art.  Are we suffocating creativity out of students?  I always thought design students would be stubbornly optimistic about games as art, wanting to experiment and create as they find themselves suddenly empowered to create virtual worlds.  Shouldn&#8217;t students be encouraged to make use of their time in college to experiment and take risks?  They&#8217;re getting an opportunity to make the games they want to make, as they exist in an environment free of the weight of money and the reponsibilities associated with a formal job.  This is why I think the student showcase is such an important part of the Independent Games Festival- it encourages students to take a risk and do something creative.</p>
<p>This applies to disciplines beyond design as well.  Programmers and artists should be encouraged to try new or unconventional techniques.  In school, it&#8217;s alright to fail at an implementation and learn from our mistakes.  We need to encourage people to experiment with ways to make their games interesting, optimized, beautiful, and every other thing that we want to achieve as developers when we work on professional projects.</p>
<p><strong>From A to B</strong></p>
<p>When I started college, it was also the beginning of me truly becoming serious about game development.  I took a long look at myself and realized where I thought I might need to be as a developer by the time I graduate.  I imagined the quality of game I thought that I might need to be capable of producing to “break in,” those devilish words that give an aspiring student the chills.</p>
<p>At the time, it seemed impossible.  There was so much to learn, and improving the quality of my work was such a tedious process, I wondered if I would be heading to grad school at the end of my four years to continue my education.  Now that I&#8217;m three years in, I feel a little foolish for thinking that during my earlier years.  However, there&#8217;s something important there- that envisioning of where I wanted to be at the end has been vitally important for my growth as a developer.  It was something that I did on my own that I really wish more people had been saying because I think it</p>
<p>In all honesty, I feel like we need to be telling students a bit more than just “you have to make games,” which is something that I&#8217;ve heard over and over again.  That&#8217;s not enough.  There&#8217;s so much more to becoming a good developer.</p>
<p><strong>What I think we should be saying:</strong></p>
<p>Based off of my own experiences over the past years, here&#8217;s a short list of what I think we should actually be telling students:</p>
<ol>
<li>Set 	your goals.  How long do you have until you will be looking for a 	job?  The clock is ticking.  But the harder you work early on, the 	easier it will get.  Make sure you include getting team based 	experience in that road plan if you don&#8217;t intend to be a one man 	show your whole life.</li>
<li>You 	have to be good at what you want to do.  Can you produce work of the 	quality of studios that you want to work at?  Realize that basic 	skills across your broader discipline is important (art, 	programming, etc), but specialize in one or two areas is important 	as well (animation, rendering, etc).</li>
<li>Speed 	counts too.  Artists hear this sometimes, but its important for 	everyone.  If you are given a programming test, it will almost 	certainly be timed.  If you are asked a design question in an 	interview, you have to be quick on your feet.  This comes naturally 	with practice.  If things aren&#8217;t slowly becoming second nature to 	you, you need to be committing more time to your work.</li>
<li>Live 	beyond your tools.  Getting stuck inside a bubble will result in 	sloppy work and messy solutions to problems.  Consider an animator 	that spends all their time playing in Maya or Max but doesn&#8217;t study 	natural motion, or a character artist that hasn&#8217;t studied anatomy, 	or a rendering programmer that isn&#8217;t familiar with linear algebra.  	You can cripple yourself if you&#8217;re not careful.</li>
<li>Try 	new and unconventional things in some of the free time you might 	have (if you&#8217;re like me this time is usually in between midnight and 	4 am).  Read white papers about the latest research, try new art 	tools, prototype an unconventional design, the list goes on and on.  	Like I said earlier, trying new things is especially important in 	college.</li>
<li>Your 	professors don&#8217;t tell the whole story.  You&#8217;d better learn what they 	have to teach you, but quite often realize that they don&#8217;t always 	have the same goals in mind.  This hearkens back to my feelings 	about how little my current roommate (<a href="http://twitter.com/#!/krismicinski">@krismicinski</a>) needs the capstone 	class that my school touts for it&#8217;s Engineering programs, being that 	he studies compilers and just got accepted into half dozen PhD 	programs.  The class is designed to help people get jobs as the more 	generic breed of software engineers, not as game developers, and 	most certainly not as academics.  You&#8217;ll have to learn a lot on your 	own no matter where you are, and this trend will continue into 	professional work.</li>
<li>Your 	free time is a commodity.  One of my closest friends is part of my 	school&#8217;s brutal Biochemistry curriculum, which has been compared to 	doing graduate level work straight out of high school.  He has a 	saying that “in college you can work, socialize, and sleep.  We 	only get to pick two.”  Playing games is, in my opinion, a 	dangerous culprit here.  Playing through an entire AAA game is a 	time consuming process, so pick your games wisely.</li>
<li>Save 	up to attend GDC.  Get at least a main conference level pass.  I 	personally equate a week of cutting edge development talks to be 	worth an entire semester of college.  Sound like a lot of money?  	How many 60 dollar games do you buy in a year that you don&#8217;t 	actually have enough time to play?</li>
<li>Keep 	a development blog.  It&#8217;ll help you be coherent when people ask 	about what type of work you do.</li>
<li>Make 	a Twitter and follow developers.  It&#8217;s an easy way to keep up to 	date on the latest research, techniques, and thoughts of some of the 	brightest people in the games industry.</li>
</ol>
<p><strong>Concluding Thoughts</strong></p>
<p>So here&#8217;s where the hypocrisy comes in a bit.  Even though I act like I&#8217;ve done a good job growing as a game developer, I still don&#8217;t know if I could resist accepting a position at a studio that has abusive dev cycles.  I feel like I could at this point in my life, but at the same time I wonder what a dozen rejected applications would do to me after I graduate next year.  I used to keep myself up wondering if I could actually cut it as a game developer.  After three years of doing the ten things I just mentioned, I feel confident that I&#8217;ll be at the level I want to be in a year&#8217;s time for graduation.  What keeps me up now is whether or not I&#8217;ll be able to live a healthy life style after college.  There&#8217;s too many stories of developers who have let parts of their lives be wrecked by abusive work environments, too many developers who get up to accept an award and thank their wives for putting up with endless hours of overtime.  So what are your opinions? I&#8217;d love to hear what advice you have for students, whether or not an endless pool of applicants enables a burnout dev cycle, and why I&#8217;m just straight up wrong.  Flame on?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/03/07/students-and-quality-of-life/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A little more Theory with your Mesh</title>
		<link>http://www.altdevblogaday.com/2011/02/18/a-little-more-theory-with-your-mesh/</link>
		<comments>http://www.altdevblogaday.com/2011/02/18/a-little-more-theory-with-your-mesh/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 22:25:10 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/?p=857</guid>
		<description><![CDATA[<p>I promised a technical post at the end of <a title="Serious Developments" href="http://altdevblogaday.com/2011/02/03/“serious”-developments/" target="_blank">my last one</a>, although I suppose that technical might not be the word so much as “mathy.”  Last fall, I took the graduate level graphics course at my University, which was taught by <a title="Professor Tong" href="http://www.cse.msu.edu/%7Eytong/" target="_blank">Prof. Yiying Tong</a>.  The interesting thing about Prof. Tong is that he is a guru of surfaces and differential geometry, which is not my focus at all (I kick around shader code all day), but the class ended up being really interesting.</p>
<p><a href="http://www.altdevblogaday.com/2011/02/18/a-little-more-theory-with-your-mesh/" class="more-link">Read more on A little more Theory with your Mesh&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I promised a technical post at the end of <a title="Serious Developments" href="http://altdevblogaday.com/2011/02/03/“serious”-developments/" target="_blank">my last one</a>, although I suppose that technical might not be the word so much as “mathy.”  Last fall, I took the graduate level graphics course at my University, which was taught by <a title="Professor Tong" href="http://www.cse.msu.edu/%7Eytong/" target="_blank">Prof. Yiying Tong</a>.  The interesting thing about Prof. Tong is that he is a guru of surfaces and differential geometry, which is not my focus at all (I kick around shader code all day), but the class ended up being really interesting.</p>
<p>As such, I&#8217;m going to talk about some basic mathematical aspects that apply to our friend, the 3D mesh.  This is the type of thing that will probably cause many rendering programmers to have violent flashbacks to &#8220;Intro to Graphics&#8221; courses, but I think people not as intimately involved in graphics might find this interesting.  The entire motivation for this is because my group for a class project where we did some terrain generation with a procedurally raised race track, had no idea what our professor was talking about when he told us that our track generation always formed a star from our seed node. We thought he was talking about a star shape (you know, like the sun), and not the mathematical operation, but I&#8217;ll get back to that later.</p>
<p><strong>Lesson 1: The Euler Characteristic</strong></p>
<p>Unless you live in a 2D only world, I&#8217;m going to bet that most of the people reading this have been living in a forest of 3D meshes for years.  And I know that a lot of artists have little rules of thumb that they use for what the ratio of faces to vertices their meshes should have to  figure out if there are hidden faces or holes floating around, but theres are actually some hard math behind the number of vertices, faces, and edges in a given mesh (triangular or not).</p>
<p>This is the <em><strong>Euler Characteristic</strong></em><em>: </em></p>
<p style="text-align: center">χ = V – E + F</p>
<p>Less Formally:</p>
<p style="text-align: center">Euler Characteristic = Vertices – Edges + Faces</p>
<p>Whoah, what does that mean?  Back as a newbie game developer that didn&#8217;t know the difference between a heap and a memory pool, I would&#8217;ve thought that was the least useful thing ever.  However, what&#8217;s interesting is that the Euler Characteristic is actually constrained based off the topology of the mesh, and not by vertex or face count as it first appears.</p>
<p>This is <em><strong>Euler&#8217;s Formula</strong></em>:</p>
<p style="text-align: center">2 = V – E + F</p>
<p>This is the Euler Characteristic for a sphere mesh, and more importantly it holds true for any mesh that can be smoothly deformed to a sphere has this characteristic, as does any convex polyhedra.  You can think of the Euler Characteristic as being controlled by the number of “holes” in the mesh, with the number of vertices, edges, and faces dependent on the characteristic.</p>
<p style="text-align: center">χ = 2 * (1 – G)</p>
<p>Where G is the number of holes in the polyhedron.  So a sphere is a closed mesh with no holes, meaning it has a G of 0, which results in an Euler Characteristic of 2.  Consider the tetrahedron:</p>
<div id="attachment_887" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/Tetrahedron.jpg"><img class="size-medium wp-image-887" src="http://altdevblogaday.com/wp-content/uploads/2011/02/Tetrahedron-300x221.jpg" alt="" width="300" height="221" /></a><p class="wp-caption-text">A Tetrahedron in Maya</p></div>
<p>A tetrahedron has 4 faces, 4 vertices, and 6 edges.  It also has a G value of zero for having no holes.  So:</p>
<p style="text-align: center">χ = V – E + F = 2 * (1 – G)</p>
<p style="text-align: center">χ = 4 – 6 + 4 = 2 * (1 – 0) = 2</p>
<p style="text-align: center">χ = 2 = 2 =2</p>
<p style="text-align: center">= Win!</p>
<p>This math holds up with other meshes and also can be proved in a variety of ways. Cool right? Direct application? – probably not, but at least you&#8217;re a better person for knowing a little more math from our friend <a title="Leonhard Euler" href="http://en.wikipedia.org/wiki/Leonhard_Euler" target="_blank">Leonhard Euler</a>.  Now go impress your friends at parties by knowing <a title="Euler Formulas" href="http://en.wikipedia.org/wiki/List_of_topics_named_after_Leonhard_Euler" target="_blank">yet another Euler Formula</a>.</p>
<p><strong>Lesson 2: Closure, Link, and Star</strong></p>
<p>So now I&#8217;m going to change gears a little bit and talk about some math terms that apply to meshes, but really could apply to other sets as well.  Specifically, these are operations that apply to a <em>simplicial</em> <em>complex</em>.  A simplicial complex is a set of simplices that follow two conditions:</p>
<ol>
<li>A 			simplex is made up of faces, and each face of a simplex is also 			part of the simplicial complex.</li>
<li>The 			intersection of any two simplices in the the simplicial complex is 			a face of each of those simplices.</li>
</ol>
<p>Triangular meshes, the simplicial complexes we care about, are made up of points, lines, and triangles, but other simplicial complexes can contain higher dimensional components, such as tetrahedra.  So there&#8217;s a mathematical concept correlating to our lists of vertices and triangles, and theres also some mathematical operators that go along with a that structure.  Also note that a face of a given simplex is a lower dimensinal component that forms it.  So the face of a triangle is an edge.  That edge is in turn a simplex that has vertices for faces.</p>
<p><strong>The Closure</strong></p>
<p>The closure of a set of simplices in a simplicial complex is the smallest subcomplex that contains each simplex in the set.  Now say that ten times fast.  Yeah, if I read that description in a paper I would probably stop reading.  But this where fancy diagrams come to the rescue!  Here&#8217;s a relatively basic simplicial complex made of triangles, vertices, and edges:</p>
<p style="text-align: center"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/SimplicialComplex.jpg"><img class="alignnone size-medium wp-image-858" src="http://altdevblogaday.com/wp-content/uploads/2011/02/SimplicialComplex-300x192.jpg" alt="" width="300" height="192" /></a></p>
<p>Consider a single edge being our entire set of simplices we are performing the closure operation on:</p>
<div id="attachment_860" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/Edge.jpg"><img class="size-medium wp-image-860" src="http://altdevblogaday.com/wp-content/uploads/2011/02/Edge-300x192.jpg" alt="" width="300" height="192" /></a><p class="wp-caption-text">S = {one edge}</p></div>
<p>Any subcomplex that contains this edge becomes part of the closure. An edge cannot exist without the two vertices so they become part of the set to form the smallest containing subcomplex:</p>
<div id="attachment_861" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/Closure.jpg"><img class="size-medium wp-image-861" src="http://altdevblogaday.com/wp-content/uploads/2011/02/Closure-300x192.jpg" alt="Closure of S" width="300" height="192" /></a><p class="wp-caption-text">Cl S</p></div>
<p><strong>The Star</strong></p>
<p>The star is another simple operation on a set of simplices in a simplicial complex.  And yes, my previous lack of knowledge about it last Spring led me to have a very misled conversation about what a star was during a presentation.</p>
<p>A star is the set of all simplices in the complex have a face in the set of simplices that the star is being computed for.   Once again, taking the star of a set of simplices is also relatively straightforward once you get past all the wordage and see a picture of it in action.  We&#8217;ll use the same edge for set S as we did before:</p>
<div id="attachment_862" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/Star.jpg"><img class="size-medium wp-image-862" src="http://altdevblogaday.com/wp-content/uploads/2011/02/Star-300x192.jpg" alt="Star of S" width="300" height="192" /></a><p class="wp-caption-text">St S</p></div>
<p><strong>The Link</strong></p>
<p>Computing the link is a little bit more involved than bit more involved than computing the star or the closure alone.  That is because for a set of simplices S, the link is the closure of the star of S minus the star of the closure of S.  This is much easier to comprehend when visualized.  We&#8217;ll use the center vertex for the set S this time:</p>
<div id="attachment_863" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/Vertex.jpg"><img class="size-medium wp-image-863" src="http://altdevblogaday.com/wp-content/uploads/2011/02/Vertex-300x192.jpg" alt="A Vertex" width="300" height="192" /></a><p class="wp-caption-text">S = {one vertex}</p></div>
<p>First consider the closure of the star of S, where the star of S will be the vertex, the 4 edges that contain it, and the 4 triangles that contain it, and then the closure will expand that to be the complete subcomplex that contains those faces, so the 4 edges and 4 vertices around the edge are added as well:</p>
<div id="attachment_866" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/ClosureOfStar.jpg"><img class="size-medium wp-image-866" src="http://altdevblogaday.com/wp-content/uploads/2011/02/ClosureOfStar-300x192.jpg" alt="Closure of Star" width="300" height="192" /></a><p class="wp-caption-text">Cl St S</p></div>
<p>And then the star of the closure of S, where the closure of S will just be the vertex again, and the star of that will include the 4 edges and 4 triangles that include the vertex:</p>
<div id="attachment_865" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/ClosureOfStar1.jpg"><img class="size-medium wp-image-865" src="http://altdevblogaday.com/wp-content/uploads/2011/02/ClosureOfStar1-300x192.jpg" alt="Star Of Closure" width="300" height="192" /></a><p class="wp-caption-text">St Cl S</p></div>
<p>Finally, by taking the difference of the closure of the star of S and the star of the closure of S, we get the link, which in this case resembles a boundary around the triangles in containing our initial vertex:</p>
<div id="attachment_867" class="wp-caption aligncenter" style="width: 310px"><a href="http://altdevblogaday.com/wp-content/uploads/2011/02/Link.jpg"><img class="size-medium wp-image-867" src="http://altdevblogaday.com/wp-content/uploads/2011/02/Link-300x192.jpg" alt="Link" width="300" height="192" /></a><p class="wp-caption-text">Lk S =  Cl St S - St (Cl S - ø)</p></div>
<p>So that covers the link, star, and closure.  Applications?  Just like with the Euler Characteristic you could probably go on living your life without knowing them&#8230; but that would be no fun!  In the context that I learned about the link, star, and closure it had relevance to types of information that might be stored in a data structure defining a 3D mesh.  For instance, you might want to store the star and the link of every vertex in the mesh to be able to find the triangles and edges that surround each vertex.</p>
<p><strong>You Made It!  Rejoice and be silly!</strong></p>
<p>Hopefully if you made it this far you actually found some of this to be interesting.  If not, well you probably won&#8217;t be any worse off for it.  But because I&#8217;m a college student and just wrote about a whole bunch of mathematical concepts, even though college students are <em>supposed</em> to spend their time doing silly things&#8230; I leave you with this: a video of Kris, my roommate, convincing the chemical engineer that lives across the hall from us that &#8220;Wumbopixels&#8221; are the metric equivalent to Megapixels.  Luckily this conversation was captured by another guy at the the table learning how to use the video feature of his fancy new phone.</p>
<p style="text-align: center"><!-- vimeo error: not a vimeo video --></p>
<p>He believed that &#8220;Wumbopixels&#8221; were real for several days before we finally decided that we should inform him of the truth before the damage could become permanent :)</p>
<p><em>This was a cross-post with my personal blog at <a title="JonManatee Blogspot" href="http://jonmanatee.blogspot.com/2011/02/little-more-theory-with-your-mesh.html" target="_blank">jonmanatee.blogspot.com</a></em><em> and you can always find me kicking around <a href="http://twitter.com/#!/jonmanatee" target="_blank">@JonManatee</a> in the Twitterverse.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/02/18/a-little-more-theory-with-your-mesh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>“Serious” Developments</title>
		<link>http://www.altdevblogaday.com/2011/02/03/%e2%80%9cserious%e2%80%9d-developments/</link>
		<comments>http://www.altdevblogaday.com/2011/02/03/%e2%80%9cserious%e2%80%9d-developments/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 14:50:00 +0000</pubDate>
		<dc:creator>Jon Moore</dc:creator>
		
		<guid isPermaLink="false">http://altdevblogaday.org/2011/02/03/%e2%80%9cserious%e2%80%9d-developments/</guid>
		<description><![CDATA[<p>Today is my first #AltDevBlogADay post, so I suppose a short introduction is in order to preface my post.  Currently, I am a computer science student at Michigan State University and a game programmer for the Games for Entertainment and Learning Lab.  In the GEL Lab we generally develop serious  games for contract or research purposes, and this post is going to be about an aspect of serious game development that I think is often not realized.</p>
<p><a href="http://www.altdevblogaday.com/2011/02/03/%e2%80%9cserious%e2%80%9d-developments/" class="more-link">Read more on “Serious” Developments&#8230;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Today is my first #AltDevBlogADay post, so I suppose a short introduction is in order to preface my post.  Currently, I am a computer science student at Michigan State University and a game programmer for the Games for Entertainment and Learning Lab.  In the GEL Lab we generally develop serious  games for contract or research purposes, and this post is going to be about an aspect of serious game development that I think is often not realized.</p>
<p style="margin-bottom: 0in;">If I were to ask any random developer as to why developing serious games is challenging, I think I would typically get a response about the game design challenges associated with serious games.  While it&#8217;s no cakewalk to try to make a game that is both fun AND teaches the player some other skill (such as financing a car or managing a power plant), there are some very likely pitfalls that will inevitably impact the entire team beyond the designers.</p>
<p style="margin-bottom: 0in;">&nbsp;</p>
<p style="margin-bottom: 0in;"><strong>You can&#8217;t go it Alone</strong></p>
<p style="margin-bottom: 0in;">The issue that I think often goes overlooked is that because an average game developer is just an expert at making games, a serious game developer will have to consult an external source that is an expert in the subject matter of the game.  More often than not, that source of expertise is also the source of funding for a serious games project.  An example is a company contracts a developer to make a game about workplace safety, and the developer will have to work with them to understand what that actually entails.</p>
<p style="margin-bottom: 0in;">&nbsp;</p>
<p style="margin-bottom: 0in;"><strong>&ldquo;The Client&rdquo;</strong></p>
<p style="margin-bottom: 0in;">This places people outside of the development team, who typically know very little about game or even software development, in a very powerful position.  The delicate relationship that arises out of this is, in my opinion, potentially more intricate than that of the developer-publisher relationship.  Personally I suspect it is more like working with an IP holder on licensed work because they care much more about how their content appears in the game.  Often if the client wants to be too hands on, the game ends up not being fun, but if the developer just runs wild, the game could end up not teaching the players what it&#8217;s supposed to, which is just as much of a failure in serious game development.  It has to be a symbiotic relationship to result in a successful game, and I&#8217;ve compiled a couple of pointers from my personal experiences from the past couple of years.</p>
<ol>
<li>
<p style="margin-bottom: 0in;">Figure out if the client 	understands what a fun game is, even if they don&#8217;t know how to make 	one.  If they do, make playable versions of the game a high 	priority.  If you&#8217;re on the right track with your game , make sure 	your client can play it and be on the same page as you, or else they 	might demand you scrap your work and change directions without 	giving your hard work a chance.</p>
</li>
<li>
<p style="margin-bottom: 0in;">Be ready for change.  If the game 	isn&#8217;t meeting its goals, the design team is going to want a change, 	and that change is necessary.  Huge design changes are in, my 	opinion, much more likely when you have to teach the player about 	something typically less than fun. Convincing the client that the 	change is needed can be hard though if they are worried about 	meeting deadlines, especially if your code base won&#8217;t easily adapt 	to the new direction.  Or the change could come at the demand of the 	client, which could be even more drastic, as one meeting can leave 	you commenting out half of your code base.</p>
</li>
<li>
<p style="margin-bottom: 0in;">Be afraid if your designers and 	client don&#8217;t get along.  You might notice that the client is&nbsp;portrayed in polar opposites in the 	past two points (wanting change and not wanting change), yet both 	can happen on the same project.  Anything less than a good 	relationship between your designers and your client is an early sign 	of approaching trouble.  As I said before, a successful serious game 	needs a balance between the entertainment and the game&#8217;s subject 	matter.</p>
</li>
<li>
<p style="margin-bottom: 0in;">Keep in mind that sales is not the 	goal of the project.  From a client&#8217;s perspective, a failure to meet 	the goals doesn&#8217;t always result in financial trouble.  It can result 	in the client looking to fund a &ldquo;do-over&rdquo; of the project.  If 	you didn&#8217;t obey point #2 is reworking the entire game going to be a 	nightmare?  This is especially possible if the project was funded by 	grants.  A failure of one project just means that it is the basis of 	the next grant proposal to fund the fixing of the first game&#8217;s 	shortcomings.</p>
</li>
</ol>
<p style="margin-bottom: 0in;">So there, a little peek into the world of serious game development.  I&#8217;ve begun to wonder if the challenges of separated expertise is one of the reasons why it seems that there is a high concentration of serious games that are quite good at what they do because their purpose is to teach the player about game design.</p>
<p style="margin-bottom: 0in;">&nbsp;</p>
<p style="margin-bottom: 0in;"><span style="font-size: small;"><em>This was a cross-post with my personal blog at <a href="http://jonmanatee.blogspot.com/2011/02/serious-developments.html" target="_blank">http://jonmanatee.blogspot.com/2011/02/serious-developments.html</a> and you can always find me kicking around <a href="http://twitter.com/#!/jonmanatee" target="_blank">@JonManatee</a> in the Twitterverse.  I promise I&#8217;ll write about something more technical next time around :)</em></span></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2011/02/03/%e2%80%9cserious%e2%80%9d-developments/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

