From 926b634b6e76951ee4da9fc7a0fa7cc679d400c4 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sun, 19 Jan 2014 23:37:28 +0000 Subject: [PATCH] Fixed an issue with parallax mapping thanks to this thread http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898 git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10993 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core-data/Common/MatDefs/Light/Lighting.frag | 9 ++++++--- engine/src/core-data/Common/MatDefs/Light/Lighting.vert | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag index eac42df22..e4773c8cf 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag @@ -211,11 +211,14 @@ void main(){ // *********************** #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) vec4 normalHeight = texture2D(m_NormalMap, newTexCoord); - vec3 normal = normalize((normalHeight.xyz * vec3(2.0) - vec3(1.0))); + //Note the -2.0 and -1.0. We invert the green channel of the normal map, + //as it's complient with normal maps generated with blender. + //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898 + //for more explanation. + vec3 normal = normalize((normalHeight.xyz * vec3(2.0,-2.0,2.0) - vec3(1.0,-1.0,1.0))); #ifdef LATC normal.z = sqrt(1.0 - (normal.x * normal.x) - (normal.y * normal.y)); - #endif - //normal.y = -normal.y; + #endif #elif !defined(VERTEX_LIGHTING) vec3 normal = vNormal; #if !defined(LOW_QUALITY) && !defined(V_TANGENT) diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert index 72323cbae..c7cb3e5db 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert @@ -171,7 +171,7 @@ void main(){ vec3 wvTangent = normalize(g_NormalMatrix * modelSpaceTan); vec3 wvBinormal = cross(wvNormal, wvTangent); - mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal); + mat3 tbnMat = mat3(wvTangent, wvBinormal * inTangent.w,wvNormal); //vPosition = wvPosition * tbnMat; //vViewDir = viewDir * tbnMat;