Преглед на файлове

- 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

rem..om преди 13 години
родител
ревизия
26ffa11655

+ 2 - 1
engine/src/core-data/Common/MatDefs/Light/Lighting.frag

@@ -249,8 +249,9 @@ void main(){
     #else
     #else
        vec4 lightDir = vLightDir;
        vec4 lightDir = vLightDir;
        lightDir.xyz = normalize(lightDir.xyz);
        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
        #ifdef COLORRAMP
            diffuseColor.rgb  *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
            diffuseColor.rgb  *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
            specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;
            specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;

+ 2 - 1
engine/src/core-data/Common/MatDefs/Light/Lighting.vert

@@ -158,7 +158,8 @@ void main(){
      mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
      mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
      
      
      //vPosition = wvPosition * tbnMat;
      //vPosition = wvPosition * tbnMat;
-     vViewDir  = viewDir * tbnMat;
+     //vViewDir  = viewDir * tbnMat;
+     vViewDir  = -wvPosition * tbnMat;
      lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
      lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
      vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
      vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
    #elif !defined(VERTEX_LIGHTING)
    #elif !defined(VERTEX_LIGHTING)

+ 15 - 5
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.Geometry;
 import com.jme3.scene.Node;
 import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
 import com.jme3.scene.Spatial;
+import com.jme3.scene.shape.Quad;
 import com.jme3.texture.Texture.WrapMode;
 import com.jme3.texture.Texture.WrapMode;
 import com.jme3.util.SkyFactory;
 import com.jme3.util.SkyFactory;
 import com.jme3.util.TangentBinormalGenerator;
 import com.jme3.util.TangentBinormalGenerator;
@@ -78,12 +79,21 @@ public class TestParallax extends SimpleApplication {
         mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
         mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
         mat.setFloat("Shininess", 0);
         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);
         TangentBinormalGenerator.generate(floorGeom);
-        floorGeom.setLocalTranslation(0, 22, 0);
-        floorGeom.setLocalScale(100);
+        floorGeom.setLocalTranslation(-50, 22, 60);
+        //floorGeom.setLocalScale(100);
 
 
         floorGeom.setMaterial(mat);        
         floorGeom.setMaterial(mat);        
         rootNode.attachChild(floorGeom);
         rootNode.attachChild(floorGeom);