diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-08-12 17:13:08 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-08-12 17:16:43 +0300 |
commit | b858b44f2e151a8ccf417a0207d039a07f449d29 (patch) | |
tree | 66123371cfd82917c52d4874ffcad6dc19c02a9b | |
parent | 76d0ab9750b04971fe7598011609faea2b4f7f62 (diff) |
Eevee: Fix and opimize MinMaxZ generation.
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_effects.c | 3 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_engine.c | 3 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl | 43 |
3 files changed, 24 insertions, 25 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_effects.c b/source/blender/draw/engines/eevee/eevee_effects.c index bf45227d793..2922e4622ad 100644 --- a/source/blender/draw/engines/eevee/eevee_effects.c +++ b/source/blender/draw/engines/eevee/eevee_effects.c @@ -992,13 +992,13 @@ void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int l EEVEE_TextureList *txl = vedata->txl; e_data.depth_src = depth_src; + e_data.depth_src_layer = layer; DRW_stats_group_start("Min buffer"); /* Copy depth buffer to min texture top level */ DRW_framebuffer_texture_attach(fbl->downsample_fb, stl->g_data->minzbuffer, 0, 0); DRW_framebuffer_bind(fbl->downsample_fb); if (layer >= 0) { - e_data.depth_src_layer = layer; DRW_draw_pass(psl->minz_downdepth_layer_ps); } else { @@ -1015,7 +1015,6 @@ void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int l DRW_framebuffer_texture_attach(fbl->downsample_fb, txl->maxzbuffer, 0, 0); DRW_framebuffer_bind(fbl->downsample_fb); if (layer >= 0) { - e_data.depth_src_layer = layer; DRW_draw_pass(psl->maxz_downdepth_layer_ps); } else { diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index d2fcc066e9c..14791952560 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -171,8 +171,6 @@ static void EEVEE_draw_scene(void *vedata) DRW_draw_pass(psl->depth_pass_cull); DRW_stats_group_end(); - DRW_draw_pass(psl->background_pass); - /* Create minmax texture */ DRW_stats_group_start("Main MinMax buffer"); EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1); @@ -183,6 +181,7 @@ static void EEVEE_draw_scene(void *vedata) /* Shading pass */ DRW_stats_group_start("Shading"); + DRW_draw_pass(psl->background_pass); EEVEE_draw_default_passes(psl); DRW_draw_pass(psl->material_pass); DRW_stats_group_end(); 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 3d580d0ce39..71e249e1599 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl @@ -11,23 +11,17 @@ uniform int depthLayer; uniform sampler2D depthBuffer; #endif -float sampleLowerMip(ivec2 texel) -{ #ifdef LAYERED - return texelFetch(depthBuffer, ivec3(texel, depthLayer), 0).r; +#define sampleLowerMip(t) texelFetch(depthBuffer, ivec3(t, depthLayer), 0).r #else - return texelFetch(depthBuffer, texel, 0).r; +#define sampleLowerMip(t) texelFetch(depthBuffer, t, 0).r #endif -} -void minmax(inout float out_val, float in_val) -{ #ifdef MIN_PASS - out_val = min(out_val, in_val); +#define minmax(a, b) min(a, b) #else /* MAX_PASS */ - out_val = max(out_val, in_val); +#define minmax(a, b) max(a, b) #endif -} void main() { @@ -40,23 +34,30 @@ void main() float val = sampleLowerMip(texelPos); #ifndef COPY_DEPTH - minmax(val, sampleLowerMip(texelPos + ivec2(1, 0))); - minmax(val, sampleLowerMip(texelPos + ivec2(1, 1))); - minmax(val, sampleLowerMip(texelPos + ivec2(0, 1))); + float val2 = sampleLowerMip(texelPos + ivec2(1, 0)); + float val3 = sampleLowerMip(texelPos + ivec2(1, 1)); + float val4 = sampleLowerMip(texelPos + ivec2(0, 1)); + val = minmax(val, val2); + val = minmax(val, val3); + val = minmax(val, val4); /* if we are reducing an odd-width texture then fetch the edge texels */ - if (((mipsize.x & 1) != 0) && (int(gl_FragCoord.x) == mipsize.x-3)) { + if (((mipsize.x & 1) != 0) && (int(gl_FragCoord.x)*2 == mipsize.x-3)) { /* if both edges are odd, fetch the top-left corner texel */ - if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y) == mipsize.y-3)) { - minmax(val, sampleLowerMip(texelPos + ivec2(-1, -1))); + if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y)*2 == mipsize.y-3)) { + val = minmax(val, sampleLowerMip(texelPos + ivec2(2, 2))); } - minmax(val, sampleLowerMip(texelPos + ivec2(0, -1))); - minmax(val, sampleLowerMip(texelPos + ivec2(1, -1))); + float val2 = sampleLowerMip(texelPos + ivec2(2, 0)); + float val3 = sampleLowerMip(texelPos + ivec2(2, 1)); + val = minmax(val, val2); + val = minmax(val, val3); } /* if we are reducing an odd-height texture then fetch the edge texels */ - else if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y) == mipsize.y-3)) { - minmax(val, sampleLowerMip(texelPos + ivec2(0, -1))); - minmax(val, sampleLowerMip(texelPos + ivec2(1, -1))); + if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y)*2 == mipsize.y-3)) { + float val2 = sampleLowerMip(texelPos + ivec2(0, 2)); + float val3 = sampleLowerMip(texelPos + ivec2(1, 2)); + val = minmax(val, val2); + val = minmax(val, val3); } #endif |