-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathSEGITransferInts.compute
89 lines (65 loc) · 1.72 KB
/
SEGITransferInts.compute
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma kernel CSMain
#pragma kernel CSMain2
RWTexture3D<float4> Result;
Texture3D<float4> PrevResult;
Texture3D<uint> RG0;
SamplerState _PointClamp;
int Resolution;
int VoxelAA;
float4 VoxelOriginDelta;
float2 IntToFloats(uint intval)
{
float value1 = f16tof32(intval);
float value2 = f16tof32(intval / 0x0000FFFF);
return float2(value1, value2);
}
float3 hsv2rgb(float3 c)
{
float4 k = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + k.xyz) * 6.0 - k.www);
return c.z * lerp(k.xxx, saturate(p - k.xxx), c.y);
}
float4 DecodeRGBAuint(uint value)
{
uint ai = value & 0x0000007F;
uint vi = (value / 0x00000080) & 0x000007FF;
uint si = (value / 0x00040000) & 0x0000007F;
uint hi = value / 0x02000000;
float h = float(hi) / 127.0;
float s = float(si) / 127.0;
float v = (float(vi) / 2047.0) * 10.0;
float a = ai * 2.0;
v = pow(v, 3.0);
float3 color = hsv2rgb(float3(h, s, v));
return float4(color.rgb, a);
}
[numthreads(16,16,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
for (int i = 0; i < Resolution; i++)
{
float4 result = float4(0,0,0,0);
result.rgba = DecodeRGBAuint(RG0[uint3(id.x, id.y, i)]);
result /= 1 + VoxelAA * 3;
result.rgb /= max(result.a, 2.0);
float blockerValue = 0.0;
if (result.a > 20.0)
{
blockerValue = max(0.0, result.a - 20.0);
}
result.a = min(result.a, 2.0) * 1.25;
result.a += blockerValue;
Result[uint3(id.xy, i)] = result;
}
}
[numthreads(16,16,1)]
void CSMain2 (uint3 id : SV_DispatchThreadID)
{
for (int i = 0; i < Resolution; i++)
{
float4 result = float4(0,0,0,0);
result.rgba = DecodeRGBAuint(RG0[uint3(id.x, id.y, i)]);
result.rgb /= max(2.0, result.a);
Result[uint3(id.xy, i)] = result;
}
}