-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathresolve.cs
195 lines (149 loc) · 4.92 KB
/
resolve.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#version 450
#extension GL_ARB_gpu_shader_int64 : enable
#extension GL_NV_shader_atomic_int64 : enable
#extension GL_NV_gpu_shader5 : enable
#extension GL_KHR_shader_subgroup_basic : require
#extension GL_KHR_shader_subgroup_arithmetic : require
#extension GL_KHR_shader_subgroup_ballot : require
#extension GL_KHR_shader_subgroup_vote : require
#extension GL_KHR_shader_subgroup_clustered : require
layout(local_size_x = 16, local_size_y = 16) in;
layout(r32ui , binding = 0) coherent uniform uimage2D uOutput;
layout(std430, binding = 1) buffer abc_0 { uint64_t ssFramebuffer[]; };
layout(std430, binding = 44) buffer abc_1 { uint32_t ssRGBA[]; };
layout(std140, binding = 31) uniform UniformData{
mat4 world;
mat4 view;
mat4 proj;
mat4 transform;
mat4 transformFrustum;
int pointsPerThread;
int enableFrustumCulling;
int showBoundingBox;
int numPoints;
ivec2 imageSize;
bool colorizeChunks;
bool colorizeOverdraw;
} uniforms;
layout (std430, binding = 30) buffer abc_2 {
uint32_t value;
bool enabled;
uint32_t numPointsProcessed;
uint32_t numNodesProcessed;
uint32_t numPointsRendered;
uint32_t numNodesRendered;
uint32_t numPointsVisible;
} debug;
float getDepthAt(ivec2 pixelCoords, int window){
float closestDepth = 100000000.0;
for(int ox = -window; ox <= window; ox++){
for(int oy = -window; oy <= window; oy++){
int pixelID = (pixelCoords.x + ox) + (pixelCoords.y + oy) * uniforms.imageSize.x;
uint64_t data = ssFramebuffer[pixelID];
uint32_t uDepth = uint32_t(data >> 32l);
uint32_t pointID = uint32_t(data & 0xffffffffl);
float depth = uintBitsToFloat(uDepth);
if(depth > 0.0 && depth < closestDepth){
closestDepth = depth;
}
}
}
return closestDepth;
}
void main(){
uvec2 id = gl_LocalInvocationID.xy;
id.x += gl_WorkGroupSize.x * gl_WorkGroupID.x;
id.y += gl_WorkGroupSize.y * gl_WorkGroupID.y;
ivec2 imgSize = uniforms.imageSize;
// { // 1 pixel
// ivec2 pixelCoords = ivec2(id);
// ivec2 sourceCoords = ivec2(id);
// int pixelID = sourceCoords.x + sourceCoords.y * uniforms.imageSize.x;
// uint64_t data = ssFramebuffer[pixelID];
// uint32_t pointID = uint32_t(data & 0xFFFFFFFFul);
// bool isLodPoint = ((data & 0x80000000ul) != 0);
// bool isBackground = (data & 0xFFFFFFFFul) > 0xfffffff0u;
// uint color;
// if(isLodPoint){
// color = lodColor.data[pointID];
// // color = 0x0000ffFF;
// }else{
// // color = ssRGBA[pointID];
// color = pointID;
// }
// if(isBackground){
// color = 0x000000FF;
// }
// imageAtomicExchange(uOutput, pixelCoords, color);
// }
{ // n x n pixel
ivec2 pixelCoords = ivec2(id);
float R = 0;
float G = 0;
float B = 0;
float count = 0;
int window = 0;
int edlWindow = 1;
float closestDepth = 1000000.0;
uint32_t closestPointID = 0;
for(int ox = -window; ox <= window; ox++){
for(int oy = -window; oy <= window; oy++){
int pixelID = (pixelCoords.x + ox) + (pixelCoords.y + oy) * imgSize.x;
uint64_t data = ssFramebuffer[pixelID];
uint32_t uDepth = uint32_t(data >> 32l);
uint32_t pointID = uint32_t(data & 0xffffffffl);
float depth = uintBitsToFloat(uDepth);
if(depth > 0.0 && depth < closestDepth){
closestDepth = depth;
closestPointID = pointID;
}
}
}
uint32_t color = 0;
if(uniforms.colorizeChunks){
color = closestPointID;
}else{
color = ssRGBA[closestPointID];
}
if(closestPointID == 0){
color = 0x00443322;
}else{
if(debug.enabled){
atomicAdd(debug.numPointsVisible, 1);
}
}
if(false)
{ // EDL
int pixelID = (pixelCoords.x) + (pixelCoords.y) * imgSize.x;
uint64_t data = ssFramebuffer[pixelID];
uint32_t uDepth = uint32_t(data >> 32l);
uint32_t pointID = uint32_t(data & 0xffffffffl);
float depth = uintBitsToFloat(uDepth);
float sum = 0.0;
for(int ox = -edlWindow; ox <= edlWindow; ox++){
for(int oy = -edlWindow; oy <= edlWindow; oy++){
int pixelID = (pixelCoords.x + ox) + (pixelCoords.y + oy) * imgSize.x;
// uint64_t data = ssFramebuffer[pixelID];
// uint32_t uDepth = uint32_t(data >> 32l);
// uint32_t pointID = uint32_t(data & 0xffffffffl);
// float neighbourDepth = uintBitsToFloat(uDepth);
float neighbourDepth = getDepthAt(pixelCoords + ivec2(ox, oy), window);
sum += max(0.0, depth - neighbourDepth);
}
}
float edlStrength = 0.0005;
float response = sum / 9.0;
float shade = exp(-response * 300.0 * edlStrength);
// shade = 1.0;
uint R = ((color >> 0) & 0xFF);
uint G = ((color >> 8) & 0xFF);
uint B = ((color >> 16) & 0xFF);
R = uint(float(R) * shade);
G = uint(float(G) * shade);
B = uint(float(B) * shade);
color = R | (G << 8) | (B << 16);
// color = uint(255.0 * shade);
}
imageAtomicExchange(uOutput, pixelCoords, color);
}
}