[Bf-blender-cvs] [f0d6879f5c7] master: Fix T62892 EEVEE HDRI lightning glitch

Clément Foucault noreply at git.blender.org
Fri Apr 5 14:21:20 CEST 2019


Commit: f0d6879f5c7998be98ac406bd6ddaa5104961206
Author: Clément Foucault
Date:   Fri Apr 5 14:37:38 2019 +0200
Branches: master
https://developer.blender.org/rBf0d6879f5c7998be98ac406bd6ddaa5104961206

Fix T62892 EEVEE HDRI lightning glitch

Clamp the texture at sampling time. This is not the best way to do it but
this is the fastest/simplest. The cost is rather negligeable.

===================================================================

M	source/blender/gpu/shaders/gpu_shader_material.glsl

===================================================================

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 5f54b53987e..9f3ea4acfb1 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2081,22 +2081,25 @@ void node_tex_environment_empty(vec3 co, out vec4 color)
 	color = vec4(1.0, 0.0, 1.0, 1.0);
 }
 
+/* 16bits floats limits. Higher/Lower values produce +/-inf. */
+#define safe_color(a) (clamp(a, -65520.0, 65520.0))
+
 void node_tex_image_linear(vec3 co, sampler2D ima, out vec4 color, out float alpha)
 {
-	color = texture(ima, co.xy);
+	color = safe_color(texture(ima, co.xy));
 	alpha = color.a;
 }
 
 void node_tex_image_linear_no_mip(vec3 co, sampler2D ima, out vec4 color, out float alpha)
 {
-	color = textureLod(ima, co.xy, 0.0);
+	color = safe_color(textureLod(ima, co.xy, 0.0));
 	alpha = color.a;
 }
 
 void node_tex_image_nearest(vec3 co, sampler2D ima, out vec4 color, out float alpha)
 {
 	ivec2 pix = ivec2(fract(co.xy) * textureSize(ima, 0).xy);
-	color = texelFetch(ima, pix, 0);
+	color = clamp(texelFetch(ima, pix, 0));
 	alpha = color.a;
 }
 
@@ -2138,10 +2141,10 @@ void node_tex_image_cubic_ex(vec3 co, sampler2D ima, float do_extend, out vec4 c
 	}
 	final_co /= tex_size.xyxy;
 
-	color  = textureLod(ima, final_co.xy, 0.0) * s0.x * s0.y;
-	color += textureLod(ima, final_co.zy, 0.0) * s1.x * s0.y;
-	color += textureLod(ima, final_co.xw, 0.0) * s0.x * s1.y;
-	color += textureLod(ima, final_co.zw, 0.0) * s1.x * s1.y;
+	color  = safe_color(textureLod(ima, final_co.xy, 0.0)) * s0.x * s0.y;
+	color += safe_color(textureLod(ima, final_co.zy, 0.0)) * s1.x * s0.y;
+	color += safe_color(textureLod(ima, final_co.xw, 0.0)) * s0.x * s1.y;
+	color += safe_color(textureLod(ima, final_co.zw, 0.0)) * s1.x * s1.y;
 
 #else /* Reference bruteforce 16 tap. */
 	color  = texelFetch(ima, ivec2(tc + vec2(-1.0, -1.0)), 0) * w0.x * w0.y;



More information about the Bf-blender-cvs mailing list