diff --git a/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag b/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag index fcda3f495..8484b454d 100644 --- a/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag +++ b/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag @@ -274,21 +274,29 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w #ifdef NORMALMAP n = texture2D(m_NormalMap, texCoord * m_DiffuseMap_0_scale).xyz; normal += n * alphaBlend.r; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.r; #endif #ifdef NORMALMAP_1 n = texture2D(m_NormalMap_1, texCoord * m_DiffuseMap_1_scale).xyz; normal += n * alphaBlend.g; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.g; #endif #ifdef NORMALMAP_2 n = texture2D(m_NormalMap_2, texCoord * m_DiffuseMap_2_scale).xyz; normal += n * alphaBlend.b; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.b; #endif #ifdef NORMALMAP_3 n = texture2D(m_NormalMap_3, texCoord * m_DiffuseMap_3_scale).xyz; normal += n * alphaBlend.a; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.a; #endif #ifdef ALPHAMAP_1 @@ -472,12 +480,12 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w vec4 coords = wVert; vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy ); - #ifdef ALPHAMAP_1 - vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy ); - #endif - #ifdef ALPHAMAP_2 - vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord.xy ); - #endif + #ifdef ALPHAMAP_1 + vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy ); + #endif + #ifdef ALPHAMAP_2 + vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord.xy ); + #endif vec3 normal = vec3(0,0,1); vec3 n = vec3(0,0,0); @@ -485,42 +493,58 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w #ifdef NORMALMAP n = getTriPlanarBlend(coords, blending, m_NormalMap, m_DiffuseMap_0_scale).xyz; normal += n * alphaBlend.r; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.r; #endif #ifdef NORMALMAP_1 n = getTriPlanarBlend(coords, blending, m_NormalMap_1, m_DiffuseMap_1_scale).xyz; normal += n * alphaBlend.g; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.g; #endif #ifdef NORMALMAP_2 n = getTriPlanarBlend(coords, blending, m_NormalMap_2, m_DiffuseMap_2_scale).xyz; normal += n * alphaBlend.b; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.b; #endif #ifdef NORMALMAP_3 n = getTriPlanarBlend(coords, blending, m_NormalMap_3, m_DiffuseMap_3_scale).xyz; normal += n * alphaBlend.a; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.a; #endif #ifdef ALPHAMAP_1 #ifdef NORMALMAP_4 n = getTriPlanarBlend(coords, blending, m_NormalMap_4, m_DiffuseMap_4_scale).xyz; normal += n * alphaBlend1.r; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.r; #endif #ifdef NORMALMAP_5 n = getTriPlanarBlend(coords, blending, m_NormalMap_5, m_DiffuseMap_5_scale).xyz; normal += n * alphaBlend1.g; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.g; #endif #ifdef NORMALMAP_6 n = getTriPlanarBlend(coords, blending, m_NormalMap_6, m_DiffuseMap_6_scale).xyz; normal += n * alphaBlend1.b; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.b; #endif #ifdef NORMALMAP_7 n = getTriPlanarBlend(coords, blending, m_NormalMap_7, m_DiffuseMap_7_scale).xyz; normal += n * alphaBlend1.a; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.a; #endif #endif @@ -528,21 +552,29 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w #ifdef NORMALMAP_8 n = getTriPlanarBlend(coords, blending, m_NormalMap_8, m_DiffuseMap_8_scale).xyz; normal += n * alphaBlend2.r; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.r; #endif #ifdef NORMALMAP_9 n = getTriPlanarBlend(coords, blending, m_NormalMap_9, m_DiffuseMap_9_scale).xyz; normal += n * alphaBlend2.g; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.g; #endif #ifdef NORMALMAP_10 n = getTriPlanarBlend(coords, blending, m_NormalMap_10, m_DiffuseMap_10_scale).xyz; normal += n * alphaBlend2.b; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.b; #endif #ifdef NORMALMAP_11 n = getTriPlanarBlend(coords, blending, m_NormalMap_11, m_DiffuseMap_11_scale).xyz; normal += n * alphaBlend2.a; + #else + normal += vec3(0.5,0.5,1) * alphaBlend.a; #endif #endif diff --git a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java index 127379eb7..ec740f921 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java +++ b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java @@ -102,22 +102,23 @@ public class TerrainTestAdvanced extends SimpleApplication { // ALPHA map (for splat textures) matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.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) 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 Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap_1", grass); 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 Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); @@ -130,12 +131,14 @@ public class TerrainTestAdvanced extends SimpleApplication { matTerrain.setTexture("DiffuseMap_3", brick); 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"); riverRock.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap_4", riverRock); 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"); normalMap0.setWrap(WrapMode.Repeat); @@ -143,16 +146,11 @@ public class TerrainTestAdvanced extends SimpleApplication { normalMap1.setWrap(WrapMode.Repeat); Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png"); normalMap2.setWrap(WrapMode.Repeat); - matTerrain.setTexture("NormalMap", normalMap0); + //matTerrain.setTexture("NormalMap", normalMap0); matTerrain.setTexture("NormalMap_1", normalMap2); matTerrain.setTexture("NormalMap_2", 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(); // CREATE HEIGHTMAP @@ -190,7 +188,7 @@ public class TerrainTestAdvanced extends SimpleApplication { //terrain.generateDebugTangents(debugMat); 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); cam.setLocation(new Vector3f(0, 10, -10));