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

eevee_depth_of_field_scatter_frag.glsl « shaders « eevee_next « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cfb7fd2568bd7b6777017f1e36a225fef07b35f9 (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

/**
 * Scatter pass: Use sprites to scatter the color of very bright pixel to have higher quality blur.
 *
 * We only scatter one quad per sprite and one sprite per 4 pixels to reduce vertex shader
 * invocations and overdraw.
 */

#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)

#define linearstep(p0, p1, v) (clamp(((v) - (p0)) / abs((p1) - (p0)), 0.0, 1.0))

void main()
{
  vec4 coc4 = vec4(interp.color_and_coc1.w,
                   interp.color_and_coc2.w,
                   interp.color_and_coc3.w,
                   interp.color_and_coc4.w);
  vec4 shapes;
  if (use_bokeh_lut) {
    shapes = vec4(texture(bokeh_lut_tx, interp.rect_uv1).r,
                  texture(bokeh_lut_tx, interp.rect_uv2).r,
                  texture(bokeh_lut_tx, interp.rect_uv3).r,
                  texture(bokeh_lut_tx, interp.rect_uv4).r);
  }
  else {
    shapes = vec4(length(interp.rect_uv1),
                  length(interp.rect_uv2),
                  length(interp.rect_uv3),
                  length(interp.rect_uv4));
  }
  shapes *= interp.distance_scale;
  /* Becomes signed distance field in pixel units. */
  shapes -= coc4;
  /* Smooth the edges a bit to fade out the undersampling artifacts. */
  shapes = saturate(1.0 - linearstep(-0.8, 0.8, shapes));
  /* Outside of bokeh shape. Try to avoid overloading ROPs. */
  if (max_v4(shapes) == 0.0) {
    discard;
  }

  if (!no_scatter_occlusion) {
    /* Works because target is the same size as occlusion_tx. */
    vec2 uv = gl_FragCoord.xy / vec2(textureSize(occlusion_tx, 0).xy);
    vec2 occlusion_data = texture(occlusion_tx, uv).rg;
    /* Fix tilling artifacts. (Slide 90) */
    const float correction_fac = 1.0 - DOF_FAST_GATHER_COC_ERROR;
    /* Occlude the sprite with geometry from the same field using a chebychev test (slide 85). */
    float mean = occlusion_data.x;
    float variance = occlusion_data.y;
    shapes *= variance * safe_rcp(variance + sqr(max(coc4 * correction_fac - mean, 0.0)));
  }

  out_color = (interp.color_and_coc1 * shapes[0] + interp.color_and_coc2 * shapes[1] +
               interp.color_and_coc3 * shapes[2] + interp.color_and_coc4 * shapes[3]);
  /* Do not accumulate alpha. This has already been accumulated by the gather pass. */
  out_color.a = 0.0;

  if (debug_scatter_perf) {
    out_color.rgb = avg(out_color.rgb) * vec3(1.0, 0.0, 0.0);
  }
}