Voxel Maps with UV texture
The basic voxel algorithm is now implemented and I can leave the “painful” field of byte-arithmetic and countless lookup tables. Back in my library it is possible to reuse the standard classes for projection and texturing.
The first simple approach for texturing is the use of UV maps. For each sample a “virtual cell” is created with the dimension [0..1][0..1]. The endpoints of an Isosur-Face lie within this cell. The resulting coordinates are mapped to a uv texture:
This is an example for the object definition with an arbitrary texture:
NSString* voxelMapIngredientName = @"voxelMap";
YAIngredient* voxelMapIngredient = [world createIngredient:voxelMapIngredientName];
[voxelMapIngredient setFlavour:Terrain];
[voxelMapIngredient setTexture:@"terrainTex.png"];
[voxelMapIngredient createModelfromTriangles:voxelData];
The random cell is now textured:
The samples of a voxel-map are accessible like in a multidimensional array. By definition samples with negative density are outside of a body, samples with positive density are “inside”. Here is an example of cube with holes:
const int vMapDimension = 32 * 2;
YAVoxelMap* voxelMap = [[YAVoxelMap alloc] initDimensions:vMapDimension :vMapDimension :vMapDimension];
for (int x = 0; x < vMapDimension; x++)
for (int y = 0; y < vMapDimension; y++)
for (int z = 0; z < vMapDimension; z++)
if(x == 0 || x == (vMapDimension - 1) || y == 0 || y == (vMapDimension - 1) || z == 0 || z == (vMapDimension - 1))
[voxelMap setVoxel: -10 x:x y:y z:z];
else {
if( ((x % 10 > 2 && x % 10 < 8) && ( y % 10 > 2 && y % 10 < 8)) ||
((z % 10 > 2 && z % 10 < 8) && ( y % 10 > 2 && y % 10 < 8)) ||
((x % 10 > 2 && x % 10 < 8) && ( z % 10 > 2 && z % 10 < 8))
)
[voxelMap setVoxel: -10 x:x y:y z:z];
else
[voxelMap setVoxel: +10 x:x y:y z:z];
}
[voxelMap calcIso];
This voxel map consists of 262144 samples and looks like this:
Obviously the mapping quality (depth) can be improved. Instead of ads, deferred shading with lightning, shadows and reflections of a HDR image can produce better results but this was already discussed in a previous post.
It is still possible to render this image with 60fps and it is therefore suitable for realtime applications:









