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:
authorClément Foucault <foucault.clem@gmail.com>2022-09-02 19:13:54 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-09-02 19:13:54 +0300
commit07cf3ce92fa257a0cac5565ca1ff857834ce67ce (patch)
tree3d73216d1c2a12497423c62902815b0e775f0ea7
parent874e9cbab9fbd65220794cebc195e5e28786ad78 (diff)
Fix T100377: EEVEE: Regression 3.2 normalmap node broken
This was caused by un-wanted normalization. This is a requirement of the MikkTspace. The issue is that g_data.N is expected to be normalized by many other functions and overriden by bump displacement. Adding a new global variable containing the interpolated normal fixes the issue AND make it match cycles behavior better (mix between bump and interpolated normal).
-rw-r--r--source/blender/draw/engines/eevee/shaders/surface_lib.glsl5
-rw-r--r--source/blender/draw/engines/eevee_next/shaders/eevee_surf_lib.glsl3
-rw-r--r--source/blender/gpu/shaders/gpu_shader_codegen_lib.glsl4
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl6
4 files changed, 11 insertions, 7 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl
index 488e229bff7..b984a6df7b3 100644
--- a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl
@@ -98,10 +98,11 @@ GlobalData init_globals(void)
# if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
surf.P = transform_direction(ViewMatrixInverse, -viewCameraVec(viewPosition));
- surf.N = surf.Ng = -surf.P;
+ surf.N = surf.Ng = surf.Ni = -surf.P;
surf.ray_length = 0.0;
# else
surf.P = worldPosition;
+ surf.Ni = worldNormal;
surf.N = safe_normalize(worldNormal);
surf.Ng = safe_normalize(cross(dFdx(surf.P), dFdy(surf.P)));
surf.ray_length = distance(surf.P, cameraPos);
@@ -123,7 +124,7 @@ GlobalData init_globals(void)
cos_theta = hairThickTime / hairThickness;
}
float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
- surf.N = safe_normalize(worldNormal * sin_theta + B * cos_theta);
+ surf.N = surf.Ni = safe_normalize(worldNormal * sin_theta + B * cos_theta);
surf.curve_T = -hairTangent;
/* Costly, but follows cycles per pixel tangent space (not following curve shape). */
surf.curve_B = cross(V, surf.curve_T);
diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_surf_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_surf_lib.glsl
index 30b48edaa78..18e748596d5 100644
--- a/source/blender/draw/engines/eevee_next/shaders/eevee_surf_lib.glsl
+++ b/source/blender/draw/engines/eevee_next/shaders/eevee_surf_lib.glsl
@@ -40,7 +40,7 @@ void init_globals_curves()
/* Shade as a cylinder. */
float cos_theta = interp.curves_time_width / interp.curves_thickness;
float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
- g_data.N = normalize(interp.N * sin_theta + interp.curves_binormal * cos_theta);
+ g_data.N = g_data.Ni = normalize(interp.N * sin_theta + interp.curves_binormal * cos_theta);
/* Costly, but follows cycles per pixel tangent space (not following curve shape). */
vec3 V = cameraVec(g_data.P);
@@ -67,6 +67,7 @@ void init_globals()
{
/* Default values. */
g_data.P = interp.P;
+ g_data.Ni = interp.N;
g_data.N = safe_normalize(interp.N);
g_data.Ng = g_data.N;
g_data.is_strand = false;
diff --git a/source/blender/gpu/shaders/gpu_shader_codegen_lib.glsl b/source/blender/gpu/shaders/gpu_shader_codegen_lib.glsl
index 6091a5c834a..c0821085c8d 100644
--- a/source/blender/gpu/shaders/gpu_shader_codegen_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_codegen_lib.glsl
@@ -187,8 +187,10 @@ struct ClosureTransparency {
struct GlobalData {
/** World position. */
vec3 P;
- /** Surface Normal. */
+ /** Surface Normal. Normalized, overriden by bump displacement. */
vec3 N;
+ /** Raw interpolated normal (non-normalized) data. */
+ vec3 Ni;
/** Geometric Normal. */
vec3 Ng;
/** Curve Tangent Space. */
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
index a54dc59ddfe..3fc4992f7c4 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
@@ -3,13 +3,13 @@
void node_normal_map(vec4 tangent, vec3 texnormal, out vec3 outnormal)
{
if (all(equal(tangent, vec4(0.0, 0.0, 0.0, 1.0)))) {
- outnormal = g_data.N;
+ outnormal = g_data.Ni;
return;
}
tangent *= (FrontFacing ? 1.0 : -1.0);
- vec3 B = tangent.w * cross(g_data.N, tangent.xyz) * sign(ObjectInfo.w);
+ vec3 B = tangent.w * cross(g_data.Ni, tangent.xyz) * sign(ObjectInfo.w);
- outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * g_data.N;
+ outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * g_data.Ni;
outnormal = normalize(outnormal);
}
#endif