From 6558400123b810d47bd346c56eb5b304fa48343e Mon Sep 17 00:00:00 2001 From: iko Date: Thu, 16 Jan 2020 15:55:29 +0300 Subject: [PATCH] 0031302: Visualization, TKOpenGl - wrong tangent space calculation for normal maps The normal after tangent space calculation has been reverted in order to be in right orientation. The tangent space calculation has been modified in order to handle back faces with inverted normal. --- src/OpenGl/OpenGl_ShaderManager.cxx | 7 ++++--- tests/v3d/glsl/pbr_tangent_normal | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/v3d/glsl/pbr_tangent_normal diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index ababd4359d..e5c143a53b 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -2731,9 +2731,10 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha EOL" aDeltaUVMatrix = mat2 (aDeltaUVMatrix[1][1], -aDeltaUVMatrix[0][1], -aDeltaUVMatrix[1][0], aDeltaUVMatrix[0][0]);" EOL" mat2x3 aDeltaVectorMatrix = mat2x3 (dFdx (PositionWorld.xyz), dFdy (PositionWorld.xyz));" EOL" aDeltaVectorMatrix = aDeltaVectorMatrix * aDeltaUVMatrix;" - EOL" aDeltaVectorMatrix[0] = aDeltaVectorMatrix[0] - dot(Normal, aDeltaVectorMatrix[0]) * Normal;" - EOL" aDeltaVectorMatrix[1] = aDeltaVectorMatrix[1] - dot(Normal, aDeltaVectorMatrix[1]) * Normal;" - EOL" Normal = mat3 (-normalize(aDeltaVectorMatrix[0]), -normalize(aDeltaVectorMatrix[1]), Normal) * aMapNormalValue.xyz;" + EOL" aDeltaVectorMatrix[0] = normalize(aDeltaVectorMatrix[0] - dot(Normal, aDeltaVectorMatrix[0]) * Normal);" + EOL" aDeltaVectorMatrix[1] = normalize(aDeltaVectorMatrix[1] - dot(Normal, aDeltaVectorMatrix[1]) * Normal);" + EOL" float aDirection = gl_FrontFacing ? 1.0 : -1.0;" + EOL" Normal = mat3 (aDirection * aDeltaVectorMatrix[0], aDirection * aDeltaVectorMatrix[1], Normal) * aMapNormalValue.xyz;" EOL" }" EOL"#endif"; } diff --git a/tests/v3d/glsl/pbr_tangent_normal b/tests/v3d/glsl/pbr_tangent_normal new file mode 100644 index 0000000000..ade81c7d42 --- /dev/null +++ b/tests/v3d/glsl/pbr_tangent_normal @@ -0,0 +1,28 @@ +puts "========" +puts "0031302: Visualization, TKOpenGl - wrong tangent space calculation for normal maps" +puts "Test for tangent space orientation." +puts "========" + +pload XDE OCAF MODELING VISUALIZATION + +vclear +vclose ALL + +vinit v -w 1024 -h 1024 +vcamera -persp +vbackground -cubemap [locate_data_file Circus_CubeMap_V.png] +vrenderparams -shadingModel PBR + +vlight -clear +vlight -add ambient + +catch { Close D } +ReadGltf D [locate_data_file bug31302_NormalTangentTest.gltf] +XDisplay -dispmode 1 D + +vfront +vfit +vdump $imagedir/${casename}_front.png + +vback +vdump $imagedir/${casename}_back.png -- 2.39.5