Welcome to mirror list, hosted at ThFree Co, Russian Federation.

eevee_culling_debug_frag.glsl « shaders « eevee « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33734324445ca7cd0670a6a7820ff0cc023b134f (plain)
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

/**
 * Debug Shader outputing a gradient of orange - white - blue to mark culling hotspots.
 * Green pixels are error pixels that are missing lights from the culling pass (i.e: when culling
 * pass is not conservative enough).
 */

#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_culling_iter_lib.glsl)

layout(std430, binding = 0) readonly restrict buffer lights_buf
{
  LightData lights[];
};

layout(std430, binding = 1) readonly restrict buffer lights_zbins_buf
{
  CullingZBin lights_zbins[];
};

layout(std430, binding = 2) readonly restrict buffer lights_culling_buf
{
  CullingData light_culling;
};

layout(std430, binding = 3) readonly restrict buffer lights_tile_buf
{
  CullingWord lights_culling_words[];
};

uniform sampler2D depth_tx;

in vec4 uvcoordsvar;

layout(location = 0) out vec4 out_debug_color;

void main(void)
{
  float depth = texelFetch(depth_tx, ivec2(gl_FragCoord.xy), 0).r;
  float vP_z = get_view_z_from_depth(depth);

  vec3 P = get_world_space_from_depth(uvcoordsvar.xy, depth);

  float lights_count = 0.0;
  uint lights_cull = 0u;
  ITEM_FOREACH_BEGIN (light_culling, lights_zbins, lights_culling_words, vP_z, l_idx) {
    LightData light = lights[l_idx];
    lights_cull |= 1u << l_idx;
    lights_count += 1.0;
  }
  ITEM_FOREACH_END

  uint lights_nocull = 0u;
  ITEM_FOREACH_BEGIN_NO_CULL (light_culling, l_idx) {
    LightData light = lights[l_idx];
    if (distance(light._position, P) < light.influence_radius_max) {
      lights_nocull |= 1u << l_idx;
    }
  }
  ITEM_FOREACH_END

  if ((lights_cull & lights_nocull) != lights_nocull) {
    /* ERROR. Some lights were culled incorrectly. */
    out_debug_color = vec4(0.0, 1.0, 0.0, 1.0);
  }
  else {
    out_debug_color = vec4(heatmap_gradient(lights_count / 4.0), 1.0);
  }
}