From 26ffa11655829f357846d07a431e6ad83183df95 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sat, 18 Feb 2012 08:17:07 +0000 Subject: [PATCH] - Fixed parallax distortion thanks to Survivor - Used a quad in TestParallax instead of a grid git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9173 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../Common/MatDefs/Light/Lighting.frag | 3 ++- .../Common/MatDefs/Light/Lighting.vert | 3 ++- .../test/jme3test/material/TestParallax.java | 20 ++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag index 2c4731da5..76f0e1512 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag @@ -249,8 +249,9 @@ void main(){ #else vec4 lightDir = vLightDir; lightDir.xyz = normalize(lightDir.xyz); + vec3 viewDir = normalize(vViewDir); - vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz) * spotFallOff; + vec2 light = computeLighting(normal, viewDir, lightDir.xyz) * spotFallOff; #ifdef COLORRAMP diffuseColor.rgb *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb; specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb; diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert index ec9a8daac..042cba9bf 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert @@ -158,7 +158,8 @@ void main(){ mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal); //vPosition = wvPosition * tbnMat; - vViewDir = viewDir * tbnMat; + //vViewDir = viewDir * tbnMat; + vViewDir = -wvPosition * tbnMat; lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir); vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz; #elif !defined(VERTEX_LIGHTING) diff --git a/engine/src/test/jme3test/material/TestParallax.java b/engine/src/test/jme3test/material/TestParallax.java index 1082c291b..b52ad3cae 100644 --- a/engine/src/test/jme3test/material/TestParallax.java +++ b/engine/src/test/jme3test/material/TestParallax.java @@ -45,6 +45,7 @@ import com.jme3.renderer.queue.RenderQueue.ShadowMode; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.Spatial; +import com.jme3.scene.shape.Quad; import com.jme3.texture.Texture.WrapMode; import com.jme3.util.SkyFactory; import com.jme3.util.TangentBinormalGenerator; @@ -78,12 +79,21 @@ public class TestParallax extends SimpleApplication { mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat); mat.setFloat("Shininess", 0); - Node floorGeom = (Node) assetManager.loadAsset("Models/WaterTest/WaterTest.mesh.xml"); - Geometry g = ((Geometry) floorGeom.getChild(0)); - g.getMesh().scaleTextureCoordinates(new Vector2f(10, 10)); + // Node floorGeom = (Node) assetManager.loadAsset("Models/WaterTest/WaterTest.mesh.xml"); + //Geometry g = ((Geometry) floorGeom.getChild(0)); + //g.getMesh().scaleTextureCoordinates(new Vector2f(10, 10)); + + Node floorGeom = new Node("floorGeom"); + Quad q = new Quad(100, 100); + q.scaleTextureCoordinates(new Vector2f(10, 10)); + Geometry g = new Geometry("geom", q); + g.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); + floorGeom.attachChild(g); + + TangentBinormalGenerator.generate(floorGeom); - floorGeom.setLocalTranslation(0, 22, 0); - floorGeom.setLocalScale(100); + floorGeom.setLocalTranslation(-50, 22, 60); + //floorGeom.setLocalScale(100); floorGeom.setMaterial(mat); rootNode.attachChild(floorGeom);