Fix: fixed a bug when using alphamaps with TerrainGrid
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7904 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
310193018d
commit
dfef1a6dfe
@ -8,6 +8,9 @@ MaterialDef Terrain Lighting {
|
|||||||
// Use ward specular instead of phong
|
// Use ward specular instead of phong
|
||||||
Boolean WardIso
|
Boolean WardIso
|
||||||
|
|
||||||
|
// Are we rendering TerrainGrid
|
||||||
|
Boolean isTerrainGrid
|
||||||
|
|
||||||
// Ambient color
|
// Ambient color
|
||||||
Color Ambient
|
Color Ambient
|
||||||
|
|
||||||
@ -113,6 +116,7 @@ MaterialDef Terrain Lighting {
|
|||||||
|
|
||||||
Defines {
|
Defines {
|
||||||
TRI_PLANAR_MAPPING : useTriPlanarMapping
|
TRI_PLANAR_MAPPING : useTriPlanarMapping
|
||||||
|
TERRAIN_GRID : isTerrainGrid
|
||||||
WARDISO : WardIso
|
WARDISO : WardIso
|
||||||
|
|
||||||
DIFFUSEMAP : DiffuseMap
|
DIFFUSEMAP : DiffuseMap
|
||||||
|
@ -36,8 +36,6 @@ varying vec4 SpecularSum;
|
|||||||
varying vec3 wNormal;
|
varying vec3 wNormal;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// JME3 lights in world space
|
// JME3 lights in world space
|
||||||
void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
|
void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
|
||||||
float posLight = step(0.5, color.w);
|
float posLight = step(0.5, color.w);
|
||||||
@ -52,7 +50,11 @@ void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4
|
|||||||
void main(){
|
void main(){
|
||||||
vec4 pos = vec4(inPosition, 1.0);
|
vec4 pos = vec4(inPosition, 1.0);
|
||||||
gl_Position = g_WorldViewProjectionMatrix * pos;
|
gl_Position = g_WorldViewProjectionMatrix * pos;
|
||||||
|
#ifdef TERRAIN_GRID
|
||||||
|
texCoord = inTexCoord * 2.0;
|
||||||
|
#else
|
||||||
texCoord = inTexCoord;
|
texCoord = inTexCoord;
|
||||||
|
#endif
|
||||||
|
|
||||||
vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
|
vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
|
||||||
vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
|
vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
|
||||||
|
@ -87,6 +87,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
// TERRAIN TEXTURE material
|
// TERRAIN TEXTURE material
|
||||||
matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
|
matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
|
||||||
matRock.setBoolean("useTriPlanarMapping", false);
|
matRock.setBoolean("useTriPlanarMapping", false);
|
||||||
|
matRock.setBoolean("isTerrainGrid", true);
|
||||||
|
|
||||||
// GRASS texture
|
// GRASS texture
|
||||||
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
||||||
@ -189,7 +190,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tileAttached(Vector3f cell, TerrainQuad quad) {
|
public void tileAttached(Vector3f cell, TerrainQuad quad) {
|
||||||
Texture alpha = assetManager.loadTexture("Scenes/TerrainAlphaTest/alphamap_" + Math.abs((int) (cell.x % 2)) * 512 + "_" + Math.abs((int) (cell.y % 2) * 512) + ".png");
|
Texture alpha = assetManager.loadTexture("Scenes/TerrainAlphaTest/alphamap_" + Math.abs((int) (cell.x % 2)) * 512 + "_" + Math.abs((int) (cell.z % 2) * 512) + ".png");
|
||||||
quad.getMaterial().setTexture("AlphaMap", alpha);
|
quad.getMaterial().setTexture("AlphaMap", alpha);
|
||||||
if (usePhysics) {
|
if (usePhysics) {
|
||||||
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user