Vectron

Vectron allows adding procedural geometry using signed distance fields (SDF).

This is a simple example defining a sphere:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include <octane-oslintrin.h>

shader Vectron(
    float radius = 1    
        [[float min = 0, float slidermax = 1e4, float sliderexponent = 4]],
    vector center = 0,
    output _sdf out = _SDFDEF)
{
    out.dist = distance(P, center) - radius;
}

An Vectron shader has exactly one output, which is a struct called _sdf.

A Vectron shader can have inputs of this type as well, this will allow you to connect other SDF shaders to this shader.

These inputs and outputs should be initialized with the _SDFDEF macro. This macro is only a placeholder, Octane always initializes these variables with a value computed at run time.

_sdf fields

Field Meaning
int objId Object ID
int matId Material ID
float u, float v Texture coordinates
float dist Signed distance (positive outside the object)

The material and object IDs are opaque identifiers. The initial values of the output variable correspond to the material and object layer on this Vectron node. You must either keep these values, or assign a value from an _sdf input.

Global variables

Within SDF shaders the following global variables are available:

Variable Meaning
point P Position where the SDF needs to be evaluated (see below)
vector I Ray direction

The P global variable

Inside Vectron shaders, P always refers to the position in a local coordinate space for this node. This avoids boilerplate to take transforms into account, and allows us to implement features like domain transforms.

The node trees connected to the inputs of a Vectron node may contain projection inputs. Position based projection nodes (eg. XYZ to UVW, Box mapping) connected to such inputs with the coordinate space set to Object space will also use this P value.


Last update: November 3, 2023