I'm coding a procedural terrain generation based on this article from GPU Gems 1.
But using CPU (not GPU). I'm stuck at generating the procedural terrain. I just can't figure out how make a 3D texture the way it looks in the article (fig. 1-10). Am I missing something big here? Here is the code:
float CTerrain::DensityFunction(float x, float y, float z) {
CPerlin3DTexture perl_tex;
float noise;
uint32_t octaves = 3;
float amplitude[10] = {0.25,0.5,1.0,1.9,4.1,8.1,16.1,9,10};
float lacunarity = 1.5;
float freq[10] = {4.03,1.96,1.01,0.51,0.2487,0.12563,0.8013,0.39913, 0, 0};
uint32_t i;
noise = 0.0;
for(i=0; i < octaves; ++i ) {
noise += perl_tex.noise(x * freq[i],
y * freq[i],
z * freq[i]) * amplitude[i];
x *= lacunarity;
y *= lacunarity;
z *= lacunarity;
}
return noise;
}
Values (nx,ny,nz) = (128,128,10)
float ***CTerrain::GenerateDensityTexture(uint32_t nx, uint32_t ny, uint32_t nz) {
float step[3];
int32_t i, j, k;
step[0] = 1.0 / (float)nx;
step[1] = 1.0 / (float)ny;
step[2] = 1.0 / (float)nz;
for(i = 1; i < nx-1; i++) {
for(j = 1; j < ny-1; j++) {
for(k = 1; k < nz-1; k++) {
tex[i][j][k] = DensityFunction((float)i * step[0],
(float)j * step[1],
(float)k * step[2]);
}
}
}
return tex;
}
Help, anybody? This is what I get from the above code:
