Page tree

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Contents

Bxdfs not only compute the scattering of light, but are also allowed to provide:

  • presence (a scalar) 
  • opacity (a color)

of non-opaque materials. This is done using the RixOpacity interface, that the renderer will query by invoking RixBxdfFactory::BeginOpacity().

Historically (RenderMan RIS 21 and before) presence has been used for masking out parts of an object, while opacity has historically been used for coloring shadows cast by an object. Depending some ray types (e.g. camera rays), opacity was being ignored, and probabilistic hit-testing was mandatory for presence.

In RenderMan RIS 22, this has been unified, and presence and opacity are now combined into a single property, the final opacity. This final opacity can be used for both probabilistic hit-testing and traditional 'blending' opacity.

However, despite the fact that we are now dealing with a combined final opacity, it can still be helpful to describe the main two usages of this quantity as:

  • a 'presence' (actually: scalar final opacity)
  • an 'opacity' (actually: colored final opacity)

Note:

  • the RixOpacity API still exposes two hooks (for each of the presence/scalar and opacity/colored component of the final opacity), and depending on the instance hint returned by the RixBxdfFactory, and on the ray type, only one of this hook may be called.

Presence (scalar final opacity)

Consider the case of trying to render a tree leaf. Rather than model it as a polygon mesh, it's common to represent a leaf as a cheap bilinear patch with an associated mask texture representing the leaf shape. Where the mask is zero, there is no leaf. We use the term presence rather than opacity to capture this use case. The leaf-shaped map is a scalar presence map.

It is important to note that in this usage, presence conceptually has no bearing on light scattering (and vice-versa). Where a material is partially present, its light scattering properties do not change. Instead, this is interpreted as the material scattering less often, with each scatter event being identical to what would happen with a totally present material. Critically, this mean that presence is not a way to model transparent surfaces such as glass, because the light scattering and refractive properties of the glass cannot be modelled by presence alone.

A leaf rendered with PxrDiffuse, using a leaf texture map as input to the presence parameter.

Bxdfs wishing to use a non-trivial presence must do the following:

  • implement the RixBxdfFactory::GetInstanceHints() method and return a bit vector which includes the k_ComputesPresence bit
  • implement the RixBxdfFactory::BeginOpacity() method and return a RixOpacity object that implements theRixOpacity::GetPresence() method

The RixOpacity object is bound to a shading context, similarly to a RixBxdf object. RixOpacity::GetPresence() will typically use this shading context (along with any pattern inputs) to return an array of presence values. There are RixShadingContext::numPts presence values in the array. These presence values need to range from 0 to 1, where:

  • 1 is fully present
  • 0 is fully absent
  • any value in between denotes a probabilistic presence for anti-aliasing

Presence vs. Continuation

When dealing with opaque objects using presence maps, it is usually the case that the objects are either entirely present or not present at all. In practical terms: the presence map is used as a cut-out map, and consists mostly of 0-or-1 values. RenderMan takes advantage of this by combining presence with probabilistic hit-testing, actually interpreting the presence value as the probability that we actually hit a surface.

The compelling advantage of this approach is that for camera rays and indirect rays, the renderer only needs to shade the surface and run the associated bxdf when the surface is actually hit (due to a non-zero presence). This means the renderer doesn't need to institute a policy of automatic continuation rays.

Presence should not be used for cases where the intention is to model a thin semi-transparent surface (rather than an opaque object). Instead, the bxdf should generate a transmitted bxdf sample, with the appropriate properties (transmission color for example). Even if those samples are generated in the exact same direction as the incoming ray, without refraction (i.e. to model a thin translucency), they have to be generated by RixBxdf::GenerateSample(), which means that the presence needs to be 1. Depending on the intention, this transmitted sample may be generated as a continuation sample.

Cached Presence

RenderMan offers an additional service that may improve performances for scenes making heavy use of presence (e.g. a forest of trees with presence-mapped leaves). By having RixBxdfFactory::GetInstanceHints() return a bit vector that includes the k_PresenceCanBeCached bit, the bxdf can request RenderMan to cache presence values. This would prevent re-evaluation of the presence values for every ray that intersects the surface.

However, note that as with most of the caching systems, this may introduce bias, manifesting itself as blurred results due to interpolation from the cached values. Presence caching efficiency is driven by the opacitycachememory setting – a speed vs memory trade-off.

