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

shadow_accum_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: 860ec9e1727139b5f205ea2fbce551dfe1bb6f3b (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

out vec4 fragColor;

#ifndef UTIL_TEX
#  define UTIL_TEX
uniform sampler2DArray utilTex;
#  define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
#endif /* UTIL_TEX */

void main()
{
  if (laNumLight == 0) {
    /* Early exit: No lights in scene */
    fragColor.r = 1.0;
    return;
  }

  ivec2 texel = ivec2(gl_FragCoord.xy);
  float depth = texelFetch(depthBuffer, texel, 0).r;
  if (depth == 1.0f) {
    /* Early exit background does not receive shadows */
    fragColor.r = 1.0;
    return;
  }

  vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
  vec2 uvs = saturate(gl_FragCoord.xy * texel_size);
  vec4 rand = texelfetch_noise_tex(texel);

  float accum_light = 0.0;
  float tracing_depth = depth;
  /* Constant bias (due to depth buffer precision) */
  /* Magic numbers for 24bits of precision.
   * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */
  tracing_depth -= mix(2.4e-7, 4.8e-7, depth);
  /* Convert to view Z. */
  tracing_depth = get_view_z_from_depth(tracing_depth);

  vec3 viewPosition = get_view_space_from_depth(uvs, depth);
  vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition);

  vec3 true_normal = normalize(cross(dFdx(viewPosition), dFdy(viewPosition)));

  for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) {
    LightData ld = lights_data[i];

    vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
    l_vector.xyz = ld.l_position - worldPosition;
    l_vector.w = length(l_vector.xyz);

    float l_vis = light_shadowing(
        ld, worldPosition, viewPosition, tracing_depth, true_normal, rand.x, true, 1.0);

    accum_light += l_vis;
  }

  fragColor.r = accum_light / float(laNumLight);
}