Keywords: main

Next: 1.6 Illumination Up: 1. Base Shaders/A> Previous: 1.4 Textures

# 1.5 Sample Compositing

Reflection

Cast a reflection ray of a given color and merge the result with an input color. This can be used to add a reflection effect to a base shader that provides illumination, possibly in conjunction with refractions or transparency added by other base shaders. If no reflection ray can be cast (because the trace depth has been exceeded, or the reflection ray caused a shader to be called that failed, or the notrace parameter is set), sample the environment if there is one.

        color "mib_reflect" (
            color           "input",
            color           "reflect",
            boolean         "notrace")

input is the color to composite the reflection onto.

reflect is an RGBA color that blends the reflection onto the input. Transparent black returns the input color without casting a reflected ray; opaque white returns the reflection color without evaluating the input color.

notrace, if set to true, prevents the shader from casting a reflection ray and samples the environment instead.

Refraction

Cast a refraction ray of a given color with an index of refraction, and merge the result with an input color. The indices of refraction can be computed with another base shader, such as mib_refraction_index, which is also stored back into the appropriate state variables. This can be used to add a refraction effect to a base shader that provides illumination.

        color "mib_refract" (
            color           "input",
            color           "refract",
            scalar          "ior",

input is the color to composite the refraction onto.

refract is an RGBA color that blends the refraction onto the input. Transparent black returns the input color without casting a refracted ray; opaque white returns the refraction color without evaluating the input color.

ior is the ratio of the indices of refractions; the index of the object being entered divided by the index of the object being exited. This controls the outgoing ray direction. If it is 0, 1 is used, which reduces refractivity to transparency.

Transparency

Cast a transparency ray of a given color and merge the result with an input color. This is like the previous function assuming an index of refraction of 1.

        color "mib_transparency" (
            color           "input",
            color           "transp")

input is the color to composite the refraction onto.

transp is an RGBA color that blends the transmission onto the input. Transparent black returns the input color without casting a transparency ray; opaque white returns the transparency color without evaluating the input color.

Opacity

Cast a transparency ray of a given intensity and merge the result with an input color. This is like the previous function, except that the opacity is given instead of the transparency. Opacity is defined as 1.0 - transparency.

        color "mib_opacity" (
            color           "input",
            color           "opacity")

input is the color to composite the refraction onto.

opacity is an RGBA color that blends the transmission onto the input. Opaque white returns the input color without casting a transparency ray; transparent black returns the transparency color without evaluating the input color.

Dielectric

Another variation of refraction, with the addition of specularity (Snell's law). This shader does only the refraction part of a dielectric material; highlights are left to other illumination nodes.

        color "mib_dielectric" (
            color           "input",
            color           "absorb",
            scalar          "refract",
            scalar          "ior")

input is the color to composite the refraction onto.

absorb specifies the outside absorption coefficients of the surface.

refract blends the refraction onto the input. A value of 0.0 returns the input color without casting a refracted ray; a value of 1.0 returns the refraction color without evaluating the input color.

ior is the ratio of the indices of refractions; the index of the object being entered divided by the index of the object being exited. This controls the outgoing ray direction. If it is 0.0, 1.0 is used, which reduces refractivity to transparency.

Ray Marcher

The ray marcher casts light rays from points on a given ray, and approximates the volumic contribution from light sources sending light through the volume. Instead of using shader interface functions like mi_sample_light, it calls a shader given as an input parameter of type shader. Ray marching consists of calling the shader for regular points between the start point and end point of the ray, and adaptively subdividing each of these intervals until a given subdivision limit is reached if the color returned by two adjacent shader calls is smaller than a given contrast threshold. The total weighted sum is returned.

        color "mib_ray_marcher" (
            shader          "shader",
            scalar          "distance",
            integer         "num",
            integer         "subdiv",
            color           "contrast")

shader is the shader to call at every sampling point. Its returned color is added to the returned total unless the shader fails (returns false).

distance is the maximum internal space distance between two initial sample points. If the distance is 0, no maximum distance is enforced.

num is the initial number of samples in the given distance. If this number is 0, no initial number is given, and the ray marcher relies on the minimum distance instead. If both are 0, the default number is 4. If the number is not 0, it must be at least 2 (one at each ray end point).

subdiv specifies the number of recursive subdivisions of the initial sample density. A value of 0 (the default) does not subdivide, so the ray marcher is restricted to the initial sample points. Values of 1 or larger make the sampling adaptive; each level of subdivision divides a distance by two. The maximum is 16.

contrast, if exceeded by the absolute difference between two adjacent samples, causes another sample to be taken in the middle. The process then repeats recursively for both sub-segments until the contrast is sufficiently low or the subdivision limit is reached.

Two-Sided

Choose one or the other input color, depending on which side of the geometry was hit. This is commonly used as a multiplexing material shader, with two other material shaders assigned to the front and back parameters.

        color "mib_twosided" (
            color           "front",
            color           "back")

front is returned if the front side was hit.

back is returned if the back side was hit.

Refraction Index

Decide whether the ray is entering or leaving the object it has hit, based on a scan of parent rays (not based on the normal vector; this can be unreliable if the scene contains dubious geometry such as cones with only one axis-aligned normal at the tip). The index of refraction ratio (outgoing divided by incoming) is returned. As a side effect, both incoming and outgoing indices of refraction are stored in the state (ior_in and ior, respectively), and the current volume shader becomes the refraction volume if the ray is entering.

        struct {
            scalar          "ior",
            boolean         "enter"
        } "mib_refraction_index" (
            scalar          "mtl_ior")

ior is the returned refraction index ratio, ready for use by refracting or dielectric base shaders.

enter is true if the ray is entering the object. Most shaders do not need to know this but it makes this base shader more versatile.

mtl_ior is the index of refraction of the material that the ray has hit. It describes the optical properties of the object the ray is entering or leaving, and is returned as the new index of refraction if the ray is found to be entering the object.

Next: 1.6 Illumination Up: 1. Base Shaders/A> Previous: 1.4 Textures