From 3889cb47b7216ac682c6dcf659306184a91442dd Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sun, 17 Sep 2017 22:11:42 -0400 Subject: [PATCH] calculate lighting in world space --- .../jme3/material/logic/StaticPassLightingLogic.java | 12 ------------ .../Common/MatDefs/Light/StaticLighting.frag | 2 +- .../Common/MatDefs/Light/StaticLighting.vert | 4 ++-- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/material/logic/StaticPassLightingLogic.java b/jme3-core/src/main/java/com/jme3/material/logic/StaticPassLightingLogic.java index 7dfc0f559..c99ef68e7 100644 --- a/jme3-core/src/main/java/com/jme3/material/logic/StaticPassLightingLogic.java +++ b/jme3-core/src/main/java/com/jme3/material/logic/StaticPassLightingLogic.java @@ -126,14 +126,6 @@ public class StaticPassLightingLogic extends DefaultTechniqueDefLogic { return techniqueDef.getShader(assetManager, rendererCaps, defines); } - protected void transformDirection(Matrix4f viewMatrix, Vector3f direction) { - viewMatrix.multNormal(direction, direction); - } - - protected void transformPosition(Matrix4f viewMatrix, Vector3f location) { - viewMatrix.mult(location, location); - } - protected float getShadowMapIndex(Light light) { return 1.0f; } @@ -154,7 +146,6 @@ public class StaticPassLightingLogic extends DefaultTechniqueDefLogic { ColorRGBA color = light.getColor(); float shadowMapIndex = getShadowMapIndex(light); tempDirection.set(light.getDirection()); - transformDirection(viewMatrix, tempDirection); lightData.setVector4InArray(color.r, color.g, color.b, shadowMapIndex, index++); lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, 1f, index++); } @@ -164,7 +155,6 @@ public class StaticPassLightingLogic extends DefaultTechniqueDefLogic { float shadowMapIndex = getShadowMapIndex(light); tempPosition.set(light.getPosition()); float invRadius = light.getInvRadius(); - transformPosition(viewMatrix, tempPosition); lightData.setVector4InArray(color.r, color.g, color.b, shadowMapIndex, index++); lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRadius, index++); } @@ -175,8 +165,6 @@ public class StaticPassLightingLogic extends DefaultTechniqueDefLogic { tempPosition.set(light.getPosition()); tempDirection.set(light.getDirection()); - transformPosition(viewMatrix, tempPosition); - transformDirection(viewMatrix, tempDirection); float invRange = light.getInvSpotRange(); float spotAngleCos = light.getPackedAngleCos(); diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.frag index 962e2c122..890cdba03 100755 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.frag @@ -162,7 +162,7 @@ surface_t getSurface() { if (!gl_FrontFacing) { s.normal = -s.normal; } - s.viewDir = normalize(-vPos); + s.viewDir = normalize(g_CameraPosition - s.position); #ifdef AMBIENTMAP s.ambient = texture2D(m_AmbientMap, vTexCoord).rgb; #else diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.vert index 354afec0c..c974fa440 100755 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/StaticLighting.vert @@ -22,8 +22,8 @@ void main() { Skinning_Compute(modelSpacePos, modelSpaceNorm); #endif - vPos = TransformWorldView(modelSpacePos).xyz; - vNormal = TransformNormal(modelSpaceNorm); + vPos = TransformWorld(modelSpacePos).xyz; + vNormal = TransformWorldNormal(modelSpaceNorm); vec3 shadowPos = TransformWorld(modelSpacePos).xyz; Shadow_ProcessProjCoord(shadowPos);