* bumped up terrain material texture support

* updated the test case example

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7655 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 14 years ago
parent be366b5b53
commit 2ded30739d
  1. 171
      engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag
  2. 33
      engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.j3md
  3. BIN
      engine/src/test-data/Textures/Terrain/splat/alpha1.png
  4. BIN
      engine/src/test-data/Textures/Terrain/splat/alpha2.png
  5. 26
      engine/src/test/jme3test/terrain/TerrainTestAdvanced.java

@ -26,6 +26,18 @@ varying vec4 vnLightDir;
#ifdef DIFFUSEMAP_3
uniform sampler2D m_DiffuseMap_3;
#endif
#ifdef DIFFUSEMAP_4
uniform sampler2D m_DiffuseMap_4;
#endif
#ifdef DIFFUSEMAP_5
uniform sampler2D m_DiffuseMap_5;
#endif
#ifdef DIFFUSEMAP_6
uniform sampler2D m_DiffuseMap_6;
#endif
#ifdef DIFFUSEMAP_7
uniform sampler2D m_DiffuseMap_7;
#endif
#ifdef DIFFUSEMAP_0_SCALE
@ -40,6 +52,18 @@ varying vec4 vnLightDir;
#ifdef DIFFUSEMAP_3_SCALE
uniform float m_DiffuseMap_3_scale;
#endif
#ifdef DIFFUSEMAP_4_SCALE
uniform float m_DiffuseMap_4_scale;
#endif
#ifdef DIFFUSEMAP_5_SCALE
uniform float m_DiffuseMap_5_scale;
#endif
#ifdef DIFFUSEMAP_6_SCALE
uniform float m_DiffuseMap_6_scale;
#endif
#ifdef DIFFUSEMAP_7_SCALE
uniform float m_DiffuseMap_7_scale;
#endif
#ifdef ALPHAMAP
@ -64,6 +88,19 @@ varying vec4 vnLightDir;
#ifdef NORMALMAP_3
uniform sampler2D m_NormalMap_3;
#endif
#ifdef NORMALMAP_4
uniform sampler2D m_NormalMap_4;
#endif
#ifdef NORMALMAP_5
uniform sampler2D m_NormalMap_5;
#endif
#ifdef NORMALMAP_6
uniform sampler2D m_NormalMap_6;
#endif
#ifdef NORMALMAP_7
uniform sampler2D m_NormalMap_7;
#endif
#ifdef TRI_PLANAR_MAPPING
varying vec4 wVertex;
@ -119,6 +156,11 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
vec4 calculateDiffuseBlend(in vec2 texCoord) {
vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
#ifdef ALPHAMAP_1
vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
#endif
vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale);
diffuseColor *= alphaBlend.r;
#ifdef DIFFUSEMAP_1
@ -130,6 +172,24 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
#ifdef DIFFUSEMAP_3
vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale);
diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a );
#ifdef ALPHAMAP_1
#ifdef DIFFUSEMAP_4
vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale);
diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r );
#ifdef DIFFUSEMAP_5
vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale);
diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g );
#ifdef DIFFUSEMAP_6
vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale);
diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b );
#ifdef DIFFUSEMAP_7
vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale);
diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a );
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
@ -143,6 +203,10 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
#ifdef ALPHAMAP_1
vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
#endif
#ifdef NORMALMAP
normalHeight = texture2D(m_NormalMap, texCoord * m_DiffuseMap_0_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
@ -175,6 +239,40 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
normal += n * alphaBlend.a;
#endif
#ifdef ALPHAMAP_1
#ifdef NORMALMAP_4
normalHeight = texture2D(m_NormalMap_4, texCoord * m_DiffuseMap_4_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.r;
#endif
#ifdef NORMALMAP_5
normalHeight = texture2D(m_NormalMap_5, texCoord * m_DiffuseMap_5_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.g;
#endif
#ifdef NORMALMAP_6
normalHeight = texture2D(m_NormalMap_6, texCoord * m_DiffuseMap_6_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.b;
#endif
#ifdef NORMALMAP_7
normalHeight = texture2D(m_NormalMap_7, texCoord * m_DiffuseMap_67_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.a;
#endif
#endif
return normalize(normal);
}
@ -215,8 +313,29 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
// blend the results of the 3 planar projections.
vec4 tex3 = getTriPlanarBlend(coords, blending, m_DiffuseMap_3, m_DiffuseMap_3_scale);
#endif
#ifdef DIFFUSEMAP_4
// blend the results of the 3 planar projections.
vec4 tex4 = getTriPlanarBlend(coords, blending, m_DiffuseMap_4, m_DiffuseMap_4_scale);
#endif
#ifdef DIFFUSEMAP_5
// blend the results of the 3 planar projections.
vec4 tex5 = getTriPlanarBlend(coords, blending, m_DiffuseMap_5, m_DiffuseMap_5_scale);
#endif
#ifdef DIFFUSEMAP_6
// blend the results of the 3 planar projections.
vec4 tex6 = getTriPlanarBlend(coords, blending, m_DiffuseMap_6, m_DiffuseMap_6_scale);
#endif
#ifdef DIFFUSEMAP_7
// blend the results of the 3 planar projections.
vec4 tex7 = getTriPlanarBlend(coords, blending, m_DiffuseMap_7, m_DiffuseMap_7_scale);
#endif
vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
#ifdef ALPHAMAP_1
vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
#endif
vec4 diffuseColor = tex0 * alphaBlend.r;
#ifdef DIFFUSEMAP_1
diffuseColor = mix( diffuseColor, tex1, alphaBlend.g );
@ -224,6 +343,20 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
diffuseColor = mix( diffuseColor, tex2, alphaBlend.b );
#ifdef DIFFUSEMAP_3
diffuseColor = mix( diffuseColor, tex3, alphaBlend.a );
#ifdef ALPHAMAP_1
#ifdef DIFFUSEMAP_4
diffuseColor = mix( diffuseColor, tex4, alphaBlend1.r );
#ifdef DIFFUSEMAP_5
diffuseColor = mix( diffuseColor, tex5, alphaBlend1.g );
#ifdef DIFFUSEMAP_6
diffuseColor = mix( diffuseColor, tex6, alphaBlend1.b );
#ifdef DIFFUSEMAP_7
diffuseColor = mix( diffuseColor, tex7, alphaBlend1.a );
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
@ -243,6 +376,10 @@ 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
vec3 normal = vec3(0,0,1);
vec3 n = vec3(0,0,0);
vec4 normalHeight = vec4(0,0,0,0);
@ -279,6 +416,40 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
normal += n * alphaBlend.a;
#endif
#ifdef ALPHAMAP_1
#ifdef NORMALMAP_4
normalHeight = getTriPlanarBlend(coords, blending, m_NormalMap_4, m_DiffuseMap_4_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.r;
#endif
#ifdef NORMALMAP_5
normalHeight = getTriPlanarBlend(coords, blending, m_NormalMap_5, m_DiffuseMap_5_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.g;
#endif
#ifdef NORMALMAP_6
normalHeight = getTriPlanarBlend(coords, blending, m_NormalMap_6, m_DiffuseMap_6_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.b;
#endif
#ifdef NORMALMAP_7
normalHeight = getTriPlanarBlend(coords, blending, m_NormalMap_7, m_DiffuseMap_7_scale);
n = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
n.z = sqrt(1.0 - (n.x * n.x) - (n.y * n.y));
n.y = -n.y;
normal += n * alphaBlend1.a;
#endif
#endif
return normalize(normal);
}
#endif

@ -40,6 +40,27 @@ MaterialDef Terrain Lighting {
Float DiffuseMap_3_scale
Texture2D NormalMap_3
// Texture map #4
Texture2D DiffuseMap_4
Float DiffuseMap_4_scale
Texture2D NormalMap_4
// Texture map #5
Texture2D DiffuseMap_5
Float DiffuseMap_5_scale
Texture2D NormalMap_5
// Texture map #6
Texture2D DiffuseMap_6
Float DiffuseMap_6_scale
Texture2D NormalMap_6
// Texture map #7
Texture2D DiffuseMap_7
Float DiffuseMap_7_scale
Texture2D NormalMap_7
// Specular/gloss map
Texture2D SpecularMap
@ -78,10 +99,18 @@ MaterialDef Terrain Lighting {
DIFFUSEMAP_1 : DiffuseMap_1
DIFFUSEMAP_2 : DiffuseMap_2
DIFFUSEMAP_3 : DiffuseMap_3
DIFFUSEMAP_4 : DiffuseMap_4
DIFFUSEMAP_5 : DiffuseMap_5
DIFFUSEMAP_6 : DiffuseMap_6
DIFFUSEMAP_7 : DiffuseMap_7
NORMALMAP : NormalMap
NORMALMAP_1 : NormalMap_1
NORMALMAP_2 : NormalMap_2
NORMALMAP_3 : NormalMap_3
NORMALMAP_4 : NormalMap_4
NORMALMAP_5 : NormalMap_5
NORMALMAP_6 : NormalMap_6
NORMALMAP_7 : NormalMap_7
SPECULARMAP : SpecularMap
ALPHAMAP : AlphaMap
ALPHAMAP_1 : AlphaMap_1
@ -90,6 +119,10 @@ MaterialDef Terrain Lighting {
DIFFUSEMAP_1_SCALE : DiffuseMap_1_scale
DIFFUSEMAP_2_SCALE : DiffuseMap_2_scale
DIFFUSEMAP_3_SCALE : DiffuseMap_3_scale
DIFFUSEMAP_4_SCALE : DiffuseMap_4_scale
DIFFUSEMAP_5_SCALE : DiffuseMap_5_scale
DIFFUSEMAP_6_SCALE : DiffuseMap_6_scale
DIFFUSEMAP_7_SCALE : DiffuseMap_7_scale
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

@ -47,12 +47,10 @@ import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.geomipmap.lodcalc.LodPerspectiveCalculatorFactory;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.util.SkyFactory;
@ -60,7 +58,7 @@ import java.util.ArrayList;
import java.util.List;
/**
*
* Uses the terrain's lighting texture with normal maps and lights.
*
* @author bowens
*/
@ -104,18 +102,19 @@ public class TerrainTestAdvanced extends SimpleApplication {
matTerrain.setBoolean("WardIso", true);
// ALPHA map (for splat textures)
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));
matTerrain.setTexture("AlphaMap_1", assetManager.loadTexture("Textures/Terrain/splat/alpha2.png"));
// HEIGHTMAP image (for the terrain heightmap)
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
// GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap", grass);
matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
// DIRT texture
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
@ -128,6 +127,18 @@ public class TerrainTestAdvanced extends SimpleApplication {
matTerrain.setTexture("DiffuseMap_2", rock);
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
// BRICK texture
Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
brick.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_3", brick);
matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
// RIVER ROCK texture
Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.png");
riverRock.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_4", riverRock);
matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
normalMap0.setWrap(WrapMode.Repeat);
@ -138,6 +149,7 @@ public class TerrainTestAdvanced extends SimpleApplication {
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");
@ -230,11 +242,15 @@ public class TerrainTestAdvanced extends SimpleApplication {
matTerrain.setFloat("DiffuseMap_0_scale", 1f / (float) (512f / grassScale));
matTerrain.setFloat("DiffuseMap_1_scale", 1f / (float) (512f / dirtScale));
matTerrain.setFloat("DiffuseMap_2_scale", 1f / (float) (512f / rockScale));
matTerrain.setFloat("DiffuseMap_3_scale", 1f / (float) (512f / rockScale));
matTerrain.setFloat("DiffuseMap_4_scale", 1f / (float) (512f / rockScale));
} else {
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
}
}
}

Loading…
Cancel
Save