-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathSEGIMipFilter.compute
67 lines (49 loc) · 1.56 KB
/
SEGIMipFilter.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
#pragma kernel CSMain
#pragma kernel CSMainGaussian
RWTexture3D<float4> Destination;
Texture3D<float4> Source;
SamplerState _LinearClamp;
SamplerState _PointClamp;
int destinationRes;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
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 = Source.SampleLevel(_LinearClamp, fcoord + texel * 0.5, 0.0f);
Destination[uint3(id.xy, i)] = 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;
}
}