Page tree

Versions Compared

Key

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

...

  • int numPts: The number of points in the shading context. All non-uniform values can be assumed to have this length.
  • struct scTraits: This struct contains several informational fields.
    • eyePath: A flag which is set to 1 if the shading context was created in the context of an eye path.
    • lightPath: A flag which is set to 1 if the shading context was created in the context of a bidirectional light path.
    • primaryHit: A flag which is set to 1 if the shading context is directly visible to the camera.
    • missContext: A flag which is set to 1 if the shading context represents a ray miss. A miss context has no geometric information associated with it, cannot provide primvar or parameter evaluation services, and the only available builtin variables will be the ones associated with the incident ray.
    • reyesGrid: A flag which is set to 1 if the shading context is associated with a tessellated micropolygon representation. This is true in certain displacement or cached execution contexts.
    • RixSCShadingMode shadingMode: This enumeration conveys the current mode associated with the current shader execution. Knowledge of the shading mode may allow the shader to minimize certain costs associated with the current execution, i.e. by avoiding certain parameter evaluations when it is known that those parameters do not pertain to the current execution.
    • bxdf, opacity, displacement, subsurface, volume: Pointers to instances of the appropriate shader type. It is rare for a shader to need knowledge of other shader types via these fields. If such knowledge is required, the use of the methods GetBxdf(), GetOpacity(), etc is encouraged instead of directly accessing the scTraits
  • int* integratorCtxIndex: This array contains a mapping from the shading context to arrays in the RixIntegratorContext: a shading point of index i is associated with the corresponding index integratorCtxIndex[i]. For example, the shading point with index i can figure out the camera ray that ultimately gave rise to the shading point by accessing the primaryRays[integratorCtxIndex[i]] field of RixIntegratorContext.
  • int* rayId: This array should usually be ignored by shaders. It is typically used by integrators to track a correspondence between the points in the shading context and any ray specific data structures in the integrator.
  • RtColorRGB *transmission: The transmittance associated with the incident ray. This transmittance will typically be non-zero if the incident ray traveled through participating media. Most shaders other than volume integrators will ignore this field, while integrators will need to inspect this field in order to compute the total transmittance along a path.
  • float *pointWeight: If the shading context was created via an importance sampling method, this is the associated weight of that method. Most shaders other than volume integrators will ignore this field, while integrators may need to multiply the shader contributions by this weight.
  • int *pointSampleCount: Only used by volume integrators to indicate the number of samples taken for multiple scattering. Integrators may need to multiply this value into the total path throughput.
  • RtColorRGB *opacityThroughput: Per-point part of the throughput resulting from opacity continuations along the ray that produced the associated hit.
  • RtColorRGB *opacity: Per-point combined opacity: the product of presence and opacity for the given point.
  • float *opacityStochasticWeight:
  • RixRNG *m_rngCtx: A per-point array of random number contexts. These can be used by shaders to generate stratified random numbers. A NULL value here means the current shading mode does not support random number generation, and shader writers should check for a NULL value before relying on these contexts.

...

  • Per-point probability hit-testing weight. Inverse of the probability of having selected this hit. When dealing with non-fully-opaque surfaces, and when using probabilistic hit-testing, the combined opacity can be interpreted as the probability that we actually hit the surface. When only considering a scalar presence value (i.e. opacity is one, so combined opacity is monochromatic), the probability is usually the inverse of the scalar presence value, and no special weighting needs to be applied to the shading on hits. However, when dealing with arbitrary combined opacity, it is necessary to weight the shading on hit by the product of: opacity (the combined opacity on hit), and opacityStochasticWeight ( the inverse hit-testing probability).
  • RixRNG *m_rngCtx: A per-point array of random number contexts. These can be used by shaders to generate stratified random numbers. A NULL value here means the current shading mode does not support random number generation, and shader writers should check for a NULL value before relying on these contexts.

Anchor
getbuiltinvar
getbuiltinvar
Builtin Variables

Builtin variables represent values which are usually always present for all geometry types, and are often used in fundamental shader calculations. Some variables like P, the shading position, and Nn, the normalized shading normal, are derived from the geometry definition. Others like incidentRaySpread and VLen are derived from the incoming rays or from a combination of the geometry definition and the incoming rays.

