Debian Codegraph @

servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl

raw
1 #[vertex]
2
3 #version 450
4
5 #VERSION_DEFINES
6
7 struct CellData {
8 uint position; // xyz 10 bits
9 uint albedo; //rgb albedo
10 uint emission; //rgb normalized with e as multiplier
11 uint normal; //RGB normal encoded
12 };
13
14 layout(set = 0, binding = 1, std140) buffer CellDataBuffer {
15 CellData data[];
16 }
17 cell_data;
18
19 layout(set = 0, binding = 2) uniform texture3D color_tex;
20
21 layout(set = 0, binding = 3) uniform sampler tex_sampler;
22
23 layout(push_constant, std430) uniform Params {
24 mat4 projection;
25 uint cell_offset;
26 float dynamic_range;
27 float alpha;
28 uint level;
29 ivec3 bounds;
30 uint pad;
31 }
32 params;
33
34 layout(location = 0) out vec4 color_interp;
35
36 void main() {
37 const vec3 cube_triangles[36] = vec3[](
38 vec3(-1.0f, -1.0f, -1.0f),
39 vec3(-1.0f, -1.0f, 1.0f),
40 vec3(-1.0f, 1.0f, 1.0f),
41 vec3(1.0f, 1.0f, -1.0f),
42 vec3(-1.0f, -1.0f, -1.0f),
43 vec3(-1.0f, 1.0f, -1.0f),
44 vec3(1.0f, -1.0f, 1.0f),
45 vec3(-1.0f, -1.0f, -1.0f),
46 vec3(1.0f, -1.0f, -1.0f),
47 vec3(1.0f, 1.0f, -1.0f),
48 vec3(1.0f, -1.0f, -1.0f),
49 vec3(-1.0f, -1.0f, -1.0f),
50 vec3(-1.0f, -1.0f, -1.0f),
51 vec3(-1.0f, 1.0f, 1.0f),
52 vec3(-1.0f, 1.0f, -1.0f),
53 vec3(1.0f, -1.0f, 1.0f),
54 vec3(-1.0f, -1.0f, 1.0f),
55 vec3(-1.0f, -1.0f, -1.0f),
56 vec3(-1.0f, 1.0f, 1.0f),
57 vec3(-1.0f, -1.0f, 1.0f),
58 vec3(1.0f, -1.0f, 1.0f),
59 vec3(1.0f, 1.0f, 1.0f),
60 vec3(1.0f, -1.0f, -1.0f),
61 vec3(1.0f, 1.0f, -1.0f),
62 vec3(1.0f, -1.0f, -1.0f),
63 vec3(1.0f, 1.0f, 1.0f),
64 vec3(1.0f, -1.0f, 1.0f),
65 vec3(1.0f, 1.0f, 1.0f),
66 vec3(1.0f, 1.0f, -1.0f),
67 vec3(-1.0f, 1.0f, -1.0f),
68 vec3(1.0f, 1.0f, 1.0f),
69 vec3(-1.0f, 1.0f, -1.0f),
70 vec3(-1.0f, 1.0f, 1.0f),
71 vec3(1.0f, 1.0f, 1.0f),
72 vec3(-1.0f, 1.0f, 1.0f),
73 vec3(1.0f, -1.0f, 1.0f));
74
75 vec3 vertex = cube_triangles[gl_VertexIndex] * 0.5 + 0.5;
76 #ifdef MODE_DEBUG_LIGHT_FULL
77 uvec3 posu = uvec3(gl_InstanceIndex % params.bounds.x, (gl_InstanceIndex / params.bounds.x) % params.bounds.y, gl_InstanceIndex / (params.bounds.y * params.bounds.x));
78 #else
79 uint cell_index = gl_InstanceIndex + params.cell_offset;
80
81 uvec3 posu = uvec3(cell_data.data[cell_index].position & 0x7FF, (cell_data.data[cell_index].position >> 11) & 0x3FF, cell_data.data[cell_index].position >> 21);
82 #endif
83
84 #ifdef MODE_DEBUG_EMISSION
85 color_interp.xyz = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff, (cell_data.data[cell_index].emission >> 9) & 0x1ff, (cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0);
86 #endif
87
88 #ifdef MODE_DEBUG_COLOR
89 color_interp.xyz = unpackUnorm4x8(cell_data.data[cell_index].albedo).xyz;
90 #endif
91
92 #ifdef MODE_DEBUG_LIGHT
93 color_interp = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level));
94 color_interp.xyz *params.dynamic_range;
95 #endif
96
97 float scale = (1 << params.level);
98
99 gl_Position = params.projection * vec4((vec3(posu) + vertex) * scale, 1.0);
100
101 #ifdef MODE_DEBUG_LIGHT_FULL
102 if (color_interp.a == 0.0) {
103 gl_Position = vec4(0.0); //force clip and not draw
104 }
105 #else
106 color_interp.a = params.alpha;
107 #endif
108 }
109
110 #[fragment]
111
112 #version 450
113
114 #VERSION_DEFINES
115
116 layout(location = 0) in vec4 color_interp;
117 layout(location = 0) out vec4 frag_color;
118
119 void main() {
120 frag_color = color_interp;
121
122 #ifdef MODE_DEBUG_LIGHT_FULL
123
124 //there really is no alpha, so use dither
125
126 int x = int(gl_FragCoord.x) % 4;
127 int y = int(gl_FragCoord.y) % 4;
128 int index = x + y * 4;
129 float limit = 0.0;
130 if (x < 8) {
131 if (index == 0) {
132 limit = 0.0625;
133 }
134 if (index == 1) {
135 limit = 0.5625;
136 }
137 if (index == 2) {
138 limit = 0.1875;
139 }
140 if (index == 3) {
141 limit = 0.6875;
142 }
143 if (index == 4) {
144 limit = 0.8125;
145 }
146 if (index == 5) {
147 limit = 0.3125;
148 }
149 if (index == 6) {
150 limit = 0.9375;
151 }
152 if (index == 7) {
153 limit = 0.4375;
154 }
155 if (index == 8) {
156 limit = 0.25;
157 }
158 if (index == 9) {
159 limit = 0.75;
160 }
161 if (index == 10) {
162 limit = 0.125;
163 }
164 if (index == 11) {
165 limit = 0.625;
166 }
167 if (index == 12) {
168 limit = 1.0;
169 }
170 if (index == 13) {
171 limit = 0.5;
172 }
173 if (index == 14) {
174 limit = 0.875;
175 }
176 if (index == 15) {
177 limit = 0.375;
178 }
179 }
180 if (frag_color.a < limit) {
181 discard;
182 }
183 #endif
184 }