1 #pragma warning(disable : 3568)
2 #pragma exclude_renderers gles gles3 d3d11_9x
4 #include "../StdLib.hlsl"
5 #include "../Colors.hlsl"
7 RWStructuredBuffer<uint> _VectorscopeBuffer;
8 Texture2D<float4> _Source;
10 CBUFFER_START (Params)
11 float4 _Params; // x: source width, y: source height, z: buffer size, w: linear?
14 #define GROUP_SIZE_X 16
15 #define GROUP_SIZE_Y 16
17 #ifdef DISABLE_COMPUTE_SHADERS
19 TRIVIAL_COMPUTE_KERNEL(KVectorscopeGather)
20 TRIVIAL_COMPUTE_KERNEL(KVectorscopeClear)
24 #pragma kernel KVectorscopeGather
25 [numthreads(GROUP_SIZE_X, GROUP_SIZE_Y, 1)]
26 void KVectorscopeGather(uint2 dispatchThreadId : SV_DispatchThreadID)
28 if (dispatchThreadId.x < uint(_Params.x) && dispatchThreadId.y < uint(_Params.y))
30 float3 color = saturate(_Source[dispatchThreadId].xyz);
33 color = LinearToSRGB(color);
35 float3 yuv = RgbToYCbCr(color);
37 uint u = (uint)floor(yuv.y * _Params.z);
38 uint v = (uint)floor(yuv.z * _Params.z);
39 InterlockedAdd(_VectorscopeBuffer[v * _Params.z + u], 1u);
43 #pragma kernel KVectorscopeClear
44 [numthreads(GROUP_SIZE_X, GROUP_SIZE_Y, 1)]
45 void KVectorscopeClear(uint2 dispatchThreadId : SV_DispatchThreadID)
47 if (dispatchThreadId.x < uint(_Params.z) && dispatchThreadId.y < uint(_Params.z))
48 _VectorscopeBuffer[dispatchThreadId.y * _Params.z + dispatchThreadId.x] = 0u;