diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-15 00:03:07 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-15 00:05:52 +0300 |
commit | 7710de26d0d768734977769af4a278b262f4da51 (patch) | |
tree | bc5b97b853528b10d75f90f4afedf5c07363a914 /source/blender | |
parent | f7829787da5c64b3fa715a042c2a45ecd4314676 (diff) |
Workbench: Depth Of Field: Fix undefined behavior with using texelFetch
On MacOS + Intel Iris Graphics 6100 (may affect other config too), the
texelFetch operation bypass the base mip setting of the texture object.
Using textureLod with lod = 0.0 ensure the lowest (after clamping) mip will
always be selected.
Also disable the texture filtering for this sampler to avoid unecessary
fetches.
This should fix T78653 Blender 2.83 broken Depth of Field in Viewport
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl | 22 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_effect_dof.c | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl index 899ada852f9..c1c1c264f42 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl @@ -108,18 +108,22 @@ layout(location = 1) out vec2 outCocs; void main() { - ivec4 texel = ivec4(gl_FragCoord.xyxy) * 2 + ivec4(0, 0, 1, 1); + vec4 texel = vec4(gl_FragCoord.xyxy) * 2 + vec4(0, 0, 1, 1); + texel = (texel + 0.5) / vec4(textureSize(sceneColorTex, 0).xyxy); - vec4 color1 = texelFetch(sceneColorTex, texel.xy, 0); - vec4 color2 = texelFetch(sceneColorTex, texel.zw, 0); - vec4 color3 = texelFetch(sceneColorTex, texel.zy, 0); - vec4 color4 = texelFetch(sceneColorTex, texel.xw, 0); + /* Using texelFetch can bypass the mip range setting on some platform. + * Using texture Lod fix this issue. Note that we need to disable filtering to get the right + * texel values. */ + vec4 color1 = textureLod(sceneColorTex, texel.xy, 0.0); + vec4 color2 = textureLod(sceneColorTex, texel.zw, 0.0); + vec4 color3 = textureLod(sceneColorTex, texel.zy, 0.0); + vec4 color4 = textureLod(sceneColorTex, texel.xw, 0.0); vec4 depths; - vec2 cocs1 = texelFetch(inputCocTex, texel.xy, 0).rg; - vec2 cocs2 = texelFetch(inputCocTex, texel.zw, 0).rg; - vec2 cocs3 = texelFetch(inputCocTex, texel.zy, 0).rg; - vec2 cocs4 = texelFetch(inputCocTex, texel.xw, 0).rg; + vec2 cocs1 = textureLod(inputCocTex, texel.xy, 0.0).rg; + vec2 cocs2 = textureLod(inputCocTex, texel.zw, 0.0).rg; + vec2 cocs3 = textureLod(inputCocTex, texel.zy, 0.0).rg; + vec2 cocs4 = textureLod(inputCocTex, texel.xw, 0.0).rg; vec4 cocs_near = vec4(cocs1.r, cocs2.r, cocs3.r, cocs4.r) * MAX_COC_SIZE; vec4 cocs_far = vec4(cocs1.g, cocs2.g, cocs3.g, cocs4.g) * MAX_COC_SIZE; diff --git a/source/blender/draw/engines/workbench/workbench_effect_dof.c b/source/blender/draw/engines/workbench/workbench_effect_dof.c index abbca0988d4..f8223945a31 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_dof.c +++ b/source/blender/draw/engines/workbench/workbench_effect_dof.c @@ -286,7 +286,7 @@ void workbench_dof_cache_init(WORKBENCH_Data *vedata) psl->dof_down2_ps = DRW_pass_create("DoF DownSample", DRW_STATE_WRITE_COLOR); DRWShadingGroup *grp = DRW_shgroup_create(downsample_sh, psl->dof_down2_ps); - DRW_shgroup_uniform_texture(grp, "sceneColorTex", txl->dof_source_tx); + DRW_shgroup_uniform_texture_ex(grp, "sceneColorTex", txl->dof_source_tx, GPU_SAMPLER_DEFAULT); DRW_shgroup_uniform_texture(grp, "inputCocTex", txl->coc_halfres_tx); DRW_shgroup_call_procedural_triangles(grp, NULL, 1); } |