<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aaron Hedquist on Medium]]></title>
        <description><![CDATA[Stories by Aaron Hedquist on Medium]]></description>
        <link>https://medium.com/@aarhed?source=rss-c1d867d387cd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*QY1a7nD61NLCs3y1rkJm7w.png</url>
            <title>Stories by Aaron Hedquist on Medium</title>
            <link>https://medium.com/@aarhed?source=rss-c1d867d387cd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:38:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aarhed/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AR Game Prototype]]></title>
            <link>https://medium.com/@aarhed/ar-game-prototype-c33c906ea6e0?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c33c906ea6e0</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Fri, 09 Mar 2018 21:18:18 GMT</pubDate>
            <atom:updated>2018-03-09T21:19:08.851Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kr9eJ3w8e0wzoqGrkFKF4g.png" /></figure><p>First screenshot of an early AR game prototype, using poker cards as image targets in Vuforia. As you can see, images that have mirrored art (and thus mirrored “features”) lead to the models being randomly oriented backwards.</p><p>Even trickier was that the model that was facing the wrong way had the same rotation as the one facing the camera, as the world was just orientated in the inverse direction. So checking against the models’ y-rotation did nothing.</p><p>Here it is fixed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVzRNFthYt8PPOv83SaCvw.png" /></figure><p>I had to do a few things to fix this:</p><ul><li>Switched <strong>World Center Mode</strong> to Camera, rather than <strong>First Target</strong>. This put the camera as the center of the universe, rather than the model, so I had a consistent world orientation.</li><li>Added a script to check the model’s orientation, and correct it as necessary. I did this by taking the dot product of the camera’s forward vector with the forward vector of the skeleton model.</li></ul><pre>private void CheckDirection(Card c)<br>{<br>   float dot = Vector3.Dot(Camera.main.transform.forward, model.forward);<br>   <br>   // if it&#39;s positive, it means it&#39;s facing in the same direction as the camera<br>   if (dot &gt; 0f)<br>   {<br>      <br>      if (model.localEulerAngles.y &gt;= -1 &amp;&amp;<br>          model.localEulerAngles.y &lt;= 1)<br>      {<br>         model.localRotation = Quaternion.Euler(0, 180, 0);          <br>      }<br>      else if (model.localEulerAngles.y &gt;= 179 &amp;&amp;<br>               model.localEulerAngles.y &lt;= 181)<br>      {<br>         model.localRotation = Quaternion.Euler(0, 0, 0);<br>      }<br>}</pre><p>It wasn’t enough to only simply set the model’s y-rotation to 180 if the dot product was positive, as the y-rotation seemed to be carried over between lost and found recognition states. So it has to be relative to whatever it is currently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c33c906ea6e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shield shader]]></title>
            <link>https://medium.com/@aarhed/shield-shader-85cdaf903db7?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/85cdaf903db7</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Sat, 03 Feb 2018 22:21:19 GMT</pubDate>
            <atom:updated>2018-03-09T21:20:51.398Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0stRmT9caODvjotCm1lvg.png" /></figure><p>This was created following <a href="https://www.youtube.com/watch?v=C6lGEgcHbWc">this video</a> by <a href="https://www.youtube.com/channel/UCEklP9iLcpExB8vp_fWQseg">Makin’ Stuff Look Good in Unity</a>. This was an excellent tutorial, but I did have to take some extra time to really unwrap some of the parts he goes over very quickly. Essentially this shader is a combination of a few components:</p><ol><li>A sphere with UVs</li><li>Use of a <a href="https://docs.unity3d.com/Manual/SL-CameraDepthTexture.html">camera depth texture</a></li><li>An intersection calculation between the sphere and the depth texture</li><li>A hexagonal texture, which is applied with a sin wave and animated over time.</li><li>A rim shader</li></ol><p>My first issue was trying to get the depth texture to work. After plugging in the first blob of code, I wasn’t seeing any intersections. And since this is a shader, which are very challenging to debug (how I miss NSLog!), I resorted to some other ways to make sure my depth texture was coming through.</p><p>First I wrote this script and added it to the main camera</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br><br>[ExecuteInEditMode]<br>public class OnRenderMaterial : MonoBehaviour<br>{<br><br>   public Material EffectMaterial;<br><br>   private void OnEnable()<br>   {<br>      GetComponent&lt;Camera&gt;().depthTextureMode = DepthTextureMode.Depth;<br>   }<br>   <br>   private void OnRenderImage(RenderTexture src, RenderTexture dest)<br>   {<br>      Graphics.Blit(src, dest, EffectMaterial);<br>   }<br>   <br>}</pre><p>For the actual shader, the depth texture mode will be .DepthNormals, but I wanted to start with something simpler. If the camera is in deferred mode, this is something that is already being generated by the <a href="https://gamedevelopment.tutsplus.com/articles/forward-rendering-vs-deferred-rendering--gamedev-12342">G-Buffer,</a> thus this you get this for free. In forward rendering this will be generated if shadows are enabled, otherwise this will be an extra pass.</p><p>OnRenderImage() passes the current view through the given material (and its shader), and renders that instead of whatever the camera would have normally shown. This is the basis for <a href="https://docs.unity3d.com/550/Documentation/Manual/WritingImageEffects.html">image shader post-processing effects</a>. <a href="https://www.youtube.com/watch?v=kpBnIAPtsj8">MSLGWU has a great tutorial </a>on this as well.</p><p>Now to actually try to render this depth texture to the screen.</p><pre>Shader &quot;Unlit/ShowDepth&quot;<br>{<br>    Properties {<br>        _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}<br>    }<br>   SubShader<br>   {<br>      Tags { &quot;RenderType&quot;=&quot;Opaque&quot; }<br>        Cull Off ZWrite Off ZTest Always <br>         <br>      Pass<br>      {<br>         CGPROGRAM<br>         #pragma vertex vert<br>         #pragma fragment frag<br>         #include &quot;UnityCG.cginc&quot;<br><br>         struct appdata<br>         {<br>            float4 vertex : POSITION;<br>            float2 uv : TEXCOORD0;<br>         };<br><br>         struct v2f<br>         {<br>            float2 uv : TEXCOORD0;<br>            float4 vertex : SV_POSITION;<br>         };<br><br>         sampler2D _CameraDepthTexture;<br>         sampler2D _MainTex;<br>         float4 _MainTex_ST;<br>         <br>         v2f vert (appdata v)<br>         {<br>                v2f o;<br>             o.vertex = UnityObjectToClipPos(v.vertex);<br>             o.uv = TRANSFORM_TEX(v.uv, _MainTex);<br>            <br>                return o;<br>            <br>         }<br>         <br>         fixed4 frag (v2f i) : SV_Target<br>         {<br>             float depth = 1 - Linear01Depth(tex2D(_CameraDepthTexture, i.uv));<br>             return depth;<br>         }<br>         ENDCG<br>      }<br>   }<br>}</pre><p>After much trial and even more error, I found a few “gotchas” with how this works.</p><ul><li>As he points out in the tutorial, you <strong>must </strong>have a _MainTex property</li></ul><pre>Properties {<br>    _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}<br>}</pre><p>even though you aren’t going to use it. I believe this helps Unity assign the texture it generates to the shader, as I had a similar issue when trying to set a variable in a shader from a script. This must help define the public interface to the shader.</p><ul><li>From the Unity documentation, Cull Off ZWrite Off ZTest Always is recommended for all image processing shaders.</li><li>Add sampler2D _CameraDepthTexture; as a declared property, next to the also required _sampler2D _MainTex; and _MainTex_ST;.</li></ul><p>The frag shader is the only other tricky bit here. This line</p><pre>1 - Linear01Depth(tex2D(_CameraDepthTexture, i.uv));</pre><p>does a couple of things. First, it reads the _CameraDepthTexture like any other texture, and applies it to the uvs. Mind you, the uvs in this case are literally just one that goes across the whole screen. Secondly Linear01Depth is a UnityCG.cginc macro that normalizes the depth texture values going from the near to the far camera plane. Otherwise the values might not show up terribly well.</p><p>You should then end up with something like this on the right:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3kkiqoTnA37MC-9OxXpjqQ.png" /><figcaption>Depth texture values rendered on the right</figcaption></figure><p>Next is to how use that in the shield shader to show white when the sphere intersects the boxes (or any other geometry).</p><p>First the vertex shader:</p><pre>sampler2D _MainTex;<br>float4 _MainTex_ST;<br>float4 _Color;<br>sampler2D _CameraDepthNormalsTexture;</pre><pre>v2f vert (appdata v)<br>{<br><br>    v2f o;<br>    o.vertex = UnityObjectToClipPos (v.vertex);<br><br>    o.screenuv = ((o.vertex.xy / o.vertex.w) + 1) / 2;<br>    o.screenuv.y = 1 - o.screenuv.y;<br>    <br>    o.depth = -mul(UNITY_MATRIX_MV, v.vertex).z * _ProjectionParams.w;<br>   <br>    return o;<br>   <br>}</pre><p>The line o.screenuv = ((o.vertex.xy / o.vertex.w) + 1) / 2; computes the screen space UV position to sample the depth texture in the frag shader. The 1 — o.screenuv.y; is to flip the y depending on which graphics card you are using (this appears correct for DX).</p><pre>o.depth = -mul(UNITY_MATRIX_MV, v.vertex).z * _ProjectionParams.w;</pre><p>This computes the depth of the vertex. Note that is isn’t using the typical UNITY_MATRIX_MVP matrix, as we don’t want it in clip space, just world space.</p><p>Frag shader:</p><pre>fixed4 frag (v2f i) : SV_Target<br>{<br><br>             float3 normalValues;<br>             float screenDepth;<br><br>    // unpack the depth from the depth texture<br>    DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, i.screenuv), screenDepth, normalValues);<br><br>    // find the distance between screen depth and fragment depth<br>    float diff = screenDepth - i.depth;<br>    <br>    float intersect = 0;<br>    <br>    if (diff &gt; 0) {<br>        // _ProjectionParams.w = 1 / far plane<br>        intersect = 1 - smoothstep(0, _ProjectionParams.w * 0.3, diff);<br>    }<br>             <br>             fixed4 sweetColor = fixed4(lerp(_Color.rgb, fixed3(1,1,1), pow(intersect, 2)), 1);<br><br>    fixed4 col = sweetColor * _Color.a + intersect;<br>   return col;<br>   <br>}</pre><p>I altered the first line around getting the depth normal from the tutorial, as this looked like the preferred method to extract the depth from the docs and other examples, and I couldn’t quite rationalize the code from the tutorial.</p><p>To actually find the intersection, the delta is found by subtracting the screenDepth from the passed in fragment depth. This should look now look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B0C9_hIScJqxr9iOputAig.png" /></figure><p>With that done, the rest of the tutorial focuses on the hex texture that animates down, and the rim shader. Of particular interest was the function he uses to make the hex texture appear in “stripes” as it animates down from the poles. Here’s the function:</p><pre>float triWave(float t, float offset, float yOffset) {<br>    return saturate(abs(frac(offset + t) * 2 - 1) + yOffset);<br>}<br><br>fixed4 texColor(v2f i, float rim) {<br>    fixed4 mainTex = tex2D(_MainTex, i.uv);<br>    mainTex.r *= triWave(_Time.x * 5, abs(i.objectPos.y) * 2, -0.7) * 6;<br>    mainTex.g *= saturate(rim) * (sin(_Time.z + mainTex.b * 5) + 1);<br>   return mainTex.r * _Color + mainTex.g * _Color;<br>}</pre><p>Focusing on the triWave function, I wanted to break it down, so I put the formula into mathematical terms:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sC2JvybOzDMXVdr_dKfRfw.png" /></figure><p>You can see the formula and play with the values at <a href="https://www.desmos.com/calculator/gv7opf8bu8">this link to Desmos</a>, an online graphing calculator. It really helps to understand why the magic numbers are what they are. He calls it “janky,” but looks legit to me! Using a linear function like this keeps the peaks angular, rather than the smooth slopes of a sine function, which is what he seemed to be after.</p><p>The final shader:</p><pre>Shader &quot;Unlit/ShieldShader2&quot;<br>{<br>   Properties<br>   {<br>      _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}<br>      _Color (&quot;Color&quot;, Color) = (1,1,1,1)<br>      _Edge (&quot;Edge Intensity&quot;, Range(0.1,10)) = 2<br>   }<br>   SubShader<br>   {<br>      Tags {<br>          &quot;RenderType&quot;=&quot;Transparent&quot;<br>          &quot;Queue&quot;=&quot;Transparent&quot;<br>      }<br>      Blend One One<br>      ZWrite Off<br>      Cull Off<br><br>      Pass<br>      {<br>         CGPROGRAM<br>         #pragma vertex vert<br>         #pragma fragment frag<br>         #include &quot;UnityCG.cginc&quot;<br><br>         struct appdata<br>         {<br>            float4 vertex : POSITION;<br>            float2 uv : TEXCOORD0;<br>            float3 normal : NORMAL;<br>         };<br><br>         struct v2f<br>         {<br>            float2 uv : TEXCOORD0;<br>            float2 screenuv : TEXCOORD1;<br>            float3 objectPos : TEXCOORD2;<br>            float4 vertex : SV_POSITION;<br>            float depth : DEPTH;<br>            float3 normal : NORMAL;<br>            float3 viewDir : TEXCOORD3;<br>         };<br><br>         sampler2D _MainTex;<br>         float4 _MainTex_ST;<br>         float4 _Color;<br>         sampler2D _CameraDepthNormalsTexture;<br>         float _Edge;<br>         <br>         v2f vert (appdata v)<br>         {<br>         <br>             v2f o;<br>             o.vertex = UnityObjectToClipPos (v.vertex);<br>             o.uv = TRANSFORM_TEX(v.uv, _MainTex);<br><br>             o.screenuv = ((o.vertex.xy / o.vertex.w) + 1) / 2;<br>             o.screenuv.y = 1 - o.screenuv.y;<br>             o.depth = -mul(UNITY_MATRIX_MV, v.vertex).z * _ProjectionParams.w;<br>             <br>             o.normal = UnityObjectToWorldNormal(v.normal);<br>             o.viewDir = normalize(UnityWorldSpaceViewDir(mul(unity_ObjectToWorld, v.vertex)));<br>                o.objectPos = v.vertex.xyz;        <br>            <br>             return o;<br>            <br>         }<br>         <br>         // https://www.desmos.com/calculator/xfmf9o043x<br>         float triWave(float t, float offset, float yOffset) {<br>             return saturate(abs(frac(offset + t) * 2 - 1) + yOffset);<br>         }<br>         <br>         fixed4 texColor(v2f i, float rim) {<br>             fixed4 mainTex = tex2D(_MainTex, i.uv);<br>             mainTex.r *= triWave(_Time.x * 5, abs(i.objectPos.y) * 2, -0.7) * 6;<br>             mainTex.g *= saturate(rim) * (sin(_Time.z + mainTex.b * 5) + 1);<br>            return mainTex.r * _Color + mainTex.g * _Color;<br>         }<br>         <br>         fixed4 frag (v2f i) : SV_Target<br>         {<br><br>                float3 normalValues;<br>                float screenDepth;<br><br>             // unpack the depth from the depth texture<br>             DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, i.screenuv), screenDepth, normalValues);<br><br>             // find the distance between screen depth and fragment depth<br>             float diff = screenDepth - i.depth;<br>             <br>             float intersect = 0;<br>             <br>             if (diff &gt; 0) {<br>                 // _ProjectionParams.w = 1 / far plane<br>                 intersect = 1 - smoothstep(0, _ProjectionParams.w * 0.3, diff);<br>             }<br>             <br>             float rim = 1 - abs(dot(i.normal, normalize(i.viewDir))) * 2;<br>             float northPole = (i.objectPos.y - 0.45) * 20;<br>             float glow = max(max(intersect, rim), northPole);<br>             <br>                fixed4 sweetColor = fixed4(lerp(_Color.rgb, fixed3(1,1,1), pow(glow, _Edge)), 1);<br><br>                fixed4 hexes = texColor(i, rim);<br><br>             fixed4 col = _Color * _Color.a + sweetColor * glow + hexes;<br>            return col;<br>            <br>         }<br>         ENDCG<br>      }<br>   }<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FLightheartedSpitefulAllosaurus&amp;url=https%3A%2F%2Fgfycat.com%2FLightheartedSpitefulAllosaurus&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FLightheartedSpitefulAllosaurus-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="640" height="334" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2d87591e719e95f92ee1214a764ea76/href">https://medium.com/media/f2d87591e719e95f92ee1214a764ea76/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85cdaf903db7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[X-Ray Glow Shader]]></title>
            <link>https://medium.com/@aarhed/x-ray-glow-shader-e9ad6157ef55?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9ad6157ef55</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[shaders]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Wed, 31 Jan 2018 01:39:24 GMT</pubDate>
            <atom:updated>2018-03-09T21:21:46.463Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXXGzCKrmCKSmOVoRVupQw.png" /><figcaption>Shader in play mode on right</figcaption></figure><p>This uses techniques learned from <a href="https://www.youtube.com/watch?v=Tjl8jP5Nuvc">Makin’ Stuff Look Good in Unity,</a> which features an episode about <a href="https://docs.unity3d.com/Manual/SL-ShaderReplacement.html">replacement shaders</a>. Replacement shaders are attached to the camera, and objects in its view can be rendered with a completely different shader than the one specified on that object’s material.</p><p>This requires more parts than a typical shader, as it needs a C# script attached to the camera to do the replacing. Here’s the script from the above shader, which is set up to use an “over draw” shader, turning all objects a solid color.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br><br>[ExecuteInEditMode]<br>public class ReplacementShaderEffect : MonoBehaviour<br>{<br><br>   public Shader ReplacementShader;<br>   public Color OverDrawColor;<br><br>   private void OnValidate()<br>   {<br>      Shader.SetGlobalColor(&quot;_OverDrawColor&quot;, OverDrawColor);<br>   }<br><br>   private void OnEnable()<br>   {<br>      if (ReplacementShader != null)<br>      {<br>         GetComponent&lt;Camera&gt;().SetReplacementShader(ReplacementShader, &quot;&quot;);<br>      }<br>   }<br><br>   private void OnDisable()<br>   {<br>      GetComponent&lt;Camera&gt;().ResetReplacementShader();<br>   }<br>}</pre><p>Two items of note: first, I discovered how to set shader variables from a C# script, with the line:</p><pre>Shader.SetGlobalColor(&quot;_OverDrawColor&quot;, OverDrawColor);</pre><p>This is different than setting a property on a material which has a shader. That looks more like this:</p><pre>AddMaterial.SetFloat(&quot;_AddIntensity&quot;, AdditiveIntensity);<br>AddMaterial.SetColor(&quot;_AddColor&quot;, AddColor);</pre><p>Note that &quot;_AddIntensity&quot; is a property in the shader that is attached to the <em>AddMaterial </em>material.</p><p>The effect above is a combination of two different scripts which use three different shaders:</p><ol><li>The above replacement shader script, with an “over draw” shader, which ignores all lighting and renders objects with a soft additive color. Here it is with just that shader:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RozJt7Vt6qp_0ohi3QV57w.png" /></figure><pre>Shader &quot;Unlit/Over Draw&quot;<br>{<br>   SubShader<br>   {<br>      Tags { &quot;Queue&quot;=&quot;Transparent&quot; }<br><br>        ZTest Always    // always draw this<br>        ZWrite Off<br>        Blend OneMinusDstColor One   // soft additive blend<br><br>      Pass<br>      {<br>         CGPROGRAM<br>         #pragma vertex vert<br>         #pragma fragment frag<br>         <br>         #include &quot;UnityCG.cginc&quot;<br><br>         struct appdata<br>         {<br>            float4 vertex : POSITION;<br>            float2 uv : TEXCOORD0;<br>         };<br><br>         struct v2f<br>         {<br>            float4 vertex : SV_POSITION;<br>         };<br><br>         half4 _OverDrawColor;        <br>         <br>         v2f vert (appdata v)<br>         {<br>            v2f o;<br>            o.vertex = UnityObjectToClipPos(v.vertex);<br>            return o;<br>         }<br>         <br>         fixed4 frag (v2f i) : SV_Target<br>         {<br>            return _OverDrawColor;<br>         }<br>         ENDCG<br>      }<br>   }<br>}</pre><p>ZWrite Off is particularly important here, as otherwise you wouldn’t see all the geometry of the meshes, and it would lack the x-ray effect.</p><p>2. A box blur, which uses multiple loops of a RenderTexture and a blur shader</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br><br>[ExecuteInEditMode]<br>public class BoxBlur : MonoBehaviour<br>{<br><br>   public Material BlurMaterial;<br>   [Range(0, 20)] public int Iterations;<br>   [Range(0, 4)] public int DownRes;<br><br>   private void OnRenderImage(RenderTexture src, RenderTexture dest)<br>   {<br><br>      int width = src.width &gt;&gt; DownRes;<br>      int height = src.height &gt;&gt; DownRes;<br>      <br>      RenderTexture rt = RenderTexture.GetTemporary(width, height);<br>      Graphics.Blit(src, rt);<br><br>      for (int i = 0; i &lt; Iterations; i++)<br>      {<br>         RenderTexture rt2 = RenderTexture.GetTemporary(width, height);<br>         Graphics.Blit(rt, rt2, BlurMaterial);<br>         RenderTexture.ReleaseTemporary(rt);<br>         rt = rt2;<br>      }<br>      <br>      Graphics.Blit(rt, dest);<br>      RenderTexture.ReleaseTemporary(rt);<br>      <br>   }<br>}</pre><p>BoxBlur Shader:</p><pre>Shader &quot;Unlit/BoxBlurShader&quot;<br>{<br>   Properties<br>   {<br>      _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}<br>      _BlurAmount (&quot;Blur Amount&quot;, Range(0,10)) = 0<br>   }<br>   SubShader<br>   {<br>   <br>       Cull Off<br>       ZWrite Off<br>       ZTest Always<br><br>      Pass<br>      {<br>         CGPROGRAM<br>         #pragma vertex vert<br>         #pragma fragment frag<br>         <br>         #include &quot;UnityCG.cginc&quot;<br><br>         struct appdata<br>         {<br>            float4 vertex : POSITION;<br>            float2 uv : TEXCOORD0;<br>         };<br><br>         struct v2f<br>         {<br>            float2 uv : TEXCOORD0;<br>            float4 vertex : SV_POSITION;<br>         };<br><br>         sampler2D _MainTex;<br>         float4 _MainTex_ST;<br>         float4 _MainTex_TexelSize;<br>         float _BlurAmount;<br>         <br>         v2f vert (appdata v)<br>         {<br>            v2f o;<br>            o.vertex = UnityObjectToClipPos(v.vertex);<br>            o.uv = TRANSFORM_TEX(v.uv, _MainTex);<br>            return o;<br>         }<br>         <br>         fixed4 box(sampler2D tex, float2 uv, float4 size) {<br>             fixed4 c = tex2D(tex, uv + float2(-size.x, size.y)) +<br>                    tex2D(tex, uv + float2(0, size.y)) +<br>                    tex2D(tex, uv + float2(size.x, size.y)) +<br>                    tex2D(tex, uv + float2(-size.x, 0)) +<br>                    tex2D(tex, uv + float2(0, 0)) +<br>                    tex2D(tex, uv + float2(size.x, 0)) +<br>                    tex2D(tex, uv + float2(-size.x, -size.y)) +<br>                    tex2D(tex, uv + float2(0, -size.y)) +<br>                    tex2D(tex, uv + float2(size.x, -size.y));<br>                    <br>             return c / 9;<br>                    <br>         }<br>         <br>         fixed4 frag (v2f i) : SV_Target<br>         {<br>            fixed4 col = box(_MainTex, i.uv, _MainTex_TexelSize * _BlurAmount);<br>            return col;<br>         }<br>         ENDCG<br>      }<br>   }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*abnyBYEnb7HV9HVSPN4FgQ.png" /><figcaption>Box blur</figcaption></figure><p>3. An additive blending shader</p><pre>Shader &quot;Unlit/AdditiveShader&quot;<br>{<br>   Properties<br>   {<br>       _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}<br>       _AddColor (&quot;Add Color&quot;, Color) = (0,1,0,0)<br>       _AddIntensity (&quot;Intensity&quot;, Range(0,1)) = 0<br>   }<br>   SubShader<br>   {<br>   <br>       Cull Off<br>       ZWrite Off<br>       ZTest Always<br><br>      Pass<br>      {<br>         CGPROGRAM<br>         #pragma vertex vert<br>         #pragma fragment frag<br>         <br>         #include &quot;UnityCG.cginc&quot;<br><br>         struct appdata<br>         {<br>            float4 vertex : POSITION;<br>            float2 uv : TEXCOORD0;<br>         };<br><br>         struct v2f<br>         {<br>            float2 uv : TEXCOORD0;<br>            float4 vertex : SV_POSITION;<br>         };<br><br>         sampler2D _MainTex;<br>         float4 _MainTex_ST;<br>         float _AddIntensity;<br>         fixed4 _AddColor;<br>         <br>         v2f vert (appdata v)<br>         {<br>            v2f o;<br>            o.vertex = UnityObjectToClipPos(v.vertex);<br>            o.uv = TRANSFORM_TEX(v.uv, _MainTex);<br>            return o;<br>         }<br>         <br>         fixed4 frag (v2f i) : SV_Target<br>         {<br>            fixed4 col = tex2D(_MainTex, i.uv) + (_AddColor * _AddIntensity);<br>            return col;<br>         }<br>         ENDCG<br>      }<br>   }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eGULsteFpMbjByu07KTbQ.png" /><figcaption>Box blur + additive. Lookin pretty glowy!</figcaption></figure><p>Once those are all combined, you get the full x-ray / glow effect!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wxt95hghBbfYc0DdUy2pYQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9ad6157ef55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stencil shaders]]></title>
            <link>https://medium.com/@aarhed/stencil-shaders-98dc5af347d4?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/98dc5af347d4</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[shaders]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 18:01:01 GMT</pubDate>
            <atom:updated>2018-03-09T21:22:19.452Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*EZ4zjac-8foKRCGHObzdFw.png" /><figcaption>See below for animated version</figcaption></figure><p>The stencil buffer allows shaders to use one set of meshes to mask another. For instance, if you want to put a hole in this wall, so you can see if there are any bunnies hiding behind it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*yVgYa6mslxIHaQrztK4gLw.png" /></figure><p>The red circle can be used as a hole</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jxeikHSUsfKHgGgLvqgK1A.gif" /></figure><p>This works by filling in the stencil buffer with a value for those pixels where the hole is. In this case, I am filling it with 1s where the hole is, if you were looking directly forward at the hole:</p><pre>Stencil Buffer<br>000000000<br>000010000<br>000111000<br>000010000<br>000000000</pre><p>Once those 1s are there, we will do a test in the wall shader to check if there is a 1 at that wall pixel. If there’s a 1, we do not draw that pixel. If there’s a zero, we draw the wall as usual. Essentially it would look like this, if it was written in normal code:</p><pre>// Wall shader psuedocode<br>bool drawWallPixel = stencilValue != 1</pre><p>In actual shader code, here is what the hole shader does, in the SubShader section:</p><pre>Tags {<br>   &quot;Queue&quot; = &quot;Geometry-1&quot; // gets to the stencil buffer first<br>}<br>   <br>ColorMask 0   // do not draw this (it&#39;s a hole!)<br>ZWrite off    // the hole has no depth  <br>   <br>Stencil {<br>    Ref 1        // write a 1 into the buffer<br>    Comp always  // comparison for what is already there.<br>    Pass replace // Replace anything in the frame buffer with this pixel pass.<br>}</pre><pre>... Lambert shader ...</pre><p>Very important point above to be sure that the hole shader is process before any others, by setting the <strong>Queue </strong>to a value less than the objects that you are wanting to punch out.</p><p>Here’s the wall shader:</p><pre>Tags {<br>    &quot;Queue&quot; = &quot;Geometry&quot; // needs to be drawn after hole<br>   }<br>   <br>   Stencil {<br>       Ref 1               // use 1 as the value to check against<br>       Comp notequal       // If this stencil Ref 1 is not equal to what&#39;s in the stencil buffer, then we will keep this pixel that belongs to the Wall<br>       Pass keep           // If you do find a 1, don&#39;t draw it.<br>   }</pre><pre>... Lambert shader ...</pre><p>Essentially Ref is the value to test against, Comp is what kind of comparison to make, and Pass is what the resulting action should be.</p><p><a href="https://docs.unity3d.com/Manual/SL-Stencil.html">Full documentation on the values used for stencil buffers</a></p><p>Using multiple stencil shaders and values, like writing a 1 or a 2 depending on which hole is being looked through, you can get trippy effects like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*vez7dEvoKvxWNEb-E4D3wQ.gif" /></figure><p>From Penny de Byl’s excellent <a href="https://www.udemy.com/unity-shaders/?couponCode=COOLINSHADES">Shader Development from Scratch for Unity with Cg class</a>! More at <a href="http://holistic3d.com/">holistic3d.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98dc5af347d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hologram shader]]></title>
            <link>https://medium.com/@aarhed/hologram-shader-a02691e631ce?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a02691e631ce</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Tue, 23 Jan 2018 18:01:02 GMT</pubDate>
            <atom:updated>2018-03-09T21:22:44.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*Uh81F_A8iOSY3SyKdTMn9Q.png" /><figcaption>Wonder Woman’s car?</figcaption></figure><p>This is actually just a modification of the earlier rim shader. The difference being that instead of just adding a color with high dot product values, we also add alpha with the inverse of those values. So essentially it creates a rim color to transparent ramp. Hm, I wonder if the ramp shader could pull this off with a blue to transparent gradient? 🤔</p><p>New concepts in this shader include manually specifying the Queue to transparent . This means objects rendered with this shader will be drawn after the default <em>geometry</em>-tagged objects, so it will compute the transparency correctly.</p><p>Also, the additional Pass{} section adds an interesting feature. Without that, you get the image above, where you can literally see the interiors of the model, no matter what surfaces are closest to the viewer. Adding ZWrite On means it will do a depth test, and write the depth of the surfaces to the z-buffer, and cull those surfaces that are being hidden. The end result looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWkB0XhU1xvOkIqdwiPYtQ.png" /><figcaption>ZWrite On no longer shows interior surfaces</figcaption></figure><pre>Shader &quot;Custom/Hologram&quot; {<br> Properties {<br>  _RimColor (&quot;Rim Color&quot;, Color) = (0,0.5,0.5,0.0)<br>  _RimPower (&quot;Rim Power&quot;, Range(0.5, 8.0)) = 3.0<br> }<br> SubShader {<br>        <br>        Tags {&quot;Queue&quot; = &quot;Transparent&quot;}<br>        <br>        Pass {<br>            ZWrite On       // Fixes z-ordering of interior parts of zombunny coming through, by writing to z-buffer<br>            ColorMask 0     // do not write to the frame buffer<br>        }<br>        <br>  CGPROGRAM<br>  #pragma surface surf Lambert alpha:fade</pre><pre>struct Input {<br>   float3 viewDir;<br>  };<br>  <br>  float4 _RimColor;<br>  float _RimPower;</pre><pre>void surf (Input IN, inout SurfaceOutput o) {<br>   half rim = 1 - saturate(dot(normalize(IN.viewDir), o.Normal));<br>   o.Emission = _RimColor.rgb * pow(rim, _RimPower) * 10;<br>   o.Alpha = pow (rim, _RimPower);<br>  }<br>  ENDCG<br> }<br> FallBack &quot;Diffuse&quot;<br>}</pre><p>From Penny de Byl’s excellent <a href="https://www.udemy.com/unity-shaders/?couponCode=COOLINSHADES">Shader Development from Scratch for Unity with Cg class</a>! More at <a href="http://holistic3d.com/">holistic3d.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a02691e631ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toon shader with a custom lighting model]]></title>
            <link>https://medium.com/@aarhed/toon-shader-with-a-custom-lighting-model-276030c0338b?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/276030c0338b</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 18:01:01 GMT</pubDate>
            <atom:updated>2018-01-23T00:01:48.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*qsaZdjFrxelr0GE33oK9Ug.png" /><figcaption>Same shader with three different source images</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*S166SSsIfoxwT7-2USKFdg.png" /></figure><p>This shader could be a lot of fun. Using a custom lighting function, it applies a color from a given texture’s UV coordinates based on the dot product of that pixel. Thus, the more perpendicular the normal for that pixel is from the light source, the further to the top left it samples the texture’s color. Step by step:</p><ol><li>Set up a custom lighting model function. ToonRamp in the #pragma must match the function name with Lighting prepended. The <a href="https://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html">parameters are explained in these Unity Docs</a>.</li></ol><pre>CGPROGRAM<br>#pragma surface surf ToonRamp<br>        <br>float4 _Color;<br>sampler2D _RampTex;<br>        <br>float4 LightingToonRamp (SurfaceOutput s, fixed3 lightDir, fixed atten) {</pre><p>2. Get the dot product of the surface normal and the light direction.</p><pre>float diffuse = dot (s.Normal, lightDir);</pre><p>3. Normalize the value of the dot product, as the above gives you a range of -1 to 1. We want 0 to 1, which is the scale UVs use.</p><pre>float normalizedDiffuse = diffuse * 0.5 + 0.5;  // 0 - 1<br>float2 normalizedDiffuseUV = normalizedDiffuse; // convert to float2 for use as a UV coordinate</pre><p>4. Look up the color from the texture</p><pre>float3 ramp = tex2D(_RampTex, normalizedDiffuseUV).rgb;</pre><p>5. Assign ramp color mixed with light color to the albedo on the surface shader struct.</p><pre>float4 c;<br>c.rgb = s.Albedo * _LightColor0.rgb * (ramp);<br>c.a = s.Alpha;<br>return c;</pre><p>6. The rest of the function is simple</p><pre>struct Input {<br>    float2 uv_MainTex;<br>};</pre><pre>void surf(Input IN, inout SurfaceOutput o) {<br>    o.Albedo = _Color.rgb;<br>}</pre><pre>ENDCG</pre><p>From <a href="https://www.udemy.com/unity-shaders/">Penny de Byl’s excellent Shader Development from Scratch for Unity with Cg class!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=276030c0338b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[World position stripes shader]]></title>
            <link>https://medium.com/@aarhed/world-position-stripes-shader-4991ddc4fb4b?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/4991ddc4fb4b</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[shaders]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Fri, 19 Jan 2018 01:12:41 GMT</pubDate>
            <atom:updated>2018-01-22T23:57:35.869Z</atom:updated>
            <content:encoded><![CDATA[<p>Uses the world position of the pixel to apply a color within a defined set of bounds. This uses the frac function, which returns the value after the decimal for any given value, e.g. 5.06 becomes 0.6 . Much like the modulo operator, this can be used to alternate on even / odd values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rA_HYP7AkSYarRxz8OPHVA.gif" /><figcaption>Just not flattering</figcaption></figure><pre>Shader &quot;Custom/Stripes&quot; {<br>   Properties {<br>       _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}<br>      _RimColor (&quot;Rim Color&quot;, Color) = (0,0.5,0.5,0.0)<br>      _RimPower (&quot;Rim Power&quot;, Range(0.5, 8.0)) = 3.0<br>      _StripeSize (&quot;Stripe Size&quot;, Range(1, 100.0)) = 10.0<br>   }<br>   SubShader {<br><br>      CGPROGRAM<br>      #pragma surface surf Lambert<br><br>      struct Input {<br>          float2 uv_MainTex;<br>         float3 viewDir;<br>         float3 worldPos;<br>      };<br>      <br>      float4 _RimColor;<br>      float _RimPower;<br>      sampler2D _MainTex;<br>      float _StripeSize;<br><br>      void surf (Input IN, inout SurfaceOutput o) {<br>      <br>          fixed3 color = tex2D(_MainTex, IN.uv_MainTex).rgb;<br>      <br>         half rim = 1 - saturate(dot(normalize(IN.viewDir), o.Normal));<br>         <br>         // frac used here to tell if this is an even or odd number, by checking if it has a<br>         // decimal remainder<br>         o.Emission = frac(IN.worldPos.y * _StripeSize * 0.5) &gt; 0.4 ? color * rim : float3(1,0,0) * rim;<br>         <br>         // frac: Fraction -- gives you the value after the decimal<br><br>      }<br>      ENDCG<br>   }<br>   FallBack &quot;Diffuse&quot;<br>}</pre><p>From <a href="https://www.udemy.com/unity-shaders/">Penny de Byl’s excellent Shader Development from Scratch for Unity with Cg class!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4991ddc4fb4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bump map shader]]></title>
            <link>https://medium.com/@aarhed/bump-map-shader-8b662f18c62?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b662f18c62</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Fri, 19 Jan 2018 01:10:04 GMT</pubDate>
            <atom:updated>2018-01-22T23:57:18.047Z</atom:updated>
            <content:encoded><![CDATA[<p>This shader uses a diffuse and a normal map, and allows adjustment of how “deep” the bump mapping is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wothFAHtNpvUt6xzSn-FRw.gif" /><figcaption>Zombunny getting swole</figcaption></figure><pre>Shader &quot;Custom/BumpedEnvironment&quot; {<br>   Properties {<br>      _myDiffuse (&quot;Diffuse Texture&quot;, 2D) = &quot;white&quot; {}<br>      _myBump (&quot;Bump Texture&quot;, 2D) = &quot;bump&quot; {}<br>      _mySlider (&quot;Bump Amount&quot;, Range(0,10)) = 1<br>      _myBright (&quot;Brightness&quot;, Range(0,10)) = 1<br>      _myCube (&quot;Cube Map&quot;, CUBE) = &quot;white&quot; {}<br>   }<br>   SubShader {<br><br>      CGPROGRAM<br>      <br>      #pragma surface surf Lambert<br><br>        sampler2D _myDiffuse;<br>        sampler2D _myBump;<br>        half _mySlider;<br>        half _myBright;<br>        samplerCUBE _myCube;<br><br>      struct Input {<br>         float2 uv_myDiffuse;<br>         float2 uv_myBump;<br>         float3 worldRefl; INTERNAL_DATA  // &lt;- THIS IS VERY IMPORTANT<br>      };<br><br>      void surf (Input IN, inout SurfaceOutput o) {<br>          o.Albedo = tex2D(_myDiffuse, IN.uv_myDiffuse).rgb;<br>          o.Normal = UnpackNormal(tex2D(_myBump, IN.uv_myBump)) * _myBright;<br>          o.Normal *= float3(_mySlider, _mySlider, 1);<br>          o.Emission = texCUBE(_myCube, WorldReflectionVector(IN, o.Normal)).rgb;<br><br>      }<br>      <br>      ENDCG<br>   }<br>   FallBack &quot;Diffuse&quot;<br>}</pre><p>It also supports adding a reflection to the emission, which looks insane with the random assortment of textures I’m using</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hp5KCXz6Boio9nsP-FbP3Q.png" /></figure><p>From <a href="https://www.udemy.com/unity-shaders/">Penny de Byl’s excellent Shader Development from Scratch for Unity with Cg class!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b662f18c62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tiered rim shader]]></title>
            <link>https://medium.com/@aarhed/tiered-rim-shader-e15391d53332?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e15391d53332</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Fri, 19 Jan 2018 00:57:26 GMT</pubDate>
            <atom:updated>2018-01-22T23:56:33.996Z</atom:updated>
            <content:encoded><![CDATA[<p>Similar to the basic rim, this just creates two thresholds of values of the dot product, and assigns different colors to each:</p><pre>half rim = 1 — saturate(dot(normalize(IN.viewDir), o.Normal));<br>o.Emission = rim &gt; 0.7 ? _RimColor1 : rim &gt; 0.6 ? _RimColor2 : 0;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*04qM7TSbHWsjM85jMkUDng.png" /></figure><p>Striking to see how this reacts to the cube, where the threshold along its edges is very noticeable. If this was using per-vertex normals, each face of the cube would be the same color. But because this is per-pixel, it evaluates the cube face at each visible pixel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*37BK2Ob8TQ7XSgx6mDRWFA.gif" /></figure><p>From <a href="https://www.udemy.com/unity-shaders/">Penny de Byl’s excellent Shader Development from Scratch for Unity with Cg class!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e15391d53332" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Rim Shader]]></title>
            <link>https://medium.com/@aarhed/basic-rim-shader-337efc121044?source=rss-c1d867d387cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/337efc121044</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Aaron Hedquist]]></dc:creator>
            <pubDate>Fri, 19 Jan 2018 00:45:00 GMT</pubDate>
            <atom:updated>2018-01-22T23:56:12.665Z</atom:updated>
            <content:encoded><![CDATA[<p>You can create a basic “rim shader,” which adds color around the edges of polygons, using the dot product of the view direction and surface normal per-pixel:</p><pre>half rim = 1 - saturate( dot( normalize(IN.viewDir), o.Normal) );<br>o.Emission = rim * _RimColor;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LyXOQHVtJ0YIJT78V4vpQw.png" /></figure><p>From <a href="https://www.udemy.com/unity-shaders/">Penny de Byl’s excellent Shader Development from Scratch for Unity with Cg class!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=337efc121044" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>