Bilinear Interpolation of a heightmap array

So, I decided to research Perlin noise for the heightmap generator I’m making. My discovery? It’s over my head. But one thing I took away from my research is that adding together noise will result in a fairly convincing-looking heightmap, provided the noise is “blurred” so that there aren’t any rough edges. And therein lies my problem. Although I have a blurring function (it basically samples all the points surrounding a given point on the heightmap and averages them), it doesn’t seem to be sufficient. So I’m hoping to get some sort of bilinear interpolation algorithm working. I found these links:



http://en.wikipedia.org/wiki/Bilinear_interpolation



How to Use Perlin Noise in Your Games – Dev.Mag



http://freespace.virgin.net/hugo.elias/models/m_perlin.htm



Problem is, the Wikipedia article is basically Egyptian to me, and the other two don’t really explain how bilinear interpolation would actually work. So I was wondering if anyone could help me out a little. How exactly does Bilinear Interpolation work (the “for dummies” version)?

Bilinear interpolation is used for points that lie between the integer points. You should use the same size texture as the heightmap, then there will be no need for that. If you use a 512x512 terrain, then use a 512x512 perlin noise.



A perlin noise should not be blurred using averages. Or bilinear interpolation for that matter. It normally uses cubic interpolation.



If the terrain is rough, it could be because of a crappy noise, but it could also be from using a too low resolution terrain (too few vertices per unit area). A 1024 terrain with a 256 heightmap will be blocky.



There are methods in the heightmap class to smooth terrains also btw. Both “smooth” and “erodeTerrain” can be run after load(), and they cause the terrain to become a bit less jagged.

@androlo said:
Bilinear interpolation is used for points that lie between the integer points. You should use the same size texture as the heightmap, then there will be no need for that. If you use a 512x512 terrain, then use a 512x512 perlin noise.

A perlin noise should not be blurred using averages. Or bilinear interpolation for that matter. It normally uses cubic interpolation.

If the terrain is rough, it could be because of a crappy noise, but it could also be from using a too low resolution terrain (too few vertices per unit area). A 1024 terrain with a 256 heightmap will be blocky.

There are methods in the heightmap class to smooth terrains also btw. Both "smooth" and "erodeTerrain" can be run after load(), and they cause the terrain to become a bit less jagged.


The problem isn't that my textures are blocky or the terrain is too low-res... the problem is with generating the actual heightmap. I'd like to use Perlin Noise or something like that, but as I said, it is just completely over my head. So what I was hoping to do was generate several interpolated heightmaps (interpolated so that the lower octaves don't just look like a bunch of big blocks), then blend them together. The problem is, I don't understand how to do bilinear interpolation. In fact, I don't understand a lot of this :P.

Truthfully, any sort of help with understanding heightmap generation would probably be helpful.

If you want to generate a noise procedurally, maybe take a look at the terraingrid examples in the jME-tests. The terrain system has a built in noise generation system. There isn’t much javadoc in it (if any at all), but if you understand noise it’s not hard to figure out, or if you look at the terrain grid examples.



EDIT: The noises are put in float buffers. I think you could put them in arrays instead if you’re gonna use terrains, because those heightmaps are arrays.



Of course you wouldn’t be able to add them directly to a mesh and make a super awesome noise man anymore (I don’t know the float buffers are really for, textures i guess). :smiley:

Ok, I’ll take a look. Thanks.

Yeah, I don’t really understand it at all :frowning:



From what I can see, though, it doesn’t take a “seed” into account, so it would produce random results every time, rather than predictably random results, yes? If so, that wouldn’t work for my plans anyway.



I’m gonna do a bit of reading on other types of terrain generation (such as here http://www.gameprogrammer.com/fractal.html). Any help at all on noise generation would be appreciated.

Yeah the noise lib has absolutely no documentation which to my mind makes it useless. I instead used the Perlin noise generator from java3d, you can find source using google.



Then I do something like this (you have to adapt to your conditions):



[java]

private static final float PERLIN_BASE_SCALE = 128.5f;



float xlarge = (float) (terrainCoordinateX) / (PERLIN_BASE_SCALE / 1) + 0.01f;

float ylarge = (float) (terrainCoordinateZ) / (PERLIN_BASE_SCALE / 1) + 0.01f;

double large = perlinNoiseGenerator.noise2(xlarge, ylarge);







float xsmall = (float) (terrainCoordinateX) / (PERLIN_BASE_SCALE / 8) + 0.01f;

float ysmall = (float) (terrainCoordinateZ) / (PERLIN_BASE_SCALE / 8) + 0.01f;

double small = perlinNoiseGenerator.noise2(xsmall, ysmall);



float height = (float) (256f * large + 32f * medium + 8f * small);

height = FastMath.clamp(height, -1024.0f, 1024f);

[/java]



Maybe your alias problem is that you input integer values for x & y to the generator, which does not work (http://www.programmersheaven.com/2/perlin).

Java3d, huh? I’ve never used it. Does it come with jMonkey, or do I need to download it somewhere?

@jefequeso said:
Java3d, huh? I've never used it. Does it come with jMonkey, or do I need to download it somewhere?


Sorry I was in a rush previously. I meant to say I found one at http://www.j3d.org/

Here is a link to the javadoc: http://code.j3d.org/javadoc/org/j3d/texture/procedural/PerlinNoiseGenerator.html

I really should think before writing :)

awesomeness. Thanks a bunch!

@jmaasing said:
Sorry I was in a rush previously. I meant to say I found one at http://www.j3d.org/

Here is a link to the javadoc: http://code.j3d.org/javadoc/org/j3d/texture/procedural/PerlinNoiseGenerator.html

I really should think before writing :)


erm... ok, really noobish question (I'm new to Java as well as jMonkey):

what do I download, and where do I put it to be able to import it? Or will this just provide source code to learn from?
@jefequeso said:
erm... ok, really noobish question (I'm new to Java as well as jMonkey):

what do I download, and where do I put it to be able to import it? Or will this just provide source code to learn from?

Only source code.
@jmaasing said:
Only source code.


Is it possible to simply import the .jar file to use? I could write my own code based on what they have, but it might be easier to just use the freely available option :P. Or are there some legal elements to this I'm not aware of?

My sixth sense is telling me that trying to tackle procedural generation while learning Java and jMonkey at the same time was a poor idea :P.
@jefequeso said:
Is it possible to simply import the .jar file to use? I could write my own code based on what they have, but it might be easier to just use the freely available option :P. Or are there some legal elements to this I'm not aware of?

My sixth sense is telling me that trying to tackle procedural generation while learning Java and jMonkey at the same time was a poor idea :P.

I didn't know they had binary downloads so yeah you could use the JAR-file I guess.
As for legal I don't know, it has to do with your application and your requirements and what you plan to do and has nothing to do with jME.