sj_trace


sj_trace is a shader letting you trace several types of ray in several directions.
In the standard tracing shaders, the tracing direction (for instance for reflections or refractions) is computed internally by the shader.
Also, the starting point of the ray is alway the current hit point.
sj_trace instead exposes the type, origin and direction of the ray to be traced.
For instance, you can decide to trace a refraction ray along the reflected direction, or along a custom-defined one, and also to shift the origin of such a ray.
So, it's to be used in particular cases, such as when you want to shift the reflection direction a little bit, without having to move the reflected object, or, for instance, to check for the thickness of the hit object before tracing it refractive. See the examples below.

Download (for both Softimage and Maya) and this doc's example scenes for Softimage (2010 and above).



Output:

The shader returns the hit color (for regular rays), together with the travelled distance, the computed direction and the hit/no hit result.
Probe rays do not return a color.
None rays only return the direction, that can be used as input of a second sj_trace.

Input:

Type: type of ray to be traced. Options are Probe, Eye, Reflection, Refraction, Environment, None.

On Hit Override: if On, and if the ray hit something, On Hit color is returned instead of the traced color. This is also the color returned for hitting Probe rays.

On No Hit Override: if On, and if the ray did not hit something, On No Hit color is returned instead of the traced color. This is also the color returned for not hitting Probe rays.

Origin: the origin of the ray. You can use the Current Point or a Custom Origin.

Direction: the direction of the ray. Options are
Current Direction: the direction of the incoming ray is used.
Reflection: the specular reflected direction.
Glossy Reflection: a glossy reflected direction. The magnitude of the glossiness is defined by Gloss.
Refraction: the refracted direction, according to Index Of Refraction.
Glossy Refraction: a glossy refracted direction, depending on both Index Of Refraction and Gloss.
Custom: Custom Direction is used.

Trace backfacing: forces tracing even if the current normal direction backfaces the computed tracing direction.

Examples:

The opening image shows an example of a simple case: shifting the reflection over the grid. sj_trace traces reflected, but the origin of the ray is shifted (State Point + Shift) of 5 units along the negative X. So, points of the grid on the right side behave as if they were shifted toward left before tracing the reflection.

In a little more complex setup, we can use an object tangent vector to shift the reflection direction.
In the example below, the torus XSI_Model_Map node returns the tangent vector along the u direction of the texture projection.
So, it's a vector that goes around the torus, parallel to the xz plane. XSI_Model_Map returns the vector encoded in the color space (0..1), so we first decode it to (-1..1), and this is the vector that goes out of C2V. This is then multiplied by a scalar (the Mul node), and added to the reflection direction that is computed by the first sj_trace node. Note that this node does not trace, it only computes a direction.
So, by adding a vector we are simply bending the reflection direction along the tangent to the torus surface.
The resulting direction is connected to the Custom Direction of the second sj_trace, which uses this direction to trace a reflection ray.
Note that there is no need to normalize the custom direction, sj_trace does it for you.
The result is then simply mixed with the standard lambert node.
In the first snapshot, the scalar multiplier in Mul is set to zero, so the reflection is not shifted at all.

But below you can see the effect setting Scalar Input to 2, 1 (top row), 0, and -1.


In this scene, there are no lights. We use sj_trace to trace the small yellow sphere, and treat it as if it was a light.
Its position is LightPos, so subtracting the state Point from it, you have the direction from the rendering point to the "light".
So, sj_trace always traces a refraction ray (could also be reflective, it doesn't matter) pointing at the yellow sphere.
The returned color (yellow) is multiplied by the incidence (Dot) between the tracing direction and the surface normal for a lambert look.
Also, the traced length is tested against the distance to the yellow sphere. If they differ at max of 0.2 units (the sphere radius), it means that the ray actually reached the sphere. Else, it meanss that the ray toward the sphere hit something else (for instance the red cube) and in this case (InRange=false) black is returned (ColorOrBlack).
You can expand this case to manage many "point lights", or also to trace an environment map with bright spots whose direction if known.

Another possible use is for overriding a visibility flag. As mentioned, it is perfectly legal to trace any kind of ray in any direction, so for instance tracing a refraction ray in place of a reflective one, yet getting the same result (both types of ray return the traced color).
In this example, the left grid is a regular reflective lambert one. The blu sphere is not visible by reflections, so you don't see it reflected.
The right grid traces a refractive ray along the reflection direction, so it renders also the blu grid.
Note also that both grid are invisible to reflections, so you only have sj_trace tracing the left grid, and not the opposite.