Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
| /** | /** | ||||
| * Shader that down-sample depth buffer, | * Shader that down-sample depth buffer, | ||||
| * saving min and max value of each texel in the above mipmaps. | * 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/ | * 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 | * Major simplification has been made since we pad the buffer to always be bigger than input to | ||||
| * avoid mipmapping misalignment. | * avoid mipmapping misalignment. | ||||
| */ | */ | ||||
| #ifdef LAYERED | #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 sampleLowerMip(t) texture(depthBuffer, vec3(t, depthLayer)).r | ||||
| # define gatherLowerMip(t) textureGather(depthBuffer, vec3(t, depthLayer)) | # define gatherLowerMip(t) textureGather(depthBuffer, vec3(t, depthLayer)) | ||||
| #else | #else | ||||
| # define sampleLowerMip(t) texture(depthBuffer, t).r | # define sampleLowerMip(t) texture(depthBuffer, t).r | ||||
| # define gatherLowerMip(t) textureGather(depthBuffer, t) | # define gatherLowerMip(t) textureGather(depthBuffer, t) | ||||
| #endif | #endif | ||||
| #ifdef MIN_PASS | #ifdef MIN_PASS | ||||
| # define minmax2(a, b) min(a, b) | # define minmax2(a, b) min(a, b) | ||||
| # define minmax3(a, b, c) min(min(a, b), c) | # define minmax3(a, b, c) min(min(a, b), c) | ||||
| # define minmax4(a, b, c, d) min(min(min(a, b), c), d) | # define minmax4(a, b, c, d) min(min(min(a, b), c), d) | ||||
| #else /* MAX_PASS */ | #else /* MAX_PASS */ | ||||
| # define minmax2(a, b) max(a, b) | # define minmax2(a, b) max(a, b) | ||||
| # define minmax3(a, b, c) max(max(a, b), c) | # define minmax3(a, b, c) max(max(a, b), c) | ||||
| # define minmax4(a, b, c, d) max(max(max(a, b), c), d) | # define minmax4(a, b, c, d) max(max(max(a, b), c), d) | ||||
| #endif | #endif | ||||
| /* On some AMD card / driver combination, it is needed otherwise, | |||||
| * the shader does not write anything. */ | |||||
| #if (defined(GPU_INTEL) || defined(GPU_ATI)) && defined(GPU_OPENGL) | |||||
| out vec4 fragColor; | |||||
| #endif | |||||
| void main() | void main() | ||||
| { | { | ||||
| vec2 texel = gl_FragCoord.xy; | vec2 texel = gl_FragCoord.xy; | ||||
| #ifdef COPY_DEPTH | #ifdef COPY_DEPTH | ||||
| vec2 uv = texel / vec2(textureSize(depthBuffer, 0).xy); | vec2 uv = texel / vec2(textureSize(depthBuffer, 0).xy); | ||||
| float val = sampleLowerMip(uv); | float val = sampleLowerMip(uv); | ||||
| Show All 29 Lines | |||||