float4 shadeVideo(ShaderContext context) { float4 color = context.sourceColor; float height = saturate(overlayHeight); float overlayStart = 1.0 - height; if (context.uv.y < overlayStart) return color; float2 scopeUv = float2(context.uv.x, (context.uv.y - overlayStart) / max(height, 0.001)); float luma = dot(sampleVideo(float2(context.uv.x, 0.5)).rgb, float3(0.2126, 0.7152, 0.0722)); float targetY = 1.0 - saturate(luma); float pixelThickness = max(lineThickness, 0.5) / max(context.outputResolution.y * height, 1.0); float wave = 1.0 - smoothstep(pixelThickness, pixelThickness * 2.5, abs(scopeUv.y - targetY)); float grid = 0.0; grid = max(grid, 1.0 - smoothstep(0.002, 0.006, abs(scopeUv.y - 0.25))); grid = max(grid, 1.0 - smoothstep(0.002, 0.006, abs(scopeUv.y - 0.50))); grid = max(grid, 1.0 - smoothstep(0.002, 0.006, abs(scopeUv.y - 0.75))); float3 bg = lerp(color.rgb, float3(0.0, 0.0, 0.0), saturate(backgroundOpacity)); float3 withGrid = lerp(bg, float3(0.16, 0.22, 0.28), grid * 0.5); float3 scoped = lerp(withGrid, waveformColor.rgb, wave * saturate(waveformOpacity) * waveformColor.a); return float4(scoped, color.a); }