Opacity

As explained in the Presence section, it would be the responsibility of a semi-translucent thin glass-like bxdf to capture light transport across its surface (instead of using presence). However, when it comes to transmission rays, requiring a similar responsibility is problematic for two reasons:

  • Transmission rays do not bend: they are usually fired to compute the amount of light flowing directly along a straight line between two points. Typically, one of these points is on the surface, the other is on the light. This means that any physically plausible object which requires refraction should be opaque to transmission rays.
  • Transmission rays typically outnumber camera and indirect rays, so the cost of running a full shader to obtain a transmission value is worth minimizing

Nonetheless, it can be desirable to have a method by which approximate colored shadows can be efficiently produced. These are often preferable to the physically realistic, but noisy, color shadows produced by considering indirect paths. RenderMan allows the bxdf to return an opacity color, which will influence the colors of shadow resulting from tracing transmission rays. An opaque object would yield black shadows, as if returning an opacity of [1 1 1], i.e. white.

Note that opacity describes the transmittance straight through the surface (no bending)

Below is an example using opacity to yield colored volumetric shadows. The box encloses both the angel statue and a volume. The only light source is behind the stained glass window (the right wall of the box).

If we were to model the stained glass window as a physically accurate piece of glass, complete with full refraction, then the crepuscular rays (also called "God rays") shining through the volume would be very expensive to render because the only lighting that could be considered for the volume is entirely indirect; the glass would have to be an opaque object and transmission rays from the volume would not reach the light source.

If we instead model the stained glass window as a thin, non-physically accurate piece of glass with colored opacity, then transmission rays from the volume can now directly reach the light (running the opacity shader of the glass window along the way to get a colored contribution). This allows the scene to be rendered with the direct lighting optimization, which allows for a much faster render.

Note that when writing a bxdf for a thin translucent surface, careful consideration should be given as to whether indirect rays should also be fired through the surface. If colored opacity is being used (and depending on the circumstances) it is quite likely that such rays should not be fired, otherwise the lighting contribution will be doubled.

 

Volumetric crepuscular rays, efficiently rendered using direct lighting by means of stained glass using colored opacity

Bxdfs wishing to use a non-trivial opacity must implement do the following:

  • implement the RixBxdfFactory::GetInstanceHints() method and return a bit vector which includes the k_ComputesOpacity bit
  • implement the RixBxdfFactory::BeginOpacity() method and return a RixOpacity object that implements the RixOpacity::GetOpacity() method

The RixOpacity object is bound to a shading context, similarly to a RixBxdf object. RixOpacity::GetOpacity() will typically use this shading context (along with any pattern inputs) to return an array of opacity values. These opacity values need be colors, ranging from [0 0 0] (black) to [1 1 1] (white), where each channel is:

  • 1 is opaque
  • 0 is non-opaque
  • any value in between will yield colored transmission shadows (the shadow color is 1 - opacity)

Cached Opacity

As with cached presence, RenderMan offers an additional service that may improve performance for scenes making heavy use of opacity. By having RixBxdfFactory::GetInstanceHints() return a bit vector that includes the k_OpacityCanBeCached bit, the bxdf can request RenderMan to cache opacity values. This would prevent re-evaluation of the opacity values for every ray that intersects the surface.

However, note that as with most of the caching systems, this may introduce bias, manifesting itself as blurred shadows due to interpolation of the cached opacity values. Opacity caching efficiency is driven by the opacitycachememory setting --the more memory is allocated to this cache, the more efficient the opacity reuse will be.

Using Both Presence and Opacity

Bxdfs are allowed to compute both presence and opacity. In this case, when dealing with transmission rays, both presence and opacity are separately computed, and combined by the renderer into the transmission result across the surface.

Note that the shading mode (RixSCShadingMode) passed to RixBxdfFactory::BeginOpacity() is a hint as to the renderer's intentions for the RixOpacity object:

  • if the shading mode is k_RixSCPresenceQuery, only the RixOpacity::GetPresence() method will be called. RixBxdfFactory::BeginOpacity() need only evaluate the pattern inputs relevant to computing presence.
  • if the shading mode is k_RixSCOpacityQuery, either RixOpacity::GetPresence(), RixOpacity::GetOpacity() (or both) will be executed on the object, and pattern inputs relevant to both presence and opacity should be fully evaluated.

Probabilistic Hit-Testing