Interested in this Exercise?

Watch the course trailer to see what's inside, read the description, and then start learning on CG Cookie today.

Watch course trailer Start Learning

Flickering Hologram Shader

crew
  • Software:Unity 2017  ·
  • Difficulty:Intermediate

Rules of the Exercise

  • 1
    Change the color of the smaller scanlines
  • 2
    Create bigger scan lines that effect the alpha (flickering effect)
  • 3
    Change the speed and direction of the bigger scanlines

Lets Add Flickering!

In this exercise we'll learn how to modify our shader to creating a flickering effect. This is a useful technique in creating a hologram that seems to be going in and out or just as a way to create something a bit more unique. Taking the techniques taught in the original Hologram shader chapter, we'll essentially reverse some of the effects and apply color to smaller scan lines while using the bigger scan lines to affect the alpha of the mesh. The bigger scan lines will effectively create a flickering or scanning effect since it will control what part of the mesh will be visible at any point.
 

Submission Process

Upload a video of your shader demonstrating the effects needed for this exercise. Provide a link to your video submission to be graded. 

Instructors Notes

If you've tried to create this effect but not having any luck, take a look below on how it was created. This requires a slight modification to our frag function. Here is the before version:

fixed4 frag (v2f i) : SV_Target
{
    float scan = step(frac(i.worldVertex.y * _ScanlineScale + _Time.y * _ScanlineSpeed), .75);
       float bigfracline = frac((i.worldVertex.y) - _Time.x * 10);
       fixed4 tex = tex2D(_MainTex, i.uv);
       half rim = 1 - saturate(dot(i.viewDir, i.worldNormal));
       fixed4 rimColor = _RimColor * pow(rim, _RimPower);
       fixed4 c = tex * _MainColor + (bigfracline * 0.5 * _MainColor) + rimColor;
       c.a = _Alpha * scan;
       c.rgb *= _RimBrightness; 
       return c;
  }



and here is the modified version. You'll see that we've essentially flipped the effects of either scanline. The thick scanlines now affect the alpha of the mesh, while the thin scalines only affect color. We also made the thick scanlines move upward creating the effect of "flickering". Take a look down below, note the original first two lines are just commented out:

fixed4 frag (v2f i) : SV_Target
 {
            
//     float scan = step(frac(i.worldVertex.y * _ScanlineScale + _Time.y *_ScanlineSpeed), .75);
//     float bigScanline = frac(i.worldVertex.y - _Time.x * 10);
       float scan = frac(i.worldVertex.y * _ScanlineScale + _Time.y *_ScanlineSpeed);
       float bigScanline = frac(i.worldVertex.y + _Time.y * 10);
       fixed4 tex = tex2D(_MainTex, i.uv);
       half rim = 1 - saturate(dot(i.viewDir, i.worldNormal));
       fixed4 rimColor = _RimColor * pow(rim, _RimPower);
       fixed4 col = tex * _MainColor + (scan * 0.5 * _ScanlineColor) + rimColor;
       col.a = _Alpha * bigScanline;
       col.rgb *= _RimBrightness;
       return col;
  }