Building 3D Objects : DFRM Guide

Introduction:

ArtMatic Voyager uses a unique approach to 3D objects modelling & rendering called Distance Field Ray Marching, DFRM for short. This document covers the details you need to know to create or modify 3D objects represented by distance fields (DF for short) and gives many practical guidelines. The technical information may help you to understand the reasoning behind the guidelines and develop your own techniques.

DFRM Concept

ArtMatic Voyager uses a technique called ray marching (http://en.wikipedia.org/wiki/Volume_ray_casting) to render images. Ray marching essentially calculates the intersection of the possible light rays between the observer and the scene by sampling along the ray. It is a slow process as the object or terrain have to be sampled many times to know where the ray intersects the object. Ray Marching is needed when the mathematics that describe the object are too complex to find intersections analytically, typically when the object is an entire procedural planet like in Voyager case.
By using distance fields Voyager can find the intersection of the ray with the surface of 3D object much more quickly than using the brute force technic of ray marching. This is because the DF field itself gives some information about the distance to the surface which allows the sampling to be much more efficient by converging quickly to the surface.
A distance field is just a scalar field where the value of the field gives a good (or exact) approximation of the distance to the surface.
The distance field does not have to be mathematically exact to allow proper convergence, but the more exact the distance estimate is, the faster the convergence will be. If the distance estimate deviates too much from the true distance the ray will miss the object (overshoot) if it overestimates that distance. Underestimation won't impair the ability to converge to the correct solution but the convergence will be slower.
A distance field function takes a space or plane coordinates and calculates an estimate of the distance from that point to the object surface. The object surface is those places where the distance is 0, that is the 'zero crossing' of the field. A value greater than 0 indicates a point inside the object with the field value indicating the distance from the surface. A value less than zero indicates a point outside of the object. ArtMatic's Geographic Clut color shader is useful for visualizing distance fields as its colors indicate distances.
A distance field can be 2D or even 1D. A 1D distance field is simply x or y or z provided they are unscaled. Thus you can directly use - y for example to create a DF infinite flat ground where y==0 defines a flat ground plane.
The simplest 3D distance field is a sphere. What is remarkable (and unique) is that the sphere equation is its own distance field equation. The field is described by this equation: R - sqrt( x^2 + y^2 + z^2) ( or R-length(x,y,z), 'length' being the euclidian distance) which comes from the sphere equation: x2 + y2 + z2 = R with R being the radius of the sphere. The minus sign is needed to adjust the field values so that the field is negative outside the sphere and positive inside. With the sphere the convergence can be done in a single step as the DF field R-length(x,y,z) gives you the exact distance to the solution. The field exist everywhere in space which makes DF objects non-local unlike with classical polygonal description.
One can see a distance field as a special kind of 'scalar field'. Scalar fields are non-directionnal (unlike vector fields) and non-local. This non-locality (field exist everywhere in space) makes the object information expand way beyond its boundaries. This property is quite interesting as a simple offset of the field value will expand or shrink the object.

DF fields can be manipulated in many ways impossible (or very difficult) with polygonal descriptions:
-DF fields can be blended or morphed together
-DF fields can be distorted by space distortion functions
-DF fields can be combined using boolean operators
-DF fields can be used as the input coordinates for another DF field calculation.

DFRM is useful not just because of its computational efficiency, but because very simple operations can be used to create complex and interesting shapes. Animating these transformations can create fascinating object morphs that would be very difficult to create with more traditional 3D tools.
DF fields provides an unified representation for very different types of objects, a tree, a fractal, a building, a sphere. This representation is non-local and independent of a particular topology. That makes morphing and combination of very different types of objects quite easy. Thus efficient and simpler technics for 3D modelling are possible with DF objects and ArtMatic Engine provides hundreds of functions designed for DF modelling.

ArtMatic 3D DF objects:

3D DF objects are created using ArtMatic Designer. Creating and modifying them requires a fairly good understanding of ArtMatic structure trees. Many pre-existing DF primitives are available in ArtMatic Engine to provide you with basic DF building blocks that you can combine using boolean functions. For the most part, you will use built-in ArtMatic components that generate distance fields and combine them (using the guidelines provided later) to create complex objects. Although advanced users can create their own distance fields, it is unlikely that you will ever need to create a distance field from scratch.

ArtMatic trees need certain properties to work as DF objects: Any 2D or 3D scalar function can be interpreted as a distance field as long as the field value provides a good distance approximation to the function zero crossing (the surface). 3D objects trees needs to be 3D which means they use the X,Y and Z global inputs. The field has to be negative outside the object surface and positive inside. All functions that are clamped to zero (positive only) cannot be used as a DF generating function.
A DF object is not necessary bounded and small. You can have one DF object describing an entire city or a forest. Using Compiled tree, there is virtually no limits in the number of functions and complexity of geometry you can have in a single DF object instance.


DF Modelling technics

Many times it is simpler to build a 3D object using 2D DF profile like the ones provided by 21 Profile Shapes # or 21 DF Curves # .
A 2D DF profile is just a DF field defined only in 2 dimension : it will be infinite in the undefined dimension. For example a 2D DF disc connected to (x,z) will render as an infinite column in Voyager because y is not specified.
Examples of basic modelling technics are located in Voyager Examples/DF Modelling/Basic technics

The most useful technics to work with 2D profiles are :


There are many ways to work with 3D DF fields and the techniques below can all be combined to achive quite complex geometry.


Shading DF Objects

Textured or not Voyager provides several rendering and shading options for DF objects. In general you will use the opaque mode but alternate modes can provides clouds and gazes, fuzzy objects, lights fields and transparent/translucent objects. Examples are provided in Voyager Examples/Shading & Rendering/folders.



Performance tips

When working on a slow computer or working with a particularly CPU-intensive DFRM based scene on any computer, you may find times when making adjustments become very difficult because the CPU is bogged down calculating the preview while you adjust sliders and other user interface controls. Or simply because feedback is too slow to be practical.
When this happens, there are a few tricks that you can use to improve the user interface's responsiveness.
Reduce render quality.
The first thing to try is setting the Render Quality setting to draft or good. In some cases, this provides a dramatic improvement. Work at the reduced quality setting until you actually need the higher quality. "Draft mode" now cut out any extra rays and should be used systematically when setting up a scene and positionning elements. In rendering using Best or Sublime quality is very slow and unnecessary most of the time. There are many cases where a Good or Better quality render is almost indistinguishable from a Best or Sublime render -- and the lower quality render may take 1/10th the time.
Make objects temporarily inactive.
With very CPU-intensive systems -- especially with object's that are reflective or transmissive or very slow like fractals -- it is often useful to temporarily make the object inactive in the ArtMatic Object inspector. While inactive make whatever adjustments you need (sun position, camera position, etc.) and then make the object active again. You may also temporarily turn off all reflections by setting quality to draft mode.
Make texture computation separate
Finding the intersection between the ray and the object is the most CPU intensive task with DF objects, especially if the object field is poorly convergent. Texture computation is not necessary at this stage and should be put in a CT (Compiled tree) set with the Compute only for colors. Sometimes the texture algorithm is much more complex than the object volume function and you really don't want it to be computed for every samples along the ray when it is only needed for the object shading. For constant colored objects or simple and fast colored textures it may be not worth to do that as there is a little overhead when using CT.
Temporarily change the sky mode.
If your scene uses objects and volumetric skies or the volumetric light sky mode, you may want to temporarily set the Sky Mode to Clear Sky or Cloudy Sky. Volumetric clouds and volumetric lights can be very cpu-intensive.
Turn off Cast Shadows and Ambiant Occlusion
The Cast Shadows option can dramatically increase the calculation time. In some cases, this option can increase rendering time by as much as a factor of 10. Turn it off until you need it. If you are rendering animation, you should render some test frames to see if the option is worth the added rendering time. Ambiant Occlusion can be set to none for each objects or is globally bypassed in Draft render mode.


Troubleshooting DF object

Object invisible
Make sure the object is not below ground, too small, or outside camera range.
Object artefacts
Artefacts in the rendering or shadows usually means the DF field is inaccurate and convergence poor. Revise the maths of the field or lower the field amplitude to make convergence safer.
Black screen
Camera is probably within the object. To fix this situation, move the camera outside the object's bounds. Otherwise it may be that the field has no more any "outside", that is, negative values that defines empty region around the object. Revise the maths of the field to ensure it does have an "outside".