### 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 :

• Intersection:
You can intersect two 2D DF fields defined in different planes to create a 3D object. Think of a 2D DF field as a “profile path” where the zero crossing of the field define the path shape. Used directly in 3D these profiles will be infinite in the other axis, typically z if the 2D DF component is connected to (x,y) or y if the 2D DF is connected to (x,z).
By intersecting a (x,y) profile with a (x,z) profile you will ensure the object is bounded in all dimensions. The result will be a 3D object that look like profile A in one direction and profile B in the perpendicular direction. The intersection is typically performed using Boolean (logical) operators like 21 Logic tools # or S:P Logic & Profiles but for a basic intersection a simple Minimum function will work.
A 2D triangle in (x,y) intersects with a 2D ellipse in (y,z)

The intersection can itself add details to the geometry using various flavors of the boolean operator. "Edged intersect" for example will add edges at the intersection. A 2D triangle in (x,y) Edged - intersects with a 2D red ellipse in (y,z)

• Sweeps:
As DF fields can be used as the input coordinates for another field calculation it is possible to use a 2D DF field as an input (x or y or z) for another DF function either 2D or 3D. This will basically 'sweep' the object B along the profile of object A. For example to get a torus sweep a disc in (x,y) along a circular path defined by disc profile in (x,z). Sweeping any profile with a disc will create a revolution object, like a glass or a bottle.
Usually you will connect directly a 2D profile to one coordinate input of another 2D profile. Another way is to use the 32 Revolution & Sweeps # component that provides many paths for sweeps.
When 2D uv coordinates are needed you may also use the 34 uvid Sweep Volumes # component that will perform sweeps internally and return uv as well as the DF field itself.
A 2D pentagon (21 Profile Shapes #) sweeps along an Archimedes spiral path (21 DF Curves # )

• Cross Sweep:
A cross-sweep will be achieved when a 2D profile is connected to two others 2D profiles, one fed in x input, the other in y input.
Quite complex models can be achieved that way.

A 2D Triangle and a 2D disk (21 Profile Shapes #) feeds coordinates of a 21 DF Curves # object.

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

• Intersection, Union.. etc
Most of the time you will build complex 3D objects by mixing various 3D DF fields using Boolean (logical) operators like 21 Logic tools #
Many examples of Logical operators usage are located in Voyager Examples/Components/Logic tools

• Morphing fields
Use the Morph components to make a morphed union of 2 objects. For Scalar fields you can use the Math tools # Morph fuction. To morph 2 colored DF object you will use the 24 tile Packed Morph.

A cyan sphere array morphed with an infinite red DF plane

• Sweeps & cross-sweeps
Sweeps can also work between 3D and 2D DF objects. You 'sweep' a 2D DF profile along a 3D DF field by feeding the 3D object field to one of the 2D DF profile coordinate.

A 2D arc curve sweep along an four sided 3D pyramid

It is also possible to sweep a 2D profile along the intersection of two 3D DF volumes : In that case the 2D profile will trace the shape of the intersection contours.
A 2D disc sweep along the intersect of a sphere and a four sided pyramid

• Space Deformation
A very efficient way to shape the DF object is to add a space-distortion function to modify the incoming space. Mirroring and Rotations are very often used to force the object to be symmetrical or to have various number of rotationnal symmetries.
3D Plane Mirror , 3D Mirrors & Rotates # , and 3D Mirrors & Offset # provides 3D Mirroring and Rotations functions.
A 3D fractal displacement like 3D Fractal displace will completey change the look of a simple sphere. Some displacement functions are specifically designed to deform DF fields like 3D Distorts & Bend #

A DF sphere and ground with 3D space displaced by 3D Fractal displace

• Displace the field value
To add a bump texture or small details you can simply add a little bit of a 3D noise function to the field. A number of 3D DF noise and 3D DF pattern functions are available in ArtMatic Engine to add textures at the geometry level, but for small details almost every ArtMatic functions can be used to modulate the DF field.
Examples of 3D noise added to a sphere : 3D Ridged Fractal , 3D Fractal Bubbles

• Instanciation by Space manipulation
The most efficient way to duplicate and instanciate objects is to manipulate space so that a single object will appear at many places at once. A simple 1D Modulo function will repeat the object in one axis infinitely for example. One may use voronoi diagram (2D or 3D) to partition space into many cells, each having its own coordinates. ArtMatic Engine provides many components that create instances by tiling or partitioning the space :
3D Repeats and Tile, Jitter Spherical, Jitter Axial, Motion Cluster, 3D Motion Path render
The difficulty with this technic is the DF field has to be well centered and relatively far from the space cell boundaries where space coordinates will suddendly be discontinuous and jump to totally unrelated values. To maintain an accurate Distance estimate and avoid overshooting one can clamp the DF value when using these to not be below a fixed value.
When the tiling is regular and space symmetrical the problem vanishes as the space is coherent even at cell boundaries.

• Carving
A 3D pattern or noise component can provide details to any 3D volume using S:P Logic & Profiles displacements functions like 'Displace','Chisel displace' and 'Circle displace'. They will carve the volume along the contours defined by the zero crossings of the 3D volumetric pattern.

An elongated sphere (XYZ Shapes # ) carved with a voronoi split pattern(3D Bubble & skins)

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.

• Ambient occlusion
Ambient occlusion approximates how much light coming from the environment is blocked by the object in addition to true shadows. It provides a kind of clarity and realism not possible without it especially when directionnal sun light is absent like in overcast sky situations. When rendering rough textured terrains or fractal objects, ambient occlusion is especially helpful for bringing out the scene details. Ambient Occlusion estimates the amount of non-directional ambient light that reaches various areas (as opposed to shadows which are caused by directional light). AO is independent of the main light direction. Concave or hard-to-access areas will be darkened. It can be applied to terrains and objects independently. Ambient occlusion affects ambient and diffuse lighting but not specular and reflective light channels because it mostly simulates the blocking of light coming from any direction but not the light hitting the surface from a single direction.
Ambient occlusion can take some time to compute and is set to OFF in draft mode.
DF objects provides several algorithm for Ambiant Occlusion. The Low freq AO is the most accurate but aslo the slowest.
There is a global preference for the AO Radius in the main preferences dialog but each object in a scene can have its own AO amount setting.
AO Amount. When the AO amount is less than 100% only convex surfaces are affected. Amounts greater than 100% tend to affect all areas but may leave convex areas intact.
AO Radius Preference. Voyager scenes can have varied needs. Preferences contains a global control for the Ambient Occlusion Radius that allows you to adjust the AO for the scene's context. On a landscape dominated by large-scale features, a size of 50 meters or so will give good results. Changing the radius will influence features of certain size or detail. The same object can look quite different with different settings. So, it is worth some experimentation to find the setting that gives you the results you prefer.
Ideally, AO should be scale-independent but this is currently impractical because of the enormous impact it would have on render time so AO radius is scaled by the DF object scale when below and above 100%. This allows in the same scene to have a 40 meter A0 radius for terrains and large DF structures while still have correct AO for a small 20 cm object in the foreground.

Here is an example of a fractal DF object entirely shaded by Ambient occlusion

• Using extra outputs
When an ArtMatic DF object has one or more extra outputs, the extra output can be mapped to various shading properties such as wetness, self illumination or reflectivity. Using extra output (or X-outs for short ) to modulate texture shading can greatly enhance realism and visual complexity. For example you may have a model that provides a texture for day light and a texture for night in an X-out channel. Turning on the channel by selecting "Self illumination" is easy and you will typically do it for night renderings without having to change the model itself.
The extra output can be mapped to:
'nothing' : the way to turn off a particular shading option.
'Self illumination' Unlike 'Ambiant & Wetness' which sets the amount of diffuse reflection coming from the environment 'Self illumination' adds its own light to the scene giving the impression of a luminous object. The self illumination light color is the X out color or white if X out is scalar.
'Wetness level' control the specular amount of light coming from the environment. This light can be filtered by the X out color if any.
'Ambiant & Wetness' control the amount of light coming from the environment, diffuse and specular. This light can be filtered by the X out color if any.
'Reflection level' Mirror reflection of light from the environment. The reflected light can be filtered by the X out color.

Auto Mapping of X-out option: The following letters put at the end of an ArtMatic 3D DF object multi outputs file will cause Voyager to set a proper shading option default when opening/importing a new AM system. The letters can be combined in any order up to 3 letters ("ri", 'wir" "wbi" etc) when multiple X-outs are used but a space needs to be present before to not get confused with letters in the name itself.
'i': sets corresponding output to "Self illumination color & level",
'r': sets corresponding output to "Reflection color & level",
'w': sets corresponding output to "Wetness level / Specular color ",
'b': sets corresponding output to "Bump Map ",
'l': (in first position only) will set the first extra output to be assigned to "Volumetric Light" in the mode 'opaque + light',
't': (in first position only) will set the first extra output to be assigned to "Transparent" in the mode 'opaque + Transparent'

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".