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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2021-03-04 13:59:49 +0300
committerClément Foucault <foucault.clem@gmail.com>2021-03-08 19:25:16 +0300
commitba75ea8012084aa84ba8c9ac088b88a8dcf4fb21 (patch)
tree32610751177961885185afee8f4c4773ccda4ced /source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
parent6afe2d373a00a49a7a51cafec50d03ada0fe0743 (diff)
EEVEE: Use Fullscreen maxZBuffer instead of halfres
This removes the need for per mipmap scalling factor and trilinear interpolation issues. We pad the texture so that all mipmaps have pixels in the next mip. This simplifies the downsampling shader too. This also change the SSR radiance buffer as well in the same fashion.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl58
1 files changed, 17 insertions, 41 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
index b99037b1e80..ccb65d2e5a6 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
@@ -2,6 +2,9 @@
* 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 misalignement.
*/
#ifdef LAYERED
@@ -12,10 +15,10 @@ uniform sampler2D depthBuffer;
#endif
#ifdef LAYERED
-# define sampleLowerMip(t) texelFetch(depthBuffer, ivec3(t, depthLayer), 0).r
+# define sampleLowerMip(t) texture(depthBuffer, vec3(t, depthLayer)).r
# define gatherLowerMip(t) textureGather(depthBuffer, vec3(t, depthLayer))
#else
-# define sampleLowerMip(t) texelFetch(depthBuffer, t, 0).r
+# define sampleLowerMip(t) texture(depthBuffer, t).r
# define gatherLowerMip(t) textureGather(depthBuffer, t)
#endif
@@ -37,54 +40,27 @@ out vec4 fragColor;
void main()
{
- ivec2 texelPos = ivec2(gl_FragCoord.xy);
- ivec2 mipsize = textureSize(depthBuffer, 0).xy;
-
-#ifndef COPY_DEPTH
- texelPos *= 2;
-#endif
+ vec2 texel = gl_FragCoord.xy;
+ vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0).xy);
#ifdef COPY_DEPTH
- float val = sampleLowerMip(texelPos);
+ vec2 uv = texel * texel_size;
+
+ float val = sampleLowerMip(uv);
#else
+ vec2 uv = texel * 2.0 * texel_size;
+
vec4 samp;
# ifdef GPU_ARB_texture_gather
- /* + 1.0 to gather at the center of target 4 texels. */
- samp = gatherLowerMip((vec2(texelPos) + 1.0) / vec2(mipsize));
+ samp = gatherLowerMip(uv);
# else
- samp.x = sampleLowerMip(texelPos);
- samp.y = sampleLowerMip(texelPos + ivec2(1, 0));
- samp.z = sampleLowerMip(texelPos + ivec2(1, 1));
- samp.w = sampleLowerMip(texelPos + ivec2(0, 1));
+ samp.x = sampleLowerMip(uv + vec2(-0.5, -0.5) * texel_size);
+ samp.y = sampleLowerMip(uv + vec2(-0.5, 0.5) * texel_size);
+ samp.z = sampleLowerMip(uv + vec2(0.5, -0.5) * texel_size);
+ samp.w = sampleLowerMip(uv + vec2(0.5, 0.5) * texel_size);
# endif
float val = minmax4(samp.x, samp.y, samp.z, samp.w);
-
- /* if we are reducing an odd-width texture then fetch the edge texels */
- if (((mipsize.x & 1) != 0) && (texelPos.x == mipsize.x - 3)) {
- /* if both edges are odd, fetch the top-left corner texel */
- if (((mipsize.y & 1) != 0) && (texelPos.y == mipsize.y - 3)) {
- samp.x = sampleLowerMip(texelPos + ivec2(2, 2));
- val = minmax2(val, samp.x);
- }
-# ifdef GPU_ARB_texture_gather
- samp = gatherLowerMip((vec2(texelPos) + vec2(2.0, 1.0)) / vec2(mipsize));
-# else
- samp.y = sampleLowerMip(texelPos + ivec2(2, 0));
- samp.z = sampleLowerMip(texelPos + ivec2(2, 1));
-# endif
- val = minmax3(val, samp.y, samp.z);
- }
- /* if we are reducing an odd-height texture then fetch the edge texels */
- if (((mipsize.y & 1) != 0) && (texelPos.y == mipsize.y - 3)) {
-# ifdef GPU_ARB_texture_gather
- samp = gatherLowerMip((vec2(texelPos) + vec2(1.0, 2.0)) / vec2(mipsize));
-# else
- samp.x = sampleLowerMip(texelPos + ivec2(0, 2));
- samp.y = sampleLowerMip(texelPos + ivec2(1, 2));
-# endif
- val = minmax3(val, samp.x, samp.y);
- }
#endif
#if defined(GPU_INTEL) || defined(GPU_ATI)