How to scale textures on a terrain quad

This will scale textures on a TerrainQuad just like you scale it on a Cube:





public void scaleTerrainTexture(TerrainQuad terrain, float scale)

{

for(int i=0;i<terrain.getChildren().size();i++)

{

for(int j=0;j<((TerrainQuad)terrain.getChild(i)).getChildren().size();j++)

{

for(int k=0;k<((TerrainQuad)((TerrainQuad)terrain.getChild(i)).getChild(j)).getChildren().size();k++)

{

((TerrainPatch)((TerrainQuad)((TerrainQuad)terrain.getChild(i)).getChild(j)).getChild(k))

.getMesh().scaleTextureCoordinates(new Vector2f(scale,scale));

}

}

}

}



Note that i am not sure that this is the most efficient way to do it, or if it will cause problems.



I spent quite some time trying to figure this out, so i thought i would share.

That should work.

You can also set the texture scale in the TerrainLighting material using the parameters for each texture layer:

matTerrain.setFloat(‚ÄúDiffuseMap_0_scale‚ÄĚ, 2);

matTerrain.setFloat(‚ÄúDiffuseMap_1_scale‚ÄĚ, 3);

matTerrain.setFloat(‚ÄúDiffuseMap_2_scale‚ÄĚ, 0.5f);

etc.

I tried doing that, and many different things. I am not sure why setting the texture scale in the shader was not working for me. I tested it a few times and how i wish it worked. Maybe it was because i am only using one texture and no alphamap?

What material are you using? TerrainLighting.j3md kind of needs the alpha map to draw anything.

1 Like
@clickity said:
I tried doing that, and many different things. I am not sure why setting the texture scale in the shader was not working for me. I tested it a few times and how i wish it worked. Maybe it was because i am only using one texture and no alphamap?


one texture and no alphamap ? :?

Maybe you just use Unshaded/Lighting material? :roll:

if yes, then you always can use Terrain Material with random alphaMap + 3 textures set as the same one.


if you use Terrain material, then
matTerrain.setFloat(‚ÄúDiffuseMap_0_scale‚ÄĚ, 2);
matTerrain.setFloat(‚ÄúDiffuseMap_1_scale‚ÄĚ, 3);
matTerrain.setFloat(‚ÄúDiffuseMap_2_scale‚ÄĚ, 0.5f);

should work, but try to use bigger values like 64f
1 Like

Lol, I guess i could probably use a flat color alpha map or just add the the 1 texture to all RGB values. I had not considered that. Thank you.



Btw, using non terrain based materials to scale did not work for me. Anyway, I hope this thread helps someone with a similar problem.