I still have my issue with splatting more than three textures… Can anyone help me figure out what my problem is? I’m very new to JME3 and the SDK but I’m slowly figuring things out.
I’m trying to add a fourth texture to splat onto my terrain using my alpha map (I made sure my colors were RGB). How would I go about adding my fourth texture exactly?
A code snippet or example would be very, very commended.
THANKS!
Current code is as follows:
[java]
/** 1. Create terrain material and load five textures into it. */
mat_terrain = new Material(
assetManager, “Common/MatDefs/Terrain/Terrain.j3md”);
/** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
mat_terrain.setTexture("Alpha", assetManager.loadTexture(
"Textures/game_island_terrain/alphamap/alphamap.png"));
/** 1.2) Add GRASS texture into the red layer (Tex1). */
Texture grass = assetManager.loadTexture(
"Textures/game_island_terrain/textures/grass.jpg");
grass.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex1", grass);
mat_terrain.setFloat("Tex1Scale", 64f);
/** 1.3) Add DIRT texture into the green layer (Tex2) */
Texture dirt = assetManager.loadTexture(
"Textures/game_island_terrain/textures/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex2", dirt);
mat_terrain.setFloat("Tex2Scale", 32f);
/** 1.4) Add ROAD texture into the blue layer (Tex3) */
Texture rock = assetManager.loadTexture(
"Textures/game_island_terrain/textures/road.jpg");
rock.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex3", rock);
mat_terrain.setFloat("Tex3Scale", 128f);
/** 1.5) Add WATER texture into the yellow layer (Tex4) */
Texture water = assetManager.loadTexture(
"Textures/game_island_terrain/textures/water.jpg");
//water.setWrap(WrapMode.Repeat);
//mat_terrain.setTexture(yellow.set(255, 255, 0, 0).toString(), water);
//mat_terrain.setFloat("Tex4Scale", 64f);
<cite>@xtgscott said:</cite>
Hi all, I'm going off of the hello_terrain example in the beginner tutorials. I created my heightmap (which is completely flat when loaded into the SDK?), and my alphamap.
Been a while since I tried that in the SDK but then I had to scale the height pretty much to see something.
My alphamap contains four colors instead of three.
So instead of:
R = grass,
G = dirt,
B = road.
I have,
R = grass,
G = dirt,
B = road,
YELLOW = water
The trick to having a forth texture is to use the alpha component. Each pixel in “alphamap.png” should be RGBA-format. Alpha is usually used in image graphics to mean how transparent that pixel is, but the terrain shader uses it to select how much of the Tex4 to mix in.
Example,
The terrain shader takes a pixel in alphamap.png. Say it finds that this pixel has the color R: 0.5, G:0.5, B: 0.0, A 0.1
The shader will sample (find a ‘corresponding’ pixel in) each of the textures tex1…tex4. So now it has 4 pixel from the images, it will mix them together to decide what color the pixel should have on the terrain. But it will weight the mixing using alphamap values, although this is not exactly the right math it will do something like:
Tex1 pixel color * 0.5 + Tex2 pixel color * 0.5 + Tex3 pixel color * 0.0 + Tex4 pixel color * 0.1
Seems like the current terrain material only supports three textures. You’d have to modify the shaders to have it support more and I suspect based on your misunderstandings so far that this is way over your skill level.
But I really can’t explain it better than I did. Try creating terrain in the SDK terrain editor, add the materials and play with the editors there. There is no “magic” code other than what is in the tutorials already. Sorry.
What @jmassing said, terrainLighting material supports more than 3 splat textures. The editor in the SDK uses this and will tell you how many texture “layers” you can splat on it.
<cite>@jmaasing said:</cite>
The 'Terrain' material only supports 3 textures. The 'TerrainLighting'-material supports more (http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.j3md)
But I really can’t explain it better than I did. Try creating terrain in the SDK terrain editor, add the materials and play with the editors there. There is no “magic” code other than what is in the tutorials already. Sorry.
Thanks, jmaasing. That looks like it would work, is there already an example usage of the TerrainLighting material?
<cite>@Sploreg said:</cite>
What @jmassing said, terrainLighting material supports more than 3 splat textures. The editor in the SDK uses this and will tell you how many texture "layers" you can splat on it.
Thanks, Sploreg, but as I said, ,is there already an example of theyou terrainLighting material in a tutorial ?
[Edit:]
I was looking through the material definition properties and found the TerrainLighting parameter properties.
I’m presuming if I wanted to use the TerrainLighting class it would look something similar t:
[java]
TerrainLighting terrain_lighting_mat;
terrain_lighting_mat = new Material(assetManager, “path to TerrainLighting.j3md”);
Texture water = assetManager.loadTexture(“path to texture”);
water.setWrap(WrapMode.Repeat);
TerrainTestAdvanced shows how to use all the different alpha maps. These are the alpha map parameters from that test file:
[java]
// 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 [/java]
<cite>@Sploreg said:</cite>
TerrainTestAdvanced shows how to use all the different alpha maps. These are the alpha map parameters from that test file:
[java]
// 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 [/java]
Thanks, Sploreg. That’s exactly what I was looking for. I’ve used the example code provided to produce this,
[java]
/** 1. Create terrain material and load five textures into it. */
mat_terrain = new Material(
assetManager, “Common/MatDefs/Terrain/TerrainLighting.j3md”);
mat_terrain.setBoolean(“useTriPlanarMapping”, false);
mat_terrain.setFloat(“Shininess”, 0.0f);
All right. I summed up my issue in to one final thread. I apologize for being all over the place, but when i have an issue that i cant solve, it eats me up like a disease