Added more comments to the TerrainLighting test. Made the TerrainLighting material more forgiving if normal maps aren't set
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9751 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
384f4ac1c2
commit
bd7c10ba80
engine/src
@ -274,21 +274,29 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
|
|||||||
#ifdef NORMALMAP
|
#ifdef NORMALMAP
|
||||||
n = texture2D(m_NormalMap, texCoord * m_DiffuseMap_0_scale).xyz;
|
n = texture2D(m_NormalMap, texCoord * m_DiffuseMap_0_scale).xyz;
|
||||||
normal += n * alphaBlend.r;
|
normal += n * alphaBlend.r;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_1
|
#ifdef NORMALMAP_1
|
||||||
n = texture2D(m_NormalMap_1, texCoord * m_DiffuseMap_1_scale).xyz;
|
n = texture2D(m_NormalMap_1, texCoord * m_DiffuseMap_1_scale).xyz;
|
||||||
normal += n * alphaBlend.g;
|
normal += n * alphaBlend.g;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.g;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_2
|
#ifdef NORMALMAP_2
|
||||||
n = texture2D(m_NormalMap_2, texCoord * m_DiffuseMap_2_scale).xyz;
|
n = texture2D(m_NormalMap_2, texCoord * m_DiffuseMap_2_scale).xyz;
|
||||||
normal += n * alphaBlend.b;
|
normal += n * alphaBlend.b;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.b;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_3
|
#ifdef NORMALMAP_3
|
||||||
n = texture2D(m_NormalMap_3, texCoord * m_DiffuseMap_3_scale).xyz;
|
n = texture2D(m_NormalMap_3, texCoord * m_DiffuseMap_3_scale).xyz;
|
||||||
normal += n * alphaBlend.a;
|
normal += n * alphaBlend.a;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.a;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ALPHAMAP_1
|
#ifdef ALPHAMAP_1
|
||||||
@ -485,42 +493,58 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
|
|||||||
#ifdef NORMALMAP
|
#ifdef NORMALMAP
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap, m_DiffuseMap_0_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap, m_DiffuseMap_0_scale).xyz;
|
||||||
normal += n * alphaBlend.r;
|
normal += n * alphaBlend.r;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_1
|
#ifdef NORMALMAP_1
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_1, m_DiffuseMap_1_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_1, m_DiffuseMap_1_scale).xyz;
|
||||||
normal += n * alphaBlend.g;
|
normal += n * alphaBlend.g;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.g;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_2
|
#ifdef NORMALMAP_2
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_2, m_DiffuseMap_2_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_2, m_DiffuseMap_2_scale).xyz;
|
||||||
normal += n * alphaBlend.b;
|
normal += n * alphaBlend.b;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.b;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_3
|
#ifdef NORMALMAP_3
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_3, m_DiffuseMap_3_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_3, m_DiffuseMap_3_scale).xyz;
|
||||||
normal += n * alphaBlend.a;
|
normal += n * alphaBlend.a;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.a;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ALPHAMAP_1
|
#ifdef ALPHAMAP_1
|
||||||
#ifdef NORMALMAP_4
|
#ifdef NORMALMAP_4
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_4, m_DiffuseMap_4_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_4, m_DiffuseMap_4_scale).xyz;
|
||||||
normal += n * alphaBlend1.r;
|
normal += n * alphaBlend1.r;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_5
|
#ifdef NORMALMAP_5
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_5, m_DiffuseMap_5_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_5, m_DiffuseMap_5_scale).xyz;
|
||||||
normal += n * alphaBlend1.g;
|
normal += n * alphaBlend1.g;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.g;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_6
|
#ifdef NORMALMAP_6
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_6, m_DiffuseMap_6_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_6, m_DiffuseMap_6_scale).xyz;
|
||||||
normal += n * alphaBlend1.b;
|
normal += n * alphaBlend1.b;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.b;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_7
|
#ifdef NORMALMAP_7
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_7, m_DiffuseMap_7_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_7, m_DiffuseMap_7_scale).xyz;
|
||||||
normal += n * alphaBlend1.a;
|
normal += n * alphaBlend1.a;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.a;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -528,21 +552,29 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
|
|||||||
#ifdef NORMALMAP_8
|
#ifdef NORMALMAP_8
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_8, m_DiffuseMap_8_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_8, m_DiffuseMap_8_scale).xyz;
|
||||||
normal += n * alphaBlend2.r;
|
normal += n * alphaBlend2.r;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_9
|
#ifdef NORMALMAP_9
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_9, m_DiffuseMap_9_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_9, m_DiffuseMap_9_scale).xyz;
|
||||||
normal += n * alphaBlend2.g;
|
normal += n * alphaBlend2.g;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.g;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_10
|
#ifdef NORMALMAP_10
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_10, m_DiffuseMap_10_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_10, m_DiffuseMap_10_scale).xyz;
|
||||||
normal += n * alphaBlend2.b;
|
normal += n * alphaBlend2.b;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.b;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NORMALMAP_11
|
#ifdef NORMALMAP_11
|
||||||
n = getTriPlanarBlend(coords, blending, m_NormalMap_11, m_DiffuseMap_11_scale).xyz;
|
n = getTriPlanarBlend(coords, blending, m_NormalMap_11, m_DiffuseMap_11_scale).xyz;
|
||||||
normal += n * alphaBlend2.a;
|
normal += n * alphaBlend2.a;
|
||||||
|
#else
|
||||||
|
normal += vec3(0.5,0.5,1) * alphaBlend.a;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -102,22 +102,23 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
// ALPHA map (for splat textures)
|
// ALPHA map (for splat textures)
|
||||||
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));
|
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));
|
||||||
matTerrain.setTexture("AlphaMap_1", assetManager.loadTexture("Textures/Terrain/splat/alpha2.png"));
|
matTerrain.setTexture("AlphaMap_1", assetManager.loadTexture("Textures/Terrain/splat/alpha2.png"));
|
||||||
|
// this material also supports 'AlphaMap_2', so you can get up to 12 diffuse textures
|
||||||
|
|
||||||
// HEIGHTMAP image (for the terrain heightmap)
|
// HEIGHTMAP image (for the terrain heightmap)
|
||||||
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
|
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
|
||||||
|
|
||||||
|
// DIRT texture, Diffuse textures 0 to 3 use the first AlphaMap
|
||||||
|
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
|
||||||
|
dirt.setWrap(WrapMode.Repeat);
|
||||||
|
matTerrain.setTexture("DiffuseMap", dirt);
|
||||||
|
matTerrain.setFloat("DiffuseMap_0_scale", dirtScale);
|
||||||
|
|
||||||
// GRASS texture
|
// GRASS texture
|
||||||
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
||||||
grass.setWrap(WrapMode.Repeat);
|
grass.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("DiffuseMap_1", grass);
|
matTerrain.setTexture("DiffuseMap_1", grass);
|
||||||
matTerrain.setFloat("DiffuseMap_1_scale", grassScale);
|
matTerrain.setFloat("DiffuseMap_1_scale", grassScale);
|
||||||
|
|
||||||
// DIRT texture
|
|
||||||
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
|
|
||||||
dirt.setWrap(WrapMode.Repeat);
|
|
||||||
matTerrain.setTexture("DiffuseMap", dirt);
|
|
||||||
matTerrain.setFloat("DiffuseMap_0_scale", dirtScale);
|
|
||||||
|
|
||||||
// ROCK texture
|
// ROCK texture
|
||||||
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
|
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
|
||||||
rock.setWrap(WrapMode.Repeat);
|
rock.setWrap(WrapMode.Repeat);
|
||||||
@ -130,12 +131,14 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
matTerrain.setTexture("DiffuseMap_3", brick);
|
matTerrain.setTexture("DiffuseMap_3", brick);
|
||||||
matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
|
matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
|
||||||
|
|
||||||
// RIVER ROCK texture
|
// RIVER ROCK texture, this texture will use the next alphaMap: AlphaMap_1
|
||||||
Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
|
Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
|
||||||
riverRock.setWrap(WrapMode.Repeat);
|
riverRock.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("DiffuseMap_4", riverRock);
|
matTerrain.setTexture("DiffuseMap_4", riverRock);
|
||||||
matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
|
matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
|
||||||
|
|
||||||
|
// diffuse textures 4 to 7 use AlphaMap_1
|
||||||
|
// diffuse textures 8 to 11 use AlphaMap_2
|
||||||
|
|
||||||
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
|
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
|
||||||
normalMap0.setWrap(WrapMode.Repeat);
|
normalMap0.setWrap(WrapMode.Repeat);
|
||||||
@ -143,16 +146,11 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
normalMap1.setWrap(WrapMode.Repeat);
|
normalMap1.setWrap(WrapMode.Repeat);
|
||||||
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
|
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
|
||||||
normalMap2.setWrap(WrapMode.Repeat);
|
normalMap2.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("NormalMap", normalMap0);
|
//matTerrain.setTexture("NormalMap", normalMap0);
|
||||||
matTerrain.setTexture("NormalMap_1", normalMap2);
|
matTerrain.setTexture("NormalMap_1", normalMap2);
|
||||||
matTerrain.setTexture("NormalMap_2", normalMap2);
|
matTerrain.setTexture("NormalMap_2", normalMap2);
|
||||||
matTerrain.setTexture("NormalMap_4", normalMap2);
|
matTerrain.setTexture("NormalMap_4", normalMap2);
|
||||||
|
|
||||||
// WIREFRAME material
|
|
||||||
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
||||||
matWire.getAdditionalRenderState().setWireframe(true);
|
|
||||||
matWire.setColor("Color", ColorRGBA.Green);
|
|
||||||
|
|
||||||
createSky();
|
createSky();
|
||||||
|
|
||||||
// CREATE HEIGHTMAP
|
// CREATE HEIGHTMAP
|
||||||
@ -190,7 +188,7 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
//terrain.generateDebugTangents(debugMat);
|
//terrain.generateDebugTangents(debugMat);
|
||||||
|
|
||||||
DirectionalLight light = new DirectionalLight();
|
DirectionalLight light = new DirectionalLight();
|
||||||
light.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalize());
|
light.setDirection((new Vector3f(-0.1f, -0.1f, -0.1f)).normalize());
|
||||||
rootNode.addLight(light);
|
rootNode.addLight(light);
|
||||||
|
|
||||||
cam.setLocation(new Vector3f(0, 10, -10));
|
cam.setLocation(new Vector3f(0, 10, -10));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user