Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This shader could be implemented like this:

shader_evaluate
{
   ...

   // direct lighting (both diffuse & specular)
   AiShaderGlobalsSetTraceSet(sg, shadow_set, shadow_set_inclusive);
   AiLightsPrepare(sg);
   while (AiLightsGetSample(sg))
   {
      ...
   }
   AiShaderGlobalsUnsetTraceSet(sg);

   // mirror Reflection
   if (sg->Rr_refl < 2)
   {
      ...
      AiShaderGlobalsSetTraceSet(sg, reflection_set, reflection_set_inclusive);
      AiMakeRay(&ray, AI_RAY_REFLECTED, &sg->P, &reflected, AI_BIG, sg);
      AiShaderGlobalsUnsetTraceSet(sg);
      ...
   }
}

 


An example render and its .ass file that demonstrates the different trace set cases follows:

Center

Image Removed

 

...

Image Added



options
{
 AA_samples 3
 xres 320
 yres 240
 GI_diffuse_depth 0
}

persp_camera
{
 name mycamera
 position 0.5 5 -5 
 look_at 0.5 0.2 0
 fov 38
 handedness left
}

point_light
{
 name mylight
 position 0.5 5 -2
 decay_type constant
}

standard
{
 name s1
 Kd 0.5
 Kd_color 1 0 1
 Ks 0.26
 specular_roughness 0.45
}

standard_tsets
{
 name s2
 Kd 0.5 
 Kd_color 1 1 1
 Kr 1
 reflection_trace_set "reflection"  # inclusive set
 shadow_trace_set "-shadow"     # exclusive set (this is parsed in the shader code)
}

plane
{
 name myplane
 shader s2
 normal 0 1 0
}

# "reflection" is used in the shader as an inclusive trace set, 
#     so only geometry tagged with it will be traced
#
# "shadow" is used in the shader as an exclusive trace set,
#     so only geometry NOT tagged with it will be traced

# invisible in reflections, visible in shadows
sphere
{
 shader s1
 trace_sets 2 1 STRING "xxx" "yyy"
 radius 0.4
 center -1 1 0
}

# this is visible to both refl and shadows 
sphere
{
 name centerSphere
 shader s1
 trace_sets 2 1 STRING "xxx" "reflection"
 radius 0.4
 center -0.2 1 0
}

# invisible to shadows, visible for reflection
sphere
{
 shader s1
 trace_sets 2 1 STRING "shadow" "reflection"
 radius 0.4
 center 0.6 1 0
}

# visible for shadows and reflections
# when no trace_set is assigned to a node, it is
# always visible to all rays
sphere
{
 shader s1
 radius 0.4
 center 1.4 1 0
}

# visible for shadows, invisible for reflections
# if any trace set is specified (even a null one)
# the geometry will participate in the trace set
# mechanism (visible by default for exclusive sets,
# invisible by default for inclusive sets)
sphere
{
 shader s1
 trace_sets 1 1 STRING ""
 radius 0.4
 center 2.2 1 0
}

 

 

...