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.

49 lines
1.3 KiB

  1. #include "UnityCG.cginc"
  2. RWStructuredBuffer<uint> _Vectorscope;
  3. Texture2D<float4> _Source;
  4. CBUFFER_START (Params)
  5. uint _IsLinear;
  6. float4 _Res;
  7. CBUFFER_END
  8. #define GROUP_SIZE 32
  9. float3 RgbToYUV(float3 c)
  10. {
  11. float Y = 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
  12. float U = -0.169 * c.r - 0.331 * c.g + 0.500 * c.b;
  13. float V = 0.500 * c.r - 0.419 * c.g - 0.081 * c.b;
  14. return float3(Y, U, V);
  15. }
  16. #pragma kernel KVectorscope
  17. [numthreads(GROUP_SIZE,GROUP_SIZE,1)]
  18. void KVectorscope(uint2 dispatchThreadId : SV_DispatchThreadID)
  19. {
  20. if (dispatchThreadId.x < (uint)_Res.x && dispatchThreadId.y < (uint)_Res.y)
  21. {
  22. float3 color = saturate(_Source[dispatchThreadId].xyz);
  23. if (_IsLinear > 0)
  24. color = LinearToGammaSpace(color);
  25. float3 yuv = RgbToYUV(color);
  26. if (length(yuv.yz) > 0.49)
  27. yuv.yz = normalize(yuv.yz) * 0.49;
  28. yuv.yz += (0.5).xx;
  29. uint u = (uint)floor(yuv.y * _Res.x);
  30. uint v = (uint)floor(yuv.z * _Res.y);
  31. InterlockedAdd(_Vectorscope[v * _Res.x + u], 1);
  32. }
  33. }
  34. #pragma kernel KVectorscopeClear
  35. [numthreads(GROUP_SIZE,GROUP_SIZE,1)]
  36. void KVectorscopeClear(uint2 dispatchThreadId : SV_DispatchThreadID)
  37. {
  38. if (dispatchThreadId.x < (uint)_Res.x && dispatchThreadId.y < (uint)_Res.y)
  39. _Vectorscope[dispatchThreadId.y * _Res.x + dispatchThreadId.x] = 0u;
  40. }