Fixed Parallax without normal map in lighting.j3md
This commit is contained in:
parent
485af7cf2a
commit
6d3377a2a8
@ -37,6 +37,7 @@ varying vec3 SpecularSum;
|
||||
#endif
|
||||
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
|
||||
uniform float m_ParallaxHeight;
|
||||
varying vec3 vViewDirPrlx;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTMAP
|
||||
@ -78,18 +79,18 @@ void main(){
|
||||
#ifdef STEEP_PARALLAX
|
||||
#ifdef NORMALMAP_PARALLAX
|
||||
//parallax map is stored in the alpha channel of the normal map
|
||||
newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
newTexCoord = steepParallaxOffset(m_NormalMap, vViewDirPrlx, texCoord, m_ParallaxHeight);
|
||||
#else
|
||||
//parallax map is a texture
|
||||
newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDirPrlx, texCoord, m_ParallaxHeight);
|
||||
#endif
|
||||
#else
|
||||
#ifdef NORMALMAP_PARALLAX
|
||||
//parallax map is stored in the alpha channel of the normal map
|
||||
newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
newTexCoord = classicParallaxOffset(m_NormalMap, vViewDirPrlx, texCoord, m_ParallaxHeight);
|
||||
#else
|
||||
//parallax map is a texture
|
||||
newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDirPrlx, texCoord, m_ParallaxHeight);
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
|
@ -48,6 +48,10 @@ varying vec3 lightVec;
|
||||
uniform vec4 g_LightDirection;
|
||||
#endif
|
||||
|
||||
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
|
||||
varying vec3 vViewDirPrlx;
|
||||
#endif
|
||||
|
||||
#ifdef USE_REFLECTION
|
||||
uniform vec3 g_CameraPosition;
|
||||
|
||||
@ -107,17 +111,25 @@ void main(){
|
||||
wvLightPos.w = g_LightPosition.w;
|
||||
vec4 lightColor = g_LightColor;
|
||||
|
||||
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
|
||||
#if (defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
|
||||
vec3 wvTangent = normalize(TransformNormal(modelSpaceTan));
|
||||
vec3 wvBinormal = cross(wvNormal, wvTangent);
|
||||
mat3 tbnMat = mat3(wvTangent, wvBinormal * inTangent.w,wvNormal);
|
||||
#endif
|
||||
|
||||
vViewDir = -wvPosition * tbnMat;
|
||||
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
|
||||
vViewDir = -wvPosition * tbnMat;
|
||||
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
|
||||
vViewDirPrlx = vViewDir;
|
||||
#endif
|
||||
lightComputeDir(wvPosition, lightColor.w, wvLightPos, vLightDir, lightVec);
|
||||
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
|
||||
#elif !defined(VERTEX_LIGHTING)
|
||||
vNormal = wvNormal;
|
||||
vViewDir = viewDir;
|
||||
#if defined(PARALLAXMAP)
|
||||
vViewDirPrlx = -wvPosition * tbnMat;
|
||||
#endif
|
||||
lightComputeDir(wvPosition, lightColor.w, wvLightPos, vLightDir, lightVec);
|
||||
#endif
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* Copyright (c) 2009-2015 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -39,20 +39,17 @@ import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.*;
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.post.filters.FXAAFilter;
|
||||
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;
|
||||
|
||||
public class TestParallax extends SimpleApplication {
|
||||
|
||||
private Vector3f lightDir = new Vector3f(-1, -1, .5f).normalizeLocal();
|
||||
private final Vector3f lightDir = new Vector3f(-1, -1, .5f).normalizeLocal();
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestParallax app = new TestParallax();
|
||||
@ -60,7 +57,7 @@ public class TestParallax extends SimpleApplication {
|
||||
}
|
||||
|
||||
public void setupSkyBox() {
|
||||
rootNode.attachChild(SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false));
|
||||
rootNode.attachChild(SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", SkyFactory.EnvMapType.CubeMap));
|
||||
}
|
||||
DirectionalLight dl;
|
||||
|
||||
@ -75,12 +72,7 @@ public class TestParallax extends SimpleApplication {
|
||||
|
||||
public void setupFloor() {
|
||||
mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall2.j3m");
|
||||
mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
|
||||
mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
|
||||
|
||||
// Node floorGeom = (Node) assetManager.loadAsset("Models/WaterTest/WaterTest.mesh.xml");
|
||||
//Geometry g = ((Geometry) floorGeom.getChild(0));
|
||||
//g.getMesh().scaleTextureCoordinates(new Vector2f(10, 10));
|
||||
//mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
|
||||
|
||||
Node floorGeom = new Node("floorGeom");
|
||||
Quad q = new Quad(100, 100);
|
||||
@ -100,9 +92,9 @@ public class TestParallax extends SimpleApplication {
|
||||
|
||||
public void setupSignpost() {
|
||||
Spatial signpost = assetManager.loadModel("Models/Sign Post/Sign Post.mesh.xml");
|
||||
Material mat = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
|
||||
Material matSp = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
|
||||
TangentBinormalGenerator.generate(signpost);
|
||||
signpost.setMaterial(mat);
|
||||
signpost.setMaterial(matSp);
|
||||
signpost.rotate(0, FastMath.HALF_PI, 0);
|
||||
signpost.setLocalTranslation(12, 23.5f, 30);
|
||||
signpost.setLocalScale(4);
|
||||
@ -116,7 +108,6 @@ public class TestParallax extends SimpleApplication {
|
||||
cam.setRotation(new Quaternion(0.05173137f, 0.92363626f, -0.13454558f, 0.35513034f));
|
||||
flyCam.setMoveSpeed(30);
|
||||
|
||||
|
||||
setupLighting();
|
||||
setupSkyBox();
|
||||
setupFloor();
|
||||
@ -124,13 +115,14 @@ public class TestParallax extends SimpleApplication {
|
||||
|
||||
inputManager.addListener(new AnalogListener() {
|
||||
|
||||
@Override
|
||||
public void onAnalog(String name, float value, float tpf) {
|
||||
if ("heightUP".equals(name)) {
|
||||
parallaxHeigh += 0.0001;
|
||||
parallaxHeigh += 0.01;
|
||||
mat.setFloat("ParallaxHeight", parallaxHeigh);
|
||||
}
|
||||
if ("heightDown".equals(name)) {
|
||||
parallaxHeigh -= 0.0001;
|
||||
parallaxHeigh -= 0.01;
|
||||
parallaxHeigh = Math.max(parallaxHeigh, 0);
|
||||
mat.setFloat("ParallaxHeight", parallaxHeigh);
|
||||
}
|
||||
@ -142,6 +134,7 @@ public class TestParallax extends SimpleApplication {
|
||||
|
||||
inputManager.addListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void onAction(String name, boolean isPressed, float tpf) {
|
||||
if (isPressed && "toggleSteep".equals(name)) {
|
||||
steep = !steep;
|
||||
|
@ -1,8 +1,7 @@
|
||||
Material Pong Rock : Common/MatDefs/Light/Lighting.j3md {
|
||||
MaterialParameters {
|
||||
Shininess: 2.0
|
||||
DiffuseMap : Textures/Terrain/BrickWall/BrickWall.jpg
|
||||
NormalMap : Textures/Terrain/BrickWall/BrickWall_normal.jpg
|
||||
ParallaxMap : Textures/Terrain/BrickWall/BrickWall_height.jpg
|
||||
DiffuseMap : Repeat Textures/Terrain/BrickWall/BrickWall.jpg
|
||||
ParallaxMap : Repeat Textures/Terrain/BrickWall/BrickWall_height.jpg
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
Material Pong Rock : Common/MatDefs/Light/Lighting.j3md {
|
||||
MaterialParameters {
|
||||
Shininess: 2.0
|
||||
DiffuseMap : Textures/Terrain/BrickWall/BrickWall.jpg
|
||||
NormalMap : Textures/Terrain/BrickWall/BrickWall_normal_parallax.dds
|
||||
DiffuseMap : Repeat Textures/Terrain/BrickWall/BrickWall.jpg
|
||||
NormalMap : Repeat Textures/Terrain/BrickWall/BrickWall_normal_parallax.dds
|
||||
PackedNormalParallax: true
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user