You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.9 KiB

  1. Shader "Hidden/Post FX/Monitors/Vectorscope Render"
  2. {
  3. SubShader
  4. {
  5. ZTest Always Cull Off ZWrite Off
  6. Fog { Mode off }
  7. CGINCLUDE
  8. #pragma fragmentoption ARB_precision_hint_fastest
  9. #pragma target 5.0
  10. #include "UnityCG.cginc"
  11. StructuredBuffer<uint> _Vectorscope;
  12. float2 _Size;
  13. float _Exposure;
  14. float Tonemap(float x, float exposure)
  15. {
  16. const float a = 6.2;
  17. const float b = 0.5;
  18. const float c = 1.7;
  19. const float d = 0.06;
  20. x *= exposure;
  21. x = max(0.0, x - 0.004);
  22. x = (x * (a * x + b)) / (x * (a * x + c) + d);
  23. return x * x;
  24. }
  25. float3 YuvToRgb(float3 c)
  26. {
  27. float R = c.x + 0.000 * c.y + 1.403 * c.z;
  28. float G = c.x - 0.344 * c.y - 0.714 * c.z;
  29. float B = c.x - 1.773 * c.y + 0.000 * c.z;
  30. return float3(R, G, B);
  31. }
  32. float4 FragBackground(v2f_img i) : SV_Target
  33. {
  34. i.uv.x = 1.0 - i.uv.x;
  35. float2 uv = i.uv - (0.5).xx;
  36. float3 c = YuvToRgb(float3(0.5, uv.x, uv.y));
  37. float dist = sqrt(dot(uv, uv));
  38. float delta = fwidth(dist);
  39. float alphaOut = 1.0 - smoothstep(0.5 - delta, 0.5 + delta, dist);
  40. float alphaIn = smoothstep(0.495 - delta, 0.495 + delta, dist);
  41. uint2 uvI = i.pos.xy;
  42. uint v = _Vectorscope[uvI.x + uvI.y * _Size.x];
  43. float vt = saturate(Tonemap(v, _Exposure));
  44. float4 color = float4(lerp(c, (0.0).xxx, vt), alphaOut);
  45. color.rgb += alphaIn;
  46. return color;
  47. }
  48. float4 FragNoBackground(v2f_img i) : SV_Target
  49. {
  50. i.uv.x = 1.0 - i.uv.x;
  51. float2 uv = i.uv - (0.5).xx;
  52. float dist = sqrt(dot(uv, uv));
  53. float delta = fwidth(dist);
  54. float alphaOut = 1.0 - smoothstep(0.5 - delta, 0.5 + delta, dist);
  55. float alphaIn = smoothstep(0.495 - delta, 0.495 + delta, dist);
  56. uint2 uvI = i.pos.xy;
  57. uint v = _Vectorscope[uvI.x + uvI.y * _Size.x];
  58. float vt = saturate(Tonemap(v, _Exposure));
  59. float4 color = float4((1.0).xxx, vt + alphaIn * alphaOut);
  60. return color;
  61. }
  62. ENDCG
  63. // (0)
  64. Pass
  65. {
  66. CGPROGRAM
  67. #pragma vertex vert_img
  68. #pragma fragment FragBackground
  69. ENDCG
  70. }
  71. // (1)
  72. Pass
  73. {
  74. CGPROGRAM
  75. #pragma vertex vert_img
  76. #pragma fragment FragNoBackground
  77. ENDCG
  78. }
  79. }
  80. FallBack off
  81. }