### Want to try this Exercise?

Start a free 7-day trial today. It's quick - and you can cancel anytime.

• 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

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. ## 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;
}

```