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:
authorJeroen Bakker <jbakker>2020-05-22 15:11:03 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2020-05-22 15:11:36 +0300
commit59aed2a255f22f0cf91dbdf2e9daac179b9c2649 (patch)
treefb8ee5059aa8262b908daf776ea0bc424e12f139 /source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl
parent4066c921fbe5777271bebe1055bfd525f4c6dcfa (diff)
Fix T73726: Workbench Closest Interpolation Artifacts
All textures in workbench are using linear interpolation. The fragment shader modifies the uv coordinates to sample always in the center of a texel. In rare conditions the GPU could sample an incorrect value due to rounding errors making some rendering artifacts. This patch skips the interpolation in the fragment shader to remove these render artifacts. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D7816
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl')
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl24
1 files changed, 18 insertions, 6 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl
index 6f99739f259..e45f7a7b9e3 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_image_lib.glsl
@@ -24,11 +24,17 @@ bool node_tex_tile_lookup(inout vec3 co, sampler2DArray ima, sampler1DArray map)
vec4 workbench_sample_texture(sampler2D image, vec2 coord, bool nearest_sampling)
{
- vec2 tex_size = vec2(textureSize(image, 0).xy);
/* TODO(fclem) We could do the same with sampler objects.
* But this is a quick workaround instead of messing with the GPUTexture itself. */
- vec2 uv = nearest_sampling ? (floor(coord * tex_size) + 0.5) / tex_size : coord;
- return texture(image, uv);
+ if (nearest_sampling) {
+ /* Use texelFetch for nearest_sampling to reduce glitches. See: T73726 */
+ vec2 tex_size = vec2(textureSize(image, 0).xy);
+ ivec2 uv = ivec2(floor(coord * tex_size) + 0.5);
+ return texelFetch(image, uv, 0);
+ }
+ else {
+ return texture(image, coord);
+ }
}
vec4 workbench_sample_texture_array(sampler2DArray tile_array,
@@ -36,7 +42,6 @@ vec4 workbench_sample_texture_array(sampler2DArray tile_array,
vec2 coord,
bool nearest_sampling)
{
- vec2 tex_size = vec2(textureSize(tile_array, 0).xy);
vec3 uv = vec3(coord, 0);
if (!node_tex_tile_lookup(uv, tile_array, tile_data))
@@ -44,8 +49,15 @@ vec4 workbench_sample_texture_array(sampler2DArray tile_array,
/* TODO(fclem) We could do the same with sampler objects.
* But this is a quick workaround instead of messing with the GPUTexture itself. */
- uv.xy = nearest_sampling ? (floor(uv.xy * tex_size) + 0.5) / tex_size : uv.xy;
- return texture(tile_array, uv);
+ if (nearest_sampling) {
+ /* Use texelFetch for nearest_sampling to reduce glitches. See: T73726 */
+ vec3 tex_size = vec3(textureSize(tile_array, 0));
+ uv.xy = floor(uv.xy * tex_size.xy) + 0.5;
+ return texelFetch(tile_array, ivec3(uv), 0);
+ }
+ else {
+ return texture(tile_array, uv);
+ }
}
uniform sampler2DArray imageTileArray;