-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathSEGIMipFilter_C.compute
79 lines (58 loc) · 1.91 KB
/
SEGIMipFilter_C.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
#pragma kernel CSMain
#pragma kernel CSMainGaussian
RWTexture3D<float4> Destination;
Texture3D<float4> Source;
SamplerState _LinearClamp;
SamplerState _PointClamp;
int destinationRes;
float4 ClipmapOverlap;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
for (uint i = 0; i < (uint)destinationRes / 2u; i++)
{
float3 fcoord = float3((float)id.x / destinationRes, (float)id.y / destinationRes, (float)i / destinationRes);
fcoord *= 2.0;
float texel = 1.0 / destinationRes;
float3 sampleCoord = (fcoord) * 1.0 - 0.0 + ClipmapOverlap.xyz * 0.0;
float4 tex = Source.SampleLevel(_LinearClamp, sampleCoord + texel * 1.0, 0.0);
tex.rgba *= 2.0;
float3 writeCoord = fcoord;
writeCoord = writeCoord * 0.5 + 0.25;
writeCoord += ClipmapOverlap.xyz * 1.0;
writeCoord *= destinationRes;
uint3 writeCoordi = uint3(writeCoord.x, writeCoord.y, writeCoord.z);
Destination[writeCoordi] = tex;
}
}
[numthreads(8,8,1)]
void CSMainGaussian (uint3 id : SV_DispatchThreadID)
{
float3 offsets[8] =
{
float3(1.0, 1.0, 1.0),
float3(1.0, 1.0, -1.0),
float3(1.0, -1.0, 1.0),
float3(1.0, -1.0, -1.0),
float3(-1.0, 1.0, 1.0),
float3(-1.0, 1.0, -1.0),
float3(-1.0, -1.0, 1.0),
float3(-1.0, -1.0, -1.0)
};
for (int i = 0; i < destinationRes; i++)
{
float3 fcoord = float3((float)id.x / destinationRes, (float)id.y / destinationRes, (float)i / destinationRes);
float texel = 1.0 / destinationRes;
float4 tex = float4(0,0,0,0);
int c = 0;
for (int j = 0; j < 8; j++)
{
float3 offset = float3(0, 0, 0);
offset = offsets[j];
tex += Source.SampleLevel(_LinearClamp, fcoord + texel * 0.5 + offset * texel * 0.5, 0.0);
c++;
}
tex /= c;
Destination[uint3(id.xy, i)] = tex;
}
}