// The video call's picture (TalkVideo): a talking loop filmed on black (Unity's player drops the webm's alpha), keyed // out again here and laid over the room behind the character, with a hologram that brings it in and takes it away. // The key: near-black is see-through, with a soft rim by brightness; dark bits the figure closes round (pupils, creases // of a navy suit) stay solid, because opaque figure is found on both sides of them. // _Appear 0..1: a glow of light sweeps up the window and leaves the picture behind it, tinted, scanlined, flickering, // breaking up in blocks and slipping sideways in bands; it settles as _Appear reaches 1, where only faint scanlines, // a slow bright roll and a rare glitch stay. Shader "GrassCutter/TalkHolo" { Properties { _MainTex ("Stacked loop", 2D) = "black" {} _BgTex ("Room behind", 2D) = "black" {} _Appear ("Appear", Range(0, 1)) = 1 _Tint ("Hologram", Color) = (0.35, 0.9, 1, 1) } SubShader { Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex, _BgTex; float4 _FigST, _BgST, _Px, _Tint, _MainTex_TexelSize; float _Appear, _T, _HasBg; float hash(float2 p) { return frac(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); } float noise(float2 p) { float2 i = floor(p), f = frac(p); f = f * f * (3 - 2 * f); return lerp(lerp(hash(i), hash(i + float2(1, 0)), f.x), lerp(hash(i + float2(0, 1)), hash(i + 1), f.x), f.y); } // how bright the brightest channel is, as filmed (the texture hands it over in linear) float Peak(float2 uv) { float3 c = max(tex2Dlod(_MainTex, float4(uv, 0, 0)).rgb, 0); #ifndef UNITY_COLORSPACE_GAMMA c = LinearToGammaSpace(c); #endif return max(c.r, max(c.g, c.b)); } // the background is at most this bright (a little blue from the codec); a pixel this bright is figure for sure #define LO (14.0 / 255.0) #define HI (30.0 / 255.0) float Solid(float2 uv) { return step(HI, Peak(uv)); } // a dark pixel with figure on both sides of it, at any of three reaches (a pupil is ~30 texels across), along any // of four lines, is figure float Closed(float2 uv) { float fill = 0; [unroll] for (int k = 0; k < 3; k++) { float2 t = _MainTex_TexelSize.xy * (k == 0 ? 6.0 : k == 1 ? 14.0 : 26.0); fill = max(fill, Solid(uv + float2(t.x, 0)) * Solid(uv - float2(t.x, 0))); fill = max(fill, Solid(uv + float2(0, t.y)) * Solid(uv - float2(0, t.y))); fill = max(fill, Solid(uv + t) * Solid(uv - t)); fill = max(fill, Solid(uv + float2(t.x, -t.y)) * Solid(uv - float2(t.x, -t.y))); } return fill; } // the figure at fuv: colour (dark at the edge, as filmed on black, so it's already "premultiplied") and coverage float4 Figure(float2 fuv) { if (any(fuv < 0) || any(fuv > 1)) return 0; float3 c = tex2D(_MainTex, fuv).rgb; float a = smoothstep(LO, HI, Peak(fuv)); if (a < 1) a = max(a, Closed(fuv)); return float4(c * step(0.001, a), a); } float3 Colour(float2 fuv) { if (any(fuv < 0) || any(fuv > 1)) return 0; return tex2D(_MainTex, fuv).rgb; } float4 frag(v2f_img i) : SV_Target { float2 uv = i.uv; float t = _T; float ap = smoothstep(0, 1, _Appear); float hs = saturate((1 - ap) * 1.6); // how much hologram // sideways slips in bands: often while it's coming in, now and then once it's on float tick = floor(t * 14); float band = floor(uv.y * 28 + hash(float2(tick, 7)) * 9); float slipOn = step(0.8, hash(float2(band, tick))) * (hs + step(0.985, hash(float2(floor(t * 3), 1))) * 0.25); uv.x += (hash(float2(band, tick + 3)) - 0.5) * 0.08 * slipOn; // the sweep: up the window, its front ragged with noise float n = noise(uv * float2(14, 30) + t * 2.5); float front = ap * 1.3 - 0.15; float edge = uv.y + (n - 0.5) * 0.1; float shown = smoothstep(front + 0.012, front - 0.012, edge); float glow = exp(-abs(edge - front) * 55) * saturate(hs * 4); // breaking up into blocks just behind the front float zone = saturate((edge - (front - 0.22)) / 0.22) * hs; // (only while it's coming or going: a hash can come out at exactly 0, and step(0, 0) is 1) float holes = zone > 0.001 ? step(hash(floor(uv * float2(46, 70)) + floor(t * 22) * 0.137), zone) : 0; // the room, a little out of focus and darker than her float3 bg = 0; if (_HasBg > 0.5) { bg = tex2Dbias(_BgTex, float4(uv * _BgST.xy + _BgST.zw, 0, 1.2)).rgb; float2 d = i.uv - 0.5; bg *= 0.82 * (1 - dot(d, d) * 0.9); } // her, split a hair into red/green/blue (more while coming in), each over the room float2 fuv = uv * _FigST.xy + _FigST.zw; float ca = 0.0015 + 0.02 * hs; float4 fg = Figure(fuv); float3 fc = float3(Colour(fuv + float2(ca, 0)).r, fg.g, Colour(fuv - float2(ca, 0)).b) * step(0.001, fg.a); float3 col = fc + bg * (1 - fg.a); // the hologram's tint, scanlines, a slow bright roll, flicker float lum = dot(col, float3(0.3, 0.59, 0.11)); col = lerp(col, lum * _Tint.rgb * 1.7 + _Tint.rgb * 0.06, hs * 0.8); float scan = 0.5 + 0.5 * sin(uv.y * _Px.y * 1.6 - t * 8); col *= 1 - (0.06 + 0.3 * hs) * scan; float r = frac(uv.y * 0.7 - t * 0.12); col += _Tint.rgb * smoothstep(0, 0.05, r) * (1 - smoothstep(0.05, 0.14, r)) * (0.035 + 0.1 * hs); float flick = 1 - hs * 0.4 * step(0.55, hash(float2(floor(t * 24), 3))); float body = shown * flick * (1 - holes * 0.9); float a = saturate(body + glow); float3 rgb = (col * body + _Tint.rgb * glow * 1.6) / max(a, 1e-3); return float4(saturate(rgb), a); } ENDCG } } }