From a076535090b41d9f2aed5f320ccdcdd97ffdec80 Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 22 Mar 2021 17:57:30 +0300 Subject: [PATCH] 0032237: Visualization, TKOpenGl - fix Gouraud shading within perspective camera projection --- src/Graphic3d/Graphic3d_ShaderManager.cxx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Graphic3d/Graphic3d_ShaderManager.cxx b/src/Graphic3d/Graphic3d_ShaderManager.cxx index aec6b76ca4..42796fe195 100644 --- a/src/Graphic3d/Graphic3d_ShaderManager.cxx +++ b/src/Graphic3d/Graphic3d_ShaderManager.cxx @@ -1476,7 +1476,16 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c EOL"{" EOL" vec4 aPositionWorld = occModelWorldMatrix * occVertex;" EOL" vec3 aNormal = transformNormal (occNormal);" - EOL" vec3 aView = (occWorldViewMatrixInverse * vec4(0.0, 0.0, 1.0, 0.0)).xyz;" + EOL" vec3 aView;" + EOL" if (occProjectionMatrix[3][3] == 1.0)" + EOL" {" + EOL" aView = (occWorldViewMatrixInverse * vec4(0.0, 0.0, 1.0, 0.0)).xyz;" + EOL" }" + EOL" else" + EOL" {" + EOL" vec3 anEye = (occWorldViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0)).xyz;" + EOL" aView = normalize (anEye - aPositionWorld.xyz);" + EOL" }" EOL" FrontColor = computeLighting (aNormal, aView, aPositionWorld, true);" EOL" BackColor = computeLighting (aNormal, aView, aPositionWorld, false);" + aSrcVertExtraMain @@ -1693,14 +1702,13 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con EOL" PositionWorld = occModelWorldMatrix * occVertex;" EOL" if (occProjectionMatrix[3][3] == 1.0)" EOL" {" - EOL" View = vec3(0.0, 0.0, 1.0);" + EOL" View = (occWorldViewMatrixInverse * vec4(0.0, 0.0, 1.0, 0.0)).xyz;" EOL" }" EOL" else" EOL" {" - EOL" vec4 aPosition = occWorldViewMatrix * PositionWorld;" - EOL" View = -aPosition.xyz;" + EOL" vec3 anEye = (occWorldViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0)).xyz;" + EOL" View = normalize (anEye - PositionWorld.xyz);" EOL" }" - EOL" View = (occWorldViewMatrixInverse * vec4(View, 0.0)).xyz;" + aSrcVertExtraMain + THE_VERT_gl_Position + EOL"}";