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

effect_minmaxz_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: ce455123987431cb639fc267460ca28b972819bf (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
72
73
74
75
76
/**
 * Shader that down-sample depth buffer,
 * saving min and max value of each texel in the above mipmaps.
 * Adapted from http://rastergrid.com/blog/2010/10/hierarchical-z-map-based-occlusion-culling/
 *
 * Major simplification has been made since we pad the buffer to always be bigger than input to
 * avoid mipmapping misalignment.
 */

#ifdef LAYERED
uniform sampler2DArray depthBuffer;
uniform int depthLayer;
#else
uniform sampler2D depthBuffer;
#endif

#ifndef COPY_DEPTH
uniform vec2 texelSize;
#endif

#ifdef LAYERED
#  define sampleLowerMip(t) texture(depthBuffer, vec3(t, depthLayer)).r
#  define gatherLowerMip(t) textureGather(depthBuffer, vec3(t, depthLayer))
#else
#  define sampleLowerMip(t) texture(depthBuffer, t).r
#  define gatherLowerMip(t) textureGather(depthBuffer, t)
#endif

#ifdef MIN_PASS
#  define minmax2(a, b) min(a, b)
#  define minmax3(a, b, c) min(min(a, b), c)
#  define minmax4(a, b, c, d) min(min(min(a, b), c), d)
#else /* MAX_PASS */
#  define minmax2(a, b) max(a, b)
#  define minmax3(a, b, c) max(max(a, b), c)
#  define minmax4(a, b, c, d) max(max(max(a, b), c), d)
#endif

/* On some AMD card / driver combination, it is needed otherwise,
 * the shader does not write anything. */
#if defined(GPU_INTEL) || defined(GPU_ATI)
out vec4 fragColor;
#endif

void main()
{
  vec2 texel = gl_FragCoord.xy;

#ifdef COPY_DEPTH
  vec2 uv = texel / vec2(textureSize(depthBuffer, 0).xy);

  float val = sampleLowerMip(uv);
#else
  /* NOTE(@fclem): textureSize() does not work the same on all implementations
   * when changing the min and max texture levels. Use uniform instead (see T87801). */
  vec2 uv = texel * 2.0 * texelSize;

  vec4 samp;
#  ifdef GPU_ARB_texture_gather
  samp = gatherLowerMip(uv);
#  else
  samp.x = sampleLowerMip(uv + vec2(-0.5, -0.5) * texelSize);
  samp.y = sampleLowerMip(uv + vec2(-0.5, 0.5) * texelSize);
  samp.z = sampleLowerMip(uv + vec2(0.5, -0.5) * texelSize);
  samp.w = sampleLowerMip(uv + vec2(0.5, 0.5) * texelSize);
#  endif

  float val = minmax4(samp.x, samp.y, samp.z, samp.w);
#endif

#if defined(GPU_INTEL) || defined(GPU_ATI)
  /* Use color format instead of 24bit depth texture */
  fragColor = vec4(val);
#endif
  gl_FragDepth = val;
}