LumixEngine/data/pipelines/debug_clusters.shd
2020-05-30 13:28:57 +02:00

58 lines
No EOL
1.5 KiB
Text

include "pipelines/common.glsl"
vertex_shader [[
layout (location = 0) out vec2 v_uv;
void main() {
vec4 pos = fullscreenQuad(gl_VertexID, v_uv);
pos.xy = pos.xy;
pos.y = -pos.y;
gl_Position = pos;
}
]]
fragment_shader [[
layout (binding=0) uniform sampler2D u_texture;
layout (location = 0) in vec2 v_uv;
layout (location = 0) out vec4 o_color;
void main() {
#ifdef ORIGIN_BOTTOM_LEFT
vec4 t = textureLod(u_texture, v_uv, 0);
#else
vec4 t = textureLod(u_texture, vec2(v_uv.x, -v_uv.y), 0);
#endif
vec2 screen_uv = gl_FragCoord.xy / u_framebuffer_size;
float ndc_depth;
vec3 wpos = getViewPosition(u_texture, u_camera_inv_view_projection, screen_uv, ndc_depth);
ivec3 cluster;
int cluster_idx = getClusterIndex(ndc_depth, cluster);
#if 1
// debug number of lights per cluster
int c = b_clusters[cluster_idx].lights_count;
if (c < 10)
o_color.rgb = vec3(0, 0, c / 10.0);
else if (c < 50)
o_color.rgb = vec3(0, (c - 10) / 40.0, 0);
else
o_color.rgb = vec3((c - 50) / 200.0, 0, 0);
#elif 1
// debug number of probes per cluster
int c = b_clusters[cluster_idx].probes_count;
if (c < 10)
o_color.rgb = vec3(0, 0, c / 10.0);
else if (c < 50)
o_color.rgb = vec3(0, (c - 10) / 40.0, 0);
else
o_color.rgb = vec3((c - 50) / 200.0, 0, 0);
#else
// debug z binning
int mask = 1 << (cluster.z % 3);
o_color.rgb = vec3(mask >> 2, (mask >> 1) & 1, mask & 1);
#endif
o_color.a = 1;
}
]]