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