What is the meaning of the range of values voxels can have?

Questions & AnswersCategory: ProgramingWhat is the meaning of the range of values voxels can have?
Jason asked 4 years ago

I understand that all the generators (but ultimately the combiner) are going to output a value [-1, 1].   And, I get that -1 means totally inside and 1 means totally outside the terrain.   I was originally just returning -1 or 1 from my combiner, which yielded fine looking, but very blocky, terrain.   To fix that, I started looking into using the full range.
From reading the docs and guessing what the range meant, I assumed that I should think of -1 to 1 as a description of the volume of the voxel that is filled with ‘land’.   So, if the voxel is 100% filled with ‘land’ then I’d return -1.   If its 75% filled, I’d return -0.5.   If its 50% filled, I’d return 0.   If its 25% filled, I’d return 0.5.   And 0% filled (e.g. sky), I’d return 1.
If I took an example in 2D, I would predict something like this for the voxel values:
http://exile.saturnvalley.org/pub/uTerrains/voxelVals/example.png
To validate, I booted the example and clicked on a few voxels.   It was readily apparent that I was very wrong about the meaning of the range … based on these sort of examples:
http://exile.saturnvalley.org/pub/uTerrains/voxelVals/wayoff.png
http://exile.saturnvalley.org/pub/uTerrains/voxelVals/wayoff2.png
http://exile.saturnvalley.org/pub/uTerrains/voxelVals/notsobad.png
The last one is roughly what I’d have guessed, but I think that’s just coincidence.   Really, all the values for voxels near the land\sky interface seem less than ~0.1 and most are less than 0.01.
I’m sure I’m just missing something obvious, but could you explain why the above values are what they are and explain the meaning of the values intermediate to -1 and 1 that I should be returning from my generator?

0 Answers
uTerrains Staff answered 4 years ago

You are not so far from the truth, but no, the voxel value does not refer to the volume of the voxel filled with land. It’s more like the distance of the voxel from the terrain surface (negative if it’s inside).
Surface is computed by interpolating the value of 2 voxels that have a different sign. To be exact, if p1 is the position of the first voxel v1 and p2 is the position of the second voxel v2, then the surface is at position given by:

float mu = (ISOLEVEL - v1.Value) / (v2.Value - v1.Value); // ISOLEVEL = 0
return new Vector3 (p1.x + mu * (p2.x - p1.x), p1.y + mu * (p2.y - p1.y), p1.z + mu * (p2.z - p1.z));

This is unintuitive, but basically is you have one voxel with -1 and the other with 1, surface will be exactly between them. What is funny is that surface will be the same if you have -05 and 0.5 for example. In the end, voxel value is related to the distance of the voxel from the surface, but this is relative to the other voxel value.
A few examples:

 

o (1.0)
|
|
x <= surface
|
|
o (-1.0)

o (0.2)
|
|
x <= surface
|
|
o (-0.2)

o (1.0)
|
|
|
x <= surface
|
o (-0.2)

o (0.002)
x <= surface
|
|
|
|
o (-1.0)

o (1.0)
|
|
|
|
o (0.0) <= surface