Trace Sets - Arnold Developer Guide
Trace sets give control over which rays are affected by which object. There are two types of trace sets:
- When a trace set is exclusive, rays are traced against all geometry except the tagged nodes.
- When a trace set is inclusive, rays are traced against tagged nodes, but also against nodes that are not tagged at all (see example .ass below).
Here is an example shader and .ass file using inclusive tracesets for a probe ray and a diffuse BSDF.
traceset.cpp
#include <ai.h>
AI_SHADER_NODE_EXPORT_METHODS(TracesetMethods);
node_parameters { }
node_initialize { }
node_update { }
node_finish { }
shader_evaluate
{
const AtString probe_set("probe_set");
const bool probe_set_inclusive = true;
const AtString diffuse_set("diffuse_set");
const bool diffuse_set_inclusive = true;
AtRGB diffuse_color(0.5f, 0.5f, 0.5f);
// trace probe ray along normal, turning the surface red on hits
AiShaderGlobalsSetTraceSet(sg, probe_set, probe_set_inclusive);
AtRay ray = AiMakeRay(AI_RAY_SHADOW, sg->P, &sg->Nf, AI_BIG, sg);
AtScrSample sample;
if (AiTrace(ray, AI_RGB_WHITE, sample))
diffuse_color = AI_RGB_RED;
AiShaderGlobalsUnsetTraceSet(sg);
// diffuse BSDF
AiShaderGlobalsSetTraceSet(sg, diffuse_set, diffuse_set_inclusive);
sg->out.CLOSURE() = AiOrenNayarBSDF(sg, diffuse_color, sg->Nf);
AiShaderGlobalsUnsetTraceSet(sg);
}
node_loader
{
if (i > 0)
return false;
node->methods = TracesetMethods;
node->output_type = AI_TYPE_CLOSURE;
node->name = "traceset";
node->node_type = AI_NODE_SHADER;
strcpy(node->version, AI_VERSION);
return true;
}
traceset.ass
options
{
xres 1024
yres 512
AA_samples 6
GI_diffuse_depth 4
GI_specular_depth 4
}
persp_camera
{
name mycamera
position 0 1 4
look_at 0 -0.2 0
up 0 1 0
}
skydome_light
{
name myskydome
intensity 1
color 1 1 1
camera 0.0
}
standard_surface
{
name mystd
base_color 0.4 0.8 0.4
}
sphere
{
shader mystd
matrix
1 0 0 0
0 1 0 0
0 0 1 0
-1.5 0 0 0
trace_sets 1 1 STRING "probe_set"
}
sphere
{
shader mystd
matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 0
trace_sets 1 1 STRING "diffuse_set"
}
sphere
{
shader mystd
matrix
1 0 0 0
0 1 0 0
0 0 1 0
1.5 0 0 0
trace_sets 1 1 STRING ""
}
traceset
{
name myshader
}
plane
{
name myplane
normal 0 1 0
point 0 -0.5 0
shader myshader
}
The resulting render looks like this, with the traceset shader assigned to the floor. The left sphere has the probe trace set assigned, which results in a red disk on the floor where the probe rays hit the sphere. The middle sphere has the diffuse trace set assigned, and as a result, cast shadows and reflections on the floor. The right sphere has an empty list of tracesets, and affects neither the probe rays nor the diffuse BSDF.
