Repeating a texture on a heightmap?

I’m working on a procedurally generated terrain engine, and have been doing ok so far. However, I have 1 problem. I don’t want any of the fancy grass/dirt/road mumbo jumbo that the Terrain.jm3d material uses. So, I’m just using Unshaded for right now. I’d like to have my terrain texture repeat over the entire large terrain… and it won’t. Here’s my code:



[java]Texture dirt = assetManager.loadTexture(

“Textures/test.png”);

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“ColorMap”, dirt);[/java]



Anyone know why this isn’t working?

Because of the uv coords, use the terrain material with just one layer if you want the heightmap-based terrain or do the mesh in blender.

when I tried doing it with just 1 layer, it did the texture stretched out as well. All I want is one single texture on the terrain, repeated.

Set the scale, it does repeat it.

Here’s what I do:



[java]



mat_terrain = new Material(assetManager,

“Common/MatDefs/Terrain/Terrain.j3md”);







Texture dirt = assetManager.loadTexture(

“Textures/test.png”);

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex1”, dirt);

mat_terrain.setFloat(“Tex1Scale”, 12f);



[/java]



And it paints the texture repeated, but also paints an un-repeated version of the texture overtop. Like it’s setting the texture as the alpha map as well. Do you know how to keep it from doing that?

Huh? Can you show a screenshot of that? You don’t need to set the wrap mode for terrain btw.





I just have it generating a gigantic random heightmap right now. The texture repeats, as you can see, but it’s also got a gigantic nonrepeating version overtop of it. Here’s the complete code for the program too (it’s full of bits and pieces that may or may not be used, I’ll warn you. This is my first ever project in both jMonkey and Java).





[java]

package jme3test.helloworld;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.renderer.Camera;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;

import com.jme3.terrain.heightmap.HillHeightMap; // for exercise 2

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

import javax.vecmath.Tuple3f;

import javax.vecmath.Vector2f;





import com.jme3.post.filters.BloomFilter;

import com.jme3.post.FilterPostProcessor;



import com.jme3.math.ColorRGBA;









/** Sample 10 - How to create fast-rendering terrains from heightmaps,

and how to use texture splatting to make the terrain look good. /

public class HelloTerrain extends SimpleApplication {



private TerrainQuad terrain;

Material mat_terrain;



public static void main(String[] args) {

HelloTerrain app = new HelloTerrain();

app.start();

}





public int random(float g){

Random number = new Random();

int f = number.nextInt();

number.setSeed(System.currentTimeMillis());

return (f
10);

}





public void random(){



//item.setText(""+(f*100.0f)%100);

}







@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(650);



//BLOOM_________



FilterPostProcessor fpp=new FilterPostProcessor(assetManager);

BloomFilter bloom=new BloomFilter();

fpp.addFilter(bloom);

viewPort.addProcessor(fpp);

bloom.setBlurScale(.5f);

bloom.setExposurePower(.0f);

//bloom.setExposureCutOff(1.0f);

bloom.setBloomIntensity(.002f);

//_________











mat_terrain = new Material(assetManager,

“Common/MatDefs/Terrain/Terrain.j3md”);





// mat_terrain.setTexture(“Alpha”, assetManager.loadTexture(

// “Textures/alpha.png”));





Texture dirt = assetManager.loadTexture(

“Textures/64x64.png”);

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex1”, dirt);

mat_terrain.setFloat(“Tex1Scale”, 32f);









int quadmapsize = 128; // the size of the map

int i = 0;

//float last = 344; // this is where you put in the random seed

//float current = 0;

//float factor = 5; // no idea

//float m = 2 ^ 80; // how often the numbers repeat. possibly effects size

//float constant = 1; // no idea

float size = 1f; // the size of the values

long seed = 123L;

int patchSize = 65;

float scalex = 10; // the size the map is scaled to.

float scaley = 10;

float scalez = 10;





Random number = new Random();

number.setSeed(seed);









float[] heights = new float[quadmapsize * quadmapsize];

do

{

//current = (((last * factor) + constant) % m);

heights = number.nextFloat() * size;

i = i + 1;

}

while(i <= (quadmapsize * quadmapsize) - 1);











terrain = new TerrainQuad(“terrain”,patchSize,quadmapsize + 1, heights);



/** 4. We give the terrain its material, position & scale it, and attach it. /

terrain.setMaterial(mat_terrain);

terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(scalex, scaley, scalez);

rootNode.attachChild(terrain);



/
* 5. The LOD (level of detail) depends on were the camera is: */

TerrainLodControl control = new TerrainLodControl(terrain, getCamera());

terrain.addControl(control);

}

}





[/java]









so… what gives?

The Terrain.j3md material is smart and won’t worry about the other textures if you do not include them, so there will be no performance hit. That way you can just have the one, repeating, texture.

@Sploreg said:
The Terrain.j3md material is smart and won't worry about the other textures if you do not include them, so there will be no performance hit. That way you can just have the one, repeating, texture.


do you know why it's painting two, then? As far as I know, I'm only telling it to paint one :P

Adjust the scale of that texture layer?

If your texture is perlin noise then this could actually be a single texture being looked at at a specific resolution.



Try changing the scale and see how different things look.

@zarch said:
If your texture is perlin noise then this could actually be a single texture being looked at at a specific resolution.

Try changing the scale and see how different things look.


so there's nothing in the code that would make it do this?

I tried using a different texture, and I tried messing with the scale. Same issue.



Could someone try plugging the code into jmonkey themselves to see if it’s just my computer? All you need to do is put some sort of 64x64 texture in the assets folder named “64x64.png”




@normen said:
Huh? Can you show a screenshot of that? You don't need to set the wrap mode for terrain btw.


Oh, I experimented around with this. I do need to it seems. If I don't it just paints the huge texture.

Read the terrain tutorials. Set up a proper jME terrain and make it work first, before attempting your own stuff. Texturing a terrain properly is not a trivial task.

@androlo said:
Read the terrain tutorials. Set up a proper jME terrain and make it work first, before attempting your own stuff. Texturing a terrain properly is not a trivial task.


Well, if you look at my code, you'll see that it's basically just built off the jme3 tutorial. Is there another tutorial I should look at as well? I really don't understand why it would be so complicated to get the engine to just paint a single repeating texture over the terrain without doing anything fancy.

I also tried passing it a solid red texture to use as the alpha texture (figuring that it would then just paint tex1 over everything, as I want). But then it tints everything red O_o. Interestingly, I tried another alpha texture that just had the same shade of red sprinkled around in it, and those patches worked perfectly well. No red tint. Maybe I need to create a completely transparent alpha texture?

When I get a chance later tonight, I'll fool around with it some more (and try to get the jme3test terrain files working too. I briefly glanced at them last night, but they didn't work. I haven't tried to figure out why yet, though).



EDIT: well, I think I may have solved it. I just made sure that the shade of red in the alpha texture was r255,g0,b0. And now it works. Perhaps in the future I'll experiment around with having the alpha map randomly generated as well, to vary up the landscape. For now, I'm just glad it does what I want it to :P.