eigenbom
|
|
« Reply #60 on: May 12, 2012, 11:30:45 PM » |
|
yeh thats heaps of vertices .. but there's still an issue with the domain scaling i think ..
try scaling the x and y coordinates so that one corner of the terrain is x=0,y=0, and the opposite corner is x=1,y=1 ...
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #61 on: May 13, 2012, 11:06:01 PM » |
|
What do you mean? Scaling the whole terrain for example: map = new Heightmap(data); mesh.ApplyHeightmap(map); mesh.ApplySize(32, 32);
mesh.Construct();
That makes sure that the terrain is of that size (32x32) make each quad 0.0457142857142857f in width and height. public void ApplyHeightmap(Heightmap map) { this.map = map;
this.columns = map.Data.GetLength(0); this.rows = map.Data.GetLength(1); }
public void ApplySize(int width, int height) { this.width = width; this.height = height; this.quadWidth = (float)width / (float)columns; this.quadHeight = (float)height / (float) rows; }
public void Construct() { ConstructVertices(); ConstructIndices(); ConstructNormals();
ConstructBuffers(); }
private void ConstructVertices() { vertices = new VertexPositionColorNormal[columns * rows]; for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { int index = x + y * columns;
// NOTICE NOTICE vertices[index].Position = new Vector3(x * quadWidth, map.Data[x, y], -y * quadHeight); vertices[index].Color = Color.Green; } } }
Is that what you meant? To scale the terrain (would you like me to scale the Y axis as well?) or something with vertex position settings like vertex.position = new Vector2(0.1f, 0.1f); which would place it near the top left of the terrain?
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #62 on: May 13, 2012, 11:34:45 PM » |
|
oh i just meant to input to the noise function should be scaled appropriately .. so in your example, you should be generating the heightmap data as...
map.Data[x,y] = NoiseSummed((double)x/columns),(double)y/rows));
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #63 on: May 14, 2012, 01:57:59 AM » |
|
Oh, okay, well in that case: private void ConstructHeightmap() { int columns = 700; int rows = 700;
float[,] data = new float[columns, rows]; float frequency = 2f; float amplitude = 12f;
PerlinNoise.Initialize();
for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { data[x, y] = (float)PerlinNoise.NoiseSummed((x / columns) * frequency, (y / rows) * frequency) * amplitude; } }
map = new Heightmap(data); mesh.ApplyHeightmap(map); }
Doesn't produce any hills and just generates a flat terrain...
|
|
« Last Edit: May 14, 2012, 02:03:26 AM by darestium »
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #64 on: May 14, 2012, 02:26:49 PM » |
|
I think you'll find that (x / columns) always equals 0, thx to the awesomeness of integer arithmetic.
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #65 on: May 14, 2012, 10:31:59 PM » |
|
Ugh, y u no implicit cast to a floating point value?!!! Okay, this private void ConstructHeightmap() { float columns = 700; float rows = 700;
float[,] data = new float[(int)columns, (int)rows]; float frequency = 2f; float amplitude = 12f;
PerlinNoise.Initialize();
for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { data[x, y] = (float)PerlinNoise.NoiseSummed((x / columns) * frequency, (y / rows) * frequency) * amplitude; } }
map = new Heightmap(data); mesh.ApplyHeightmap(map); }
Outputs that:
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #66 on: May 15, 2012, 12:25:57 AM » |
|
yeh thats look much better, increase amplitude until you get nice mountains
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #67 on: May 15, 2012, 12:36:44 AM » |
|
Okay, increased the amplitude to 78...
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #68 on: May 15, 2012, 01:51:50 AM » |
|
cool man that's starting to look a lot better!
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #69 on: May 15, 2012, 02:07:25 AM » |
|
So, should I start implementing ridged multi-fractal noise? Or keep playing with Perlin?
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #70 on: May 15, 2012, 02:32:21 AM » |
|
i'd implement ridged multifractal noise as it looks a lot better then i'd start texturing the terrain (e.g., you could blend between a grassy texture on the low plains and a rocky texture for the mountains) then the next steph would be to explore the spherised cube someone mentioned a couple of pages back.. lots of stuff to do .. enjoy!
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #71 on: May 15, 2012, 10:19:46 PM » |
|
What should I start implementing Ridged Multi-fractal noise off? Is it in da book? (STILL HASN'T ARRIVED - UGH!)
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #72 on: May 15, 2012, 11:09:53 PM » |
|
Might be a bit tricky without context, but here's Musgrave's original function (found here): /* Ridged multifractal terrain model. * * Copyright 1994 F. Kenton Musgrave * * Some good parameter values to start with: * * H: 1.0 * offset: 1.0 * gain: 2.0 */ double RidgedMultifractal( Vector point, double H, double lacunarity, double octaves, double offset, double gain ) { double result, frequency, signal, weight, Noise3(); int i; static int first = TRUE; static double *exponent_array;
/* precompute and store spectral weights */ if ( first ) { /* seize required memory for exponent_array */ exponent_array = (double *)malloc( (octaves+1) * sizeof(double) ); frequency = 1.0; for (i=0; i<=octaves; i++) { /* compute weight for each frequency */ exponent_array[i] = pow( frequency, -H ); frequency *= lacunarity; } first = FALSE; }
/* get first octave */ signal = Noise3( point ); /* get absolute value of signal (this creates the ridges) */ if ( signal < 0.0 ) signal = -signal; /* invert and translate (note that "offset" should be ~= 1.0) */ signal = offset - signal; /* square the signal, to increase "sharpness" of ridges */ signal *= signal; /* assign initial values */ result = signal; weight = 1.0;
for( i=1; i<octaves; i++ ) { /* increase the frequency */ point.x *= lacunarity; point.y *= lacunarity; point.z *= lacunarity;
/* weight successive contributions by previous signal */ weight = signal * gain; if ( weight > 1.0 ) weight = 1.0; if ( weight < 0.0 ) weight = 0.0; signal = Noise3( point ); if ( signal < 0.0 ) signal = -signal; signal = offset - signal; signal *= signal; /* weight the contribution */ signal *= weight; result += signal * exponent_array[i]; }
return( result );
} /* RidgedMultifractal() */
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #73 on: May 16, 2012, 12:01:10 AM » |
|
Mmmm... In C, what does "double Noise3();" create? It looks like a function - stuffs is passed to it, but no body is declared... I should really learn C one day...
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #74 on: May 16, 2012, 12:15:44 AM » |
|
you can exclude that, just replace Noise3() with your noise..
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #75 on: May 16, 2012, 10:18:13 PM » |
|
Cool, works! I'm playing around with the parameters in the ridged function and got the following: But since that's abit boring I tried adding a bit of perlin to make it more rough: Still quite boring though. Anyhow, I'll play around with the parameters and see what I get! Could you recomend any really cool parameters
|
|
« Last Edit: May 16, 2012, 10:45:12 PM by darestium »
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #76 on: May 16, 2012, 10:56:00 PM » |
|
i admire your enthusiasm, but that's not right. here's sample output from that exact function: note that it is rough in some parts and smooth in others, that's what you should be getting. maybe your domain scale is not right. keep at it, but don't complicate it by adding more perlin noise to it ..
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #77 on: May 16, 2012, 11:09:49 PM » |
|
Lol, thanks ... Mm... Well I really wouldn't know what I am doing wrong. I am using the normal Perlin Noise function (not summed) - am I meant to be using the summed function? Here is my ported code... class RidgedNoise { /* Ridged multifractal terrain model. * * Copyright 1994 F. Kenton Musgrave * * Some good parameter values to start with: * * H: 1.0 * offset: 1.0 * gain: 2.0 */ public static double RidgedMultifractal(double x, double y, double z, double H, double lacunarity, double octaves, double offset, double gain) { double result, frequency, signal, weight; int i; int first = 1; double[] exponent_array = new double[0];
/* precompute and store spectral weights */ if (first == 1) { /* seize required memory for exponent_array */ exponent_array = new double[(int)((octaves + 1) * sizeof(double))]; frequency = 1.0; for (i=0; i<=octaves; i++) { /* compute weight for each frequency */ exponent_array[i] = Math.Pow(frequency, -H); frequency *= lacunarity; } first = 0; }
/* get first octave */ signal = PerlinNoise.Noise(x, y, z);
/* get absolute value of signal (this creates the ridges) */ if (signal < 0.0) signal = -signal;
/* invert and translate (note that "offset" should be ~= 1.0) */ signal = offset - signal; /* square the signal, to increase "sharpness" of ridges */ signal *= signal; /* assign initial values */ result = signal; weight = 1.0;
for (i = 1; i < octaves; i++) { /* increase the frequency */ x *= lacunarity; y *= lacunarity; z *= lacunarity;
/* weight successive contributions by previous signal */ weight = signal * gain;
if ( weight > 1.0 ) weight = 1.0; if ( weight < 0.0 ) weight = 0.0;
signal = PerlinNoise.Noise(x, y, z);
if ( signal < 0.0 ) signal = -signal;
signal = offset - signal; signal *= signal; /* weight the contribution */ signal *= weight; result += signal * exponent_array[i]; }
return result;
} }
I could possibly be doing something incorrectly there... And here is the code I generate the terrain with (the first screenshot) private void ConstructHeightmap() { float columns = 700; float rows = 700;
float[,] data = new float[(int)columns, (int)rows]; float frequency = 6f; float amplitude = 48f;
PerlinNoise.Initialize();
for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { data[x, y] = (float)RidgedNoise.RidgedMultifractal((x / columns) * frequency, 0, (y / rows) * frequency, 4, 2, 8, 0, 18) * amplitude; } }
map = new Heightmap(data); mesh.ApplyHeightmap(map); }
and.. That terrain looks completely amazing (your screenshot)...
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
eigenbom
|
|
« Reply #78 on: May 16, 2012, 11:27:57 PM » |
|
that figure is in the book you are getting, and many more nice pics.. oop, i gotta run to dinner but here's some quick notes.. int first = 1; -> static int first = 1; (you only want it initialised once, not every time the function is called...!) also static double[] exponent_arrayalso, try starting with musgrave's recommended parameters ... and finally, start with one octave, render the output, then try 2 octaves, etc.. it should be fairly clear if adding more octaves is giving you detail in the right places.. good luck!
|
|
|
Logged
|
|
|
|
Hedgehodg
Level 1
...
|
|
« Reply #79 on: May 16, 2012, 11:56:19 PM » |
|
Oh, ok, well, I've just made those variables static class properties (C# doesn't support the deceleration of static variables in functions) Anyhow, here is what I've got after much experimenting (most parameters look REALLY weird, some look like some crazed alien has drawn runes on the terrain...) Still not what I would call aesthetically pleasing but I guess I'm getting there (and no flat bits?!)... float[,] data = new float[(int)columns, (int)rows]; float frequency = 4f; float amplitude = 28f;
PerlinNoise.Initialize();
for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { data[x, y] = (float)RidgedNoise.RidgedMultifractal((x / columns) * frequency, 0, (y / rows) * frequency, 1, 3, 4, 1, 2) * amplitude; } }
And I really can't wait for the book - I hope it arrives soon, I think I'll spend most of the time looking through the awesome terrain :D
|
|
|
Logged
|
Previously known as "darestium"...
|
|
|
|