Fix T52001: material draw mode principled BSDF artifacts at some angles.

The default anisotropic tangent computation could fail in some cases,
leading to NaNs and artifacts. Use a simpler formulation that doesn't
suffer from this.
This commit is contained in:
Brecht Van Lommel 2017-07-08 23:37:16 +02:00
parent 0584c5ba8e
commit ba256b32ee
Notes: blender-bot 2023-02-14 06:48:47 +01:00
Referenced by issue #52013, Differences between CPU and GPU with this Volumetric World Texture
Referenced by issue #52001, Artifacts with Principled BSDF in Material view - master
1 changed files with 5 additions and 8 deletions

View File

@ -2636,14 +2636,11 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad
vec3 Tangent = T;
if (T == vec3(0.0)) {
// if no tangent is set, use a default tangent
Tangent = vec3(1.0, 0.0, 0.0);
if (N.x != 0.0 || N.y != 0.0) {
vec3 N_xz = normalize(vec3(N.x, 0.0, N.z));
vec3 axis = normalize(cross(vec3(0.0, 0.0, 1.0), N_xz));
float angle = acos(dot(vec3(0.0, 0.0, 1.0), N_xz));
Tangent = normalize(rotate_vector(vec3(1.0, 0.0, 0.0), axis, angle));
if(N.x != N.y || N.x != N.z) {
Tangent = vec3(N.z-N.y, N.x-N.z, N.y-N.x); // (1,1,1) x N
}
else {
Tangent = vec3(N.z-N.y, N.x+N.z, -N.y-N.x); // (-1,1,1) x N
}
}