Manually unpacked normal mapping to fix issue with refraction being offset rather than distorted.

(cherry picked from commit 31f2d946ad)
This commit is contained in:
Brennen Green 2021-05-05 10:25:32 -04:00 committed by Rémi Verschelde
parent fc67ff3d0a
commit fac2e5dc67
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -861,7 +861,10 @@ void SpatialMaterial::_update_shader() {
if (features[FEATURE_REFRACTION]) {
if (features[FEATURE_NORMAL_MAPPING]) {
code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * NORMALMAP.x + BINORMAL * NORMALMAP.y + NORMAL * NORMALMAP.z,NORMALMAP_DEPTH) );\n";
code += "\tvec3 unpacked_normal = NORMALMAP;\n";
code += "\tunpacked_normal.xy = unpacked_normal.xy * 2.0 - 1.0;\n";
code += "\tunpacked_normal.z = sqrt(max(0.0, 1.0 - dot(unpacked_normal.xy, unpacked_normal.xy)));\n";
code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * unpacked_normal.x + BINORMAL * unpacked_normal.y + NORMAL * unpacked_normal.z,NORMALMAP_DEPTH) );\n";
} else {
code += "\tvec3 ref_normal = NORMAL;\n";
}