Builtin variables may be queried using the GetBuiltinVar() method. The BuiltinVar enumeration is used to select one of the following variables:


  • RtFloat3 P: The position of the point being shaded. Derived

Builtin variables represent values which are usually always present for all geometry types, and are often used in fundamental shader calculations. Some variables like P, the shading position, and Nn, the normalized shading normal, are derived from the geometry definition. Others like incidentRaySpread and VLen are derived from the incoming rays or from a combination of the geometry definition and the incoming rays.

Builtin variables may be queried using the GetBuiltinVar() method. The BuiltinVar enumeration is used to select one of the following variables:

  • RtFloat3 P: The position of the point being shaded. Derived directly from the underlying tessellated representation used during hit testing.
  • float PRadius: When the geometry is a collection of hits, the radius of the incident ray at P. Otherwise it is half the micropolygon radius at P.
  • RtFloat3 Po: If the geometry was displaced, the value of the undisplaced position that became P after displacement
  • RtFloat3 Nn: The normalized shading normal,which is the normal that is typically used for shading because it has the smoothest appearance in all circumstances.RtFloat3 Ngn: The normalized geometric normal. The geometric normal is the normal derived directly from the underlying tessellated representation used during hit testing, and may be preferred to the shading normal for certain uses such as horizon culling.
  • RtFloat3 Non: The normalized undisplaced normal, i.e. equivalent to Nn if the geometry did not undergo displacement.
  • .
  • float PRadius: When the geometry is a collection of hits, the radius of the incident ray at P. Otherwise it is half the micropolygon radius at P.
  • RtFloat3 Po: If the geometry was displaced, the value of the undisplaced position that became P after displacement
  • RtFloat3 Nn: The normalized shading normal,which is the normal that is typically used for shading because it has the smoothest appearance in all circumstances.
  • RtFloat3 Ngn: The normalized geometric normal. The geometric normal is the normal derived directly from the underlying tessellated representation used during hit testing, and may be preferred to the shading normal for certain uses such as horizon culling.
  • RtFloat3 Non: The normalized undisplaced normal, i.e. equivalent to Nn if the geometry did not undergo displacement.
  • RtFloat3 Tn: The shading tangent. Typically a vector which is orthonormal to the shading normal Nn, often used in RtFloat3 Tn: The shading tangent. Typically a vector which is orthonormal to the shading normal Nn, often used in conjunction with same to create an orthonormal basis.
  • RtFloat3 Vn: The normalized view vector, pointing away from P. In ray tracing contexts, this is the reverse direction of the incoming ray. In other contexts where there is no view direction, this may be set to the same as Nn.
  • float VLen: The length of the view vector.
  • float curvature: The local mean surface curvature, which is the average of curvatureU and curvatureV.
  • float incidentRaySpread: How much the ray radius increases for each unit distance the incident travels.
  • float incidentRayRadius: Radius of incident ray at P.
  • int incidentLobeSampled: RixBXLobeSampled id of incident rays.
  • float mpSize: The micropolygon size. 0 for non-tessellated surfaces. May be used as a hint for biasing purposes.
  • float biasR: A renderer-computed bias used for reflected rays.
  • float biasT: A renderer-computed bias used for transmitted rays.
  • float u: The position of the current point on the current surface in parametric space.
  • float v: The position of the current point on the current surface in parametric space.
  • float w: The position of the current point on the current surface in parametric space.
  • float du: The size of the ray footprint (radius) in parametric space.
  • float dv: The size of the ray footprint (radius) in parametric space.
  • float dw: The size of the ray footprint (radius) in parametric space.
  • RtFloat3 dPdu: The surface derivative of P with respect to u.
  • RtFloat3 dPdv: The surface derivative of P with respect to v.
  • RtFloat3 dPdw: The surface derivative of P with respect to w.
  • RtFloat3 dPdtime: The instantaneous velocity of P in current space.
  • float time: The shading time of the point being shaded, normalized between shutter open and shutter close.
  • int Id: The value of any Attribute "identifier" "id" associated with the geometry.
  • int Id2: The value of any Attribute "identifier" "id2" associated with the geometry.
  • float outsideIOR: The incident index of refraction.
  • RtFloat3 Oi: The opacity.
  • RixLPEState lpeState: The current LPE state.
  • int launchShadingCtxId: The ID of the shading context that launched the incident ray.
  • RtFloat3 motionFore: Forward 2D raster-space motion vector.
  • RtFloat3 motionBack: Backwards 2D raster-space motion vector.
  • float curvatureU: The principal curvature in the parametric u direction, computed via dot(dNu, dPu) / |dPu|^2, where dNu is a difference between two surface normals computed at P and P' (P' being a point near P offset in the u direction) and dPu is the difference between P and P`. This is a signed quantity. 
  • float curvatureV: The principal curvature in the parametric v direction, computed via dot(dNv, dPv) / |dPv|^2, where dNv is a difference between two surface normals computed at P and P' (P' being a point near P offset in the v direction) and dPv is the difference between P and P`. This is a signed quantity. 
  • RtFloat3 dPcameradtime: The instantaneous velocity of P relative to the camera.
  • float wavelength: The wavelength of the incident ray.

...

For normal shading contexts, SetPrimVar() is a no-op. Shaders that wish to change the values of primitive variables will need to create a mutable shading context.

...

Note

Primitive variables of type RtFloat3 and RtMatrix4x4 are automatically transformed and returned in current space, which is generally considered the optimal space for the renderer to perform operations. Plugin authors should make no assumptions about what current space actually maps to, and should transform such primvars from current to another space if required using the transformation routines.


Anchor
evalparam
evalparam
Parameter Evaluation

Evaluation of the input parameters to the shader is provided via the EvalParam() methods. Input parameters may be constant (the direct parameters to the shader invocation), or

...

Evaluation of the input parameters to the shader is provided via the EvalParam() methods. Input parameters may be constant (the direct parameters to the shader invocation), or may be connected to an upstream node and trigger an upstream of that node (and in turn, any of its dependencies). All such upstream computation will be automatically cached by the renderer for the duration of the RixShadingContext.

...

RixShadingContext provides a limited service for tracing rays. The GetNearestHits() routine allows shaders to trace rays to determine the nearest hit. These rays do not trigger shading on the hit geometry, and should thus be considered geometric probe rays: the only information that can be returned from GetNearestHits is a RtHitPoint struct, which contains a minimal set of geometric information including the distance, the PNg, uv builtins of the hit geometry, and the filter and micropolygon sizes. A ray that missed is indicated by the distance being set to 0. While limited, this service is sufficient to allow for calculation of effects such as ambient occlusion. This service should not be confused with the RixIntegratorContext ability to trace rays, which is provided only to implementors of RixIntegrator.

Anchor
Anchor
Transformations
Transformations
Transformations

...

In addition, transform matrices between two coordinate systems can be returned directly via the GetTransform() method. The matrix output parameter points at storage allocated by the renderer containing the matrices. The size of this storage is indicated by the numMatrices output parameter. If the transformation is time varying, the numMatrices returned will be the same as numPts. If the transformation is uniform, numMatrices will be set to 1. A non-zero return value indicates a failed transformation, typically due to unknown coordinate systems being specified.

Anchor
RayProperty
RayProperty
Querying Ray Properties

As long as the RixIntegrator used supports the appropriate ray property query, plugin authors may want to query ray properties such as the ray depth or eye throughput, in order to allow for artistic control or optimization. For instance, as an optimization a RixBxdf may want to skip the evaluation of a particularly expensive lobe, if the current ray depth of the hit point is beyond some arbitrary threshold. This service is provided by the GetProperty() routine on the RixShadingContext. Callers of this routine are responsible for allocating and deallocating the result memory.  The integrator is responsible for filling in the result. Below is a code snippet demonstrating how to use this feature.

Code Block
languagecpp
// Query ray depths for each point in the shading context
int nPts = shadingCtx->numPts;
int* rayDepths = new int [nPts];
if (vCtx->GetProperty(k_RayDepth, rayDepths))
{
    // Do something expensive for small ray depths, or something cheaper for large ray depths  
}
delete[] rayDepths;


For documentation on the available ray properties, please consult the integrator ray property query documentation.