Issues with Heightbasedterrain Slope

Anyone experienced any issues like this? The texture seems to be drawn in the right places, but its all just one line of pixels stretched.

I’ve tried a few different formats for the “mountains” image (the one thats having problems) such as png and jpg, converted in GIMP.

Here is my code:

TerrainGrid terrain;
Material terrain_mat;

public WorldTerrain(GameplayState game) {
    //terrain = new TerrainGrid("terrain", 65, 257,
    terrain_mat = new Material(game.assetManager, "Common/MatDefs/Terrain/HeightBasedTerrain.j3md");

    Texture ice1 = game.assetManager.loadTexture("Terrain/Snow0086_7_S.png");
    ice1.setWrap(WrapMode.Repeat);
    terrain_mat.setTexture("region1ColorMap", ice1);
    terrain_mat.setVector3("region1", new Vector3f(0, 400, 8));
    
    Texture ice2 = game.assetManager.loadTexture("Terrain/Snow0064_7_S.png");
    ice2.setWrap(WrapMode.Repeat);
    //terrain_mat.setTexture("region2ColorMap", ice2);
    //terrain_mat.setVector3("region2", new Vector3f(200, 400, 8));
    
    Texture rock = game.assetManager.loadTexture("Terrain/mountains.png");
    //ice2.setWrap(WrapMode.Repeat);
    terrain_mat.setTexture("slopeColorMap", rock);
    terrain_mat.setFloat("slopeTileFactor", 2);
    

    terrain_mat.setFloat("terrainSize", 257);

    terrain = new TerrainGrid("terrain", 65, 257, new ImageTileLoader(game.assetManager, new Namer() {
        public String getName(int x, int y) {
            return "Terrain/grid/TerrainMountains/terrain_" + x + "_" + y + ".png";
        }
    }));
    
    terrain.setMaterial(terrain_mat);
    terrain.setLocalTranslation(0, -200, 0);
    terrain.setLocalScale(4f, 4f, 4f);
    game.rootNode.attachChild(terrain);
    
    TerrainLodControl control = new TerrainGridLodControl(terrain, game.cam);
    control.setLodCalculator( new DistanceLodCalculator(65, 4f) );
    this.terrain.addControl(control);

Theoretically the issue looks like the terrain_mat.setFloat(“slopeTileFactor”, 2); is the issue, try a larger number like 32 or 64…

Tried 32:

It seems like this stretched image is only on a grid type thing now. I thought the slope factor only changes how the “slopyness” the terrain has to be to get the texture on it? Or am I wrong?

from the TerrainGridTest.java in the jmeTests: “// slopeTileFactor: the texture scale for slopes”
so I assumed it was just to set the scale of the texture as you would the other colormaps.
I’ll look into the .j3md file and see if it says…

the .j3md file says the same and if I’m reading the .frag code right that’s all it does, sets the scale of the texture to paint.
looks like the slope factor is hard-coded and taken from the normal.

“return (blend.y * terrainColor + blend.x * slopeCol1 + blend.z * slopeCol2);”

blend is a vec3 normal vector

maybe run the jmeTests and try the TerrainGridTest.java code and see what it looks like, then experiment with that and your code? maybe a texture or vid card driver issue?
yeah grasping straws here :slight_smile:

EDIT: reminder the httpZipLocater is broken, so download http://jmonkeyengine.googlecode.com/files/TerrainGridTestData.zip and place into the JmeTests root project folder…

Confirmed, modified the test code to allow me to change the slopeScale in real time. slope factor never changed just the scale of the texture.
I do see similar "pixel-lines’ like you tho, right on the slope factor change… just not as severe but your snow texture might be making it more obvious…

http://radans.net/temp/test1.jpg
http://radans.net/temp/test2.jpg
http://radans.net/temp/test3.jpg
http://radans.net/temp/test4.jpg

1 Like

Got it working after an hour or so of debugging and comparing my code to the tests! It was this:

Texture rock = game.assetManager.loadTexture("Terrain/mountains.png"); ice2.setWrap(WrapMode.Repeat); terrain_mat.setTexture("slopeColorMap", rock); terrain_mat.setFloat("slopeTileFactor", 2);

In the second line here, I was setting my ice texture wrapmode instead of the rock texture. Feeling really stupid, but thanks for the help @radanz!

1 Like