Syphorlate wrote:
Yes I will do as you say. Indeed I have max density inside the sphere and zero density outside. So I'll interpolate the density or something.
EDIT: I tried to interpolate the densities but this makes it look even worse. I am surely not doing it right. Maybe you have some sample function where you create a sphere or something with smooth densities?
I don't have an example to hand, but the principle:
1) Compute the centre of your volume
2) For each voxel, compute it's distance to the centre.
3) Scale this distance by some amount, such that the density values cross the threshold (128) at the distance from the centre that gives you the size you want. You'll also want to invert the densities, as you want high density in the middle and low on the outside.
The distance changes smoothly from the centre moving out, so this should give you smooth densities and a smooth sphere.
With Perlin noise, I assume your function returns a float in the range 0.0 to 1.0? If so, you can map 0.0 to 0 and 1.0 to 255. However, you might improve quality by mapping 0.4 to 0 and 0.6 to 255 (assuming you want your boundary at 0.5). Values outside 0.4 or 0.6 would just be clamped to min and max.
Syphorlate wrote:
Also I was wondering how the smooth function works. I applied it to the whole volume but don't know if it worked.
You mean the smoothRegion() function? It basically just performs a blur on the volume data so that each voxel gets averaged with it's neighbours. Be aware it's replaced in the Git version of PolyVox though I'm working on something similar.
Syphorlate wrote:
And what about life editing the terrain. You said I can extract a smaller region of the volume or do I have to reextract the whole surface everytime I use the brush on the terrain? No that can't be. But how do I update the mesh then after a brush stroke?
Yes, you can extract a smaller region by passing a PolyVox::Region instance to the SurfaceExtractor's construcor. Conceptually you should break you terrain down into tiles of maybe 32x32x32 or 64x64x64, each with an associated mesh. When one of the voxels in the tiles changes you regenerate the mesh for the whole tile (should take a fraction of a second).