©Anton Podvalny


Introduction


In this chapter, we cover the concept of render passes, some essential render elements, and how to use them to create selection masks.

First, let's define some terms:

  • Pass – A “once-over” on the rendering to produce a specific effect. You can think of a pass as a “sweep” through the image to do one specific thing.
  • Render pass – A pass that renders the entire image and stores one or more scene elements, for example, just the lighting or reflections.
  • Render Element – The results of a render pass that can be combined in a post-process to adjust the final image. It is a regular 2D image, where each pixel has RGB numerical values.
  • Render Mask – It makes it easy to choose just a part of the image you'd like to rerender. It's more exact and offers more control than Render Region.
  • Compositing – The combining and adjustment of Render Elements and/or other elements such as live footage or background plates.
  • Beauty pass – The combining and editing of certain Render Elements to create a traditional rendered image.
  • Multiple Matte Passes

    • Unshaded solid color images with red, green, and blue colors.
    • Each color allows control of the selected geometry or materials to which the color has been assigned.
  • Ambient Occlusion Pass – A shading and rendering technique used to calculate how exposed each point in a scene is to ambient lighting.

  • Z-Depth Pass – A black-and-white image that shades an object based on the distance from the camera.

The reasoning behind the compositing process is the following: for high-end work such as feature films, rendering straight out of the 3D modeling software/V-Ray is usually never enough to control to get the desired look.

  • Rendered image might need adjustment to match live-action lighting, color temperature, etc.
  • The director might want to try different sky backgrounds, combinations of landscape elements, etc.
  • Common adjustments include color correction, improvement of contrast, adding or enhancing Lens Effects.
  • Making changes to Render Elements is faster and easier than re-rendering.

Compositing with Render Elements provides the solution.

  • Render elements layered on top of one another to generate the final image.
  • Render Elements can be adjusted individually to produce a specific look.

Compositing of Render Elements is done outside the 3D modeling app/V-Ray in a compositing program.

  • Software programs designed for compositing include After Effects, Nuke, Fusion, Photoshop
  • Render Elements are exported from V-Ray and imported into compositing software

In compositing, each Render Element is usually “added” or “multiplied” with previous layers.

  • In compositing, black = 0 and white = 1
  • Colored pixel + black pixel = no change
  • Colored pixel + white pixel = brighter colored pixel (up to pure white pixel)
  • Colored pixel x black pixel = black pixel
  • Colored pixel x white pixel = no change

All Render Elements can be exported together in one multi-channel EXR file, or each Render Element can be rendered in its own image file for layering in compositing software. Here, we cover how to achieve these approaches programmatically.

Here's a list of the available Render elements which V-Ray provides to the user:

  • Basic: Alpha, Diffuse

  • Beauty: Global Illumination, Lighting, Reflection, Refraction, Specular, Atmosphere, Background, Caustics, Self Illumination, Subsurface Scattering

  • Matte: Material ID, Multimatte, Object ID, Render ID

  • Geometry: Velocity, Z-Depth, Wire Color, Normals

  • Utility: Distributed Render ID, Denoiser, Extra Texture, Sampler Info


We cover 1 and 2 in this topic and 3, 4, and 5 next.


Here's a quick example of how render elements can be retrieved from the renderer object. A more thorough example can be found at the end of the article:


renderer.renderElements.getAll() 
# returns an array of render elements with the following structure:
# {
#   'name': 'shadow', 
#   'type': 'shadow', 
#   'binaryFormat': '3_floats', 
#   'defaultPixelFormat': '3x4_bytes_float_RGB', 
#   'pixelFormat': '3x4_bytes_float_RGB', 
#   'plugin': vrayRE_Shdow', 
#   'alphaChannelPlugin': 'Not set'
# }
std::vector<RenderElement> REs = renderer.getRenderElements().getAll(RenderElement::SHADOW);
for (auto re : REs) {
    void* data = NULL;
    cout << "Name: " << re.getName() << endl;
    cout << "Binary format: " << re.getBinaryFormat() << endl;
    cout << "Pixel format: " << re.getDefaultPixelFormat() << endl;
    cout << "Size of data: " << re.getData(&data) << endl;
}
/* sample output:
    Name: shadow
    Binary format: 3 (corresponds to BF_3FLOAT)
    Pixel format: 203 (corresponds to PF_RGB_FLOAT)
    Size of data: 9000000 (12 bytes x size in pixels)
*/
RenderElements REs = renderer.RenderElements;
foreach(RenderElement re in REs.GetAll())
{
    Console.WriteLine("Name: " + re.Name);
    Console.WriteLine("Binary format: " + re.BinaryFormat);
    Console.WriteLine("Pixel format: " + re.DefaultPixelFormat);
    byte[] data = re.GetData();
    Console.WriteLine("Size of data: " + data.Length);
}
/* sample output
Name: shadow
Binary format: FLOAT3
Pixel format: RGB_FLOAT
Size of data: 9000000
*/
renderer.renderElements.getAll(); 
/* returns an array of render elements with the following structure:
RenderElement {
    name: 'shadow',
    type: 'shadow',
    binaryFormat: '3_floats',
    pixelFormat: '3x4_bytes_float_RGB',
    defaultPixelFormat: '3x4_bytes_float_RGB',
    rgbOrder: false,
    plugin:
     Plugin {
       _name: 'vrayRE_Shadow',
       _type: 'RenderChannelColor',
       name: 'shadow',
       alias: 105,
       color_mapping: 1,
       consider_for_aa: 0,
       filtering: 1,
       derive_raw_channels: 1,
       vfb_color_corrections: 1 } 
*/


Basic Render Elements


The Diffuse and Alpha render elements are available directly from the image returned by renderer.getImage(). When saved, two files are generated - one with the diffuse channels and another, ending with "_Alpha", with the alpha channel.

Diffuse

Type: RenderChannelColor

The Diffuse Filter Render Element is one of the basic render elements used to form many other render elements.



Overview

It shows the colors and textures used in materials, flatly applied to objects with no lighting information. The colors are the actual colors set in the material definition, and each texture appears as it does in the texture (file) itself. There are no highlights or shadows, and any background image is not included.

Other render elements that include colors from materials are said to include the diffuse contribution or the diffuse component of the rendered scene. The Diffuse Filter Render Element contributes to this diffuse component; any render element that includes this diffuse component is a combination of Diffuse Filter and other render element(s).

This render element is useful for making overall adjustments and enhancements to colors and textures during compositing.

Common Uses

The Diffuse Filter Render Element helps change the appearance of many passes when combined with Raw render passes (like Raw Global Illumination, Raw Lighting, etc.). In the example below, the Diffuse Filter is multiplied by the Raw Global Illumination Render Element to provide the Global Illumination element. In this way, color correction can be performed upon the raw pass without changing the actual diffuse colors, making it possible to tint a pass realistically without re-rendering.

The Diffuse Filter is a handy render element due to the number of raw passes with which it can be combined, giving the ability to manipulate many areas of the render at the composite level. The Diffuse Filter pass can also be color-corrected, as shown in the example below. In this case, a Multimatte Render Element was used in conjunction with the Diffuse Filter render element to isolate the dangling light and change its color from white to blue without also tinting its lighting or shadowing in any way.


Diffuse Filter Render Element

Original Beauty Render Element

Diffuse Filter Render Element with color corrections

Resulting composite with color corrections



Underlying Compositing Formulas

Diffuse Filter x Raw Global Illumination = Global Illumination
Diffuse Filter x Raw Lighting = Lighting
Diffuse Filter x Raw Shadow = Shadow


Alpha


Type: RenderChannelColor

Overview

The Alpha Render Element shows the transparency of objects in the scene as grayscale colors. Solid geometry is represented by solid white, while those areas not blocked by geometry within the scene are black. Pixels at antialiased edges have varying shades of gray, as do semi-transparent surfaces.

Common Uses

The Alpha Render Element is primarily used as a mask to enable other elements to be placed behind the Beauty composite, such as the Background Render Element. The Alpha Render Element shown below considers the glass's transparency in the windows, including the frosted glass made semi-transparent by a texture mask in the glass material.


Beauty composite with no background


Alpha Render Element


New Beauty composite with the Background Render Element behind the original Beauty composite

When using transparent materials such as glass, make sure that the material is set up to treat the material as transparent with regard to the Alpha channel. For example, when using VRayMtl as the material, set the Affect channels parameter for Reflection (reflect_affect_alpha) and Refraction (refract_affect_alpha) to Color+alpha or All channels. Otherwise, the transparent surface will not be treated as transparent in the Alpha Render Element.


Beauty Render Elements


The Beauty Render (RGB_Color) is V-Ray's pre-composited final render and is usually the primary export when rendering a scene. This pass can be re-created manually in a composite by assembling the proper components and fine-tuning the components. This process is commonly called Back to Beauty Compositing.

Back to Beauty Compositing

The following is the base formula for reconstructing the Beauty pass. Some Render Elements can be excluded if the scene does not utilize them. Click the image to see the full-size version and zoom in to view all the render elements involved.

Lighting + Global Illumination + Reflection + Refraction + Specular + SSS2 + Self Ilumination + Caustics + Atmosphere = RGB_Color (Beauty)


Advanced Back to Beauty

Occasionally, there may be a need for more specific editing of the final image. There's a more detailed workflow than the standard back-to-beauty workflow for this. Click the image to see the full-size version and zoom in to view all the render elements involved.

Diffuse Filter x (Raw Lighting + Raw Global Illumination)) + (Raw Reflection x Reflection Filter) + ( Raw Refraction x Refraction Filter) + Specular + SSS2 + Self Illumination + Caustics + Atmosphere + Background = RGB_Color (Beauty)



There are two options for handling Motion blur and Depth of Field in the back-to-beauty composite. If Depth of field and Motion blur are enabled in the V-Ray Physical Camera, these effects will already be baked into all render elements. In this scenario, using the filter render elements in the advanced back-to-beauty composite can offer finer control of some render elements. Alternatively, many compositing and photo editing packages can add the effects post-rendering using specific tools that utilize VRayVelocity for motion blur and VRayZDepth for depth of field, with some limitations.


Global Illumination


Type: RenderChannelColor

Global Illumination is the indirect lighting bouncing around within a scene to contribute to the overall illumination, as opposed to direct lighting from a light source. This page overviews the two global illumination render elements that may be created through V-Ray and how they are used in compositing. Specific usage for each of these global illumination elements is explained in the Overview.

GI



Raw GI



Overview

The Global Illumination Render Elements store indirect lighting information calculated in the scene. The following passes may be generated:

  • Global Illumination Render Element (VRayGlobalIllumination) - Stores the diffuse surface global illumination in a scene when Indirect Illumination is enabled. This pass is already attenuated by the diffuse contribution in the scene and can be used directly in the composite.

  • Raw Global Illumination Render Element (VRayRawGlobalIlumination) - Stores the raw information for the indirect lighting information calculated in the scene, untouched by the diffuse contribution. This pass is used to fine-tune the GI in a scene before attenuating it with the diffuse contributions of the scene.

The Global Illumination Render Element (VRayGlobalIllumination) can be used in Back to Beauty compositing to add the GI lighting contribution to the scene. The GI contribution may be adjusted (tinted, brightened, darkened, etc.) in the composite without rerendering the scene.

When even more control over the GI contribution to the final image is desired, this main Global Illumination Render Element can be re-created by multiplying the Raw Global Illumination Render Element with the Diffuse Filter Render Element:

Raw Global Illumination x Diffuse Filter = Global Illumination

Examples



Global Illumination Render Element


Raw Global Illumination Render Element


When Raw Global Illumination is needed in the composite, please also render the Global Illumination element (VRayGlobalIllumination) and the Raw GI element (VRayRawGlobalIlumination).


Global Illumination Render Element

The Global Illumination Render Element is a color image that stores indirect lighting information from reflected diffuse light in a scene ( without direct light and reflection contributions) when Indirect Illumination is enabled. This element may be used directly in Back to Beauty compositing and adjusted for brightness and color to control the final image easily.

For even more control of indirect illumination without rerendering the scene, the Global Illumination render element may be re-assembled by multiplying the VRayRawGlobalIllumination Render Element by the Diffuse Filter Render Element:

Raw Global Illumination x Diffuse Filter = Global Illumination

The Global Illumination Render Element is useful for changing the appearance of indirect lighting after rendering in a compositing or image editing software. Below are a couple of examples of its use.



Global Illumination Render Element

Original Beauty Composite

Brightened GI

Tinted and Brightened GI



Raw Global Illumination Render Element

The Raw Global Illumination Render Element stores how much indirect lighting (reflected diffuse light) is received by surfaces in the scene. This raw element is useful for fine-tuning indirect lighting in the compositing process.

The Raw Global Illumination Render Element is untouched by the diffuse colors of the scene and represents the pure indirect lighting contribution. You can use this raw element to reconstitute the Global Illumination by multiplying the Raw Global Illumination with the Diffuse Filter.

For proper results, this raw render element must be rendered along with the Global Illumination element (VRayGlobalIllumination).

Once the scene is rendered, the Raw Global Illumination Render Element is useful for changing the appearance of indirect lighting in a compositing or image editing application. Below are examples of its use.



Raw Global Illumination Render Element

Original Beauty Composite

Brightened GI

Tinted and Brightened GI



Lighting



Overview

V-Ray Lighting Render Elements are a group of elements that store lighting information from the scene. Each element can be individually adjusted during the compositing phase to change the Beauty Pass without rerendering.

The Lighting Render Elements are:

  • Lighting (VRayLighting) - Stores direct lighting information from lights in the scene, including the diffuse contribution.

  • Light Select (VRayLightSelect) - Stores direct lighting information from user-selected lights in the scene; can be limited to the light's raw, diffuse, or specular contribution.

  • Raw Lighting (VRayRawLighting) - Stores the effects of direct lighting on scene objects without the diffuse contribution.

  • Total Lighting (VRayTotalLighting) - Stores the effects of both direct and indirect lighting on materials in the scene, including the diffuse contribution.

  • Raw Total Lighting (VRayRawTotalLighting) - Stores the sum of both direct and indirect lighting in the scene without the diffuse contribution.


All of them are of the type: RenderChannelColor

Examples



Lighting


Light Select - dome light


Light Select - plane light





Raw Lighting


 Total Lighting


Raw Total Lighting


  • Lighting can be added or subtracted at a composite level using Lighting Render Elements.
  • Lighting can be color corrected
  • When using Light Select, lights can be turned on and off at a composite level without rerendering.


Lighting

The Lighting Render Element stores direct lighting information from lights in the scene and materials as lit by the lighting. This render element can brighten, lessen, or tint the direct lighting in a composite.

The Lighting Render Element is the same as Raw Lighting multiplied by Diffuse Filter.  Lighting Render Element is provided as a convenience to the compositor.



Lighting Render Element

Original Beauty Composite

Brightened Lights

Tinted Lights



Raw Lighting x Diffuse Filter = Lighting


Light Select

The Light Select Render Element represents the lighting contribution from one or more selected lights in the scene. Each Light Select channel can output selected lights' raw, diffuse, or specular contributions to the illumination or overall (normal) contribution. When multiple lights are selected, all the contributions from the selected lights are combined into a single render element. Multiple Light Select elements can be rendered for a single scene, and lights may be included in more than one Light Select element.

This element is similar to the Lighting Render Element. However, the Lighting element combines the effect of all lights in the scene, while the Light Select element allows for a user-selection light or set of lights to be broken out, showing their own individual effect(s) on the scene's illumination. Using these render elements, specific lights in the resulting render can be adjusted (color, temperature, brightness, etc.) in a composite without rerendering.

For example, by generating a Light Select element for all of the backlights in a scene, an artist may adjust the backlighting of the rendered scene easily in the composite without affecting the rest of the scene's illumination.

The following diagram shows the compositing formula to recreate all the light in a scene in its most basic form, but only when each light is accounted for in exactly one Light Select element for a particular mode. If a particular light is used in more than one Light Select element, this equation will result in brighter lighting than intended because that light will contribute to lighting more than once.



Shadow Select

The Light Select Render Element (RenderChannelLightSelect::light_select_mode) represents the lighting contribution from one or more user-selected lights in the scene. The shadow modes (Direct diffuse shadow and Direct specular shadow) render a color image that works as a reverse mask for shadows caused by a specific light(s). It can lighten, darken, or tint the shadows in post-production.

The Direct Diffuse Shadows channel outputs only the shadows cast by objects illuminated by pre-selected lights. This option has the same output as the Shadow render element. Works with all V-Ray materials that have diffuse (which excludes Stochastic Flakes and V-Ray Flakes 2). V-Ray Toon material is not supported.

The Direct Specular Shadows channel outputs the specular information from the shadows cast by objects illuminated by a pre-selected light. The objects that the shadows are cast on must have reflective material for this channel to be visible. It works with all V-Ray materials that have reflection and glossiness values less than 1. 

The Matte Objects Only option (light_select_matte) renders object shadows generated by a predetermined light source onto a matte surface (object with matte properties assigned). It is available for the Direct diffuse shadow Type only. It can add 3D elements to the composite's background image or footage. 


Example: Shadow Select







Example: Matte Objects Only






Raw Lighting

The Raw Lighting Render Element stores the effects of direct lighting on scene objects with no diffuse components. It is useful for adjusting the brightness of direct lighting during compositing.



Total Lighting

The Total Lighting Render Element is a color image that includes the effects of both direct and indirect lighting on materials in the scene, including the diffuse component. It results from adding the Lighting and Global Illumination render elements or multiplying the Raw Total Lighting and Diffuse Filter render elements.

The Total Lighting Render Element is useful for brightening or dimming all lighting during compositing. Below are a couple of examples of its use.


Total Lighting Render Element

Original Beauty Composite

Brightened Lights

Tinted Lights



Raw Total Lighting x Diffuse Filter = Total Lighting


Raw Total Lighting

The Raw Total Lighting Render Element is the sum of all raw lighting (both direct and indirect) in the scene, without any diffuse details. This render element is useful for changing the appearance of the scene's lighting in a compositing or image editing application.



The Raw Total Lighting Render Element is useful for changing the appearance of the entire scene lighting after rendering, using a compositing or image editing application. Below are a couple of examples of possible uses. The first two images show the render element itself and the Beauty render put together. In the following examples, a Matte Render Element was used to isolate different parts of the scene. Then, the Raw Total Lighting Render Element was brightened and tinted differently to show the range of editing possible.


Raw Total Lighting Render Element

Original Beauty Composite

Brightened Lights with different brightening for the floor, wall, and ceiling

Tinted Lights with different tinting for the floor, wall, and ceiling



Raw Lighting + Raw Global Illumination = Raw Total Lighting


Reflection


Overview

The Reflection Render Elements store reflection information calculated from the materials' reflection values in the scene. Surfaces with no reflection values set in their material(s) will contain no information in the render pass and render it black.




The Reflection Render Elements include:

  • Reflection – Stores reflection information calculated from the materials' reflection value in the scene. It is the product of Raw Reflection | VRayRawReflection and Reflection Filter | VRayReflectionFilter.
  • Raw Reflection – Gives the full reflection data of objects reflecting in the scene at the reflection's maximum possible intensity.
  • Reflection Filter – Sets how much raw reflection data should come through in the composite. It is designed to be used in conjunction with Raw Reflection.


All of them are of the type RenderChannelColor.

These three render elements are designed to be used together or separately to adjust the overall reflection in the scene.

In addition, several other render elements are available for adjusting reflection in a composite. These render elements can be used for texture baking when there is a need to recreate a shader in a real-time engine or to do relighting in a compositing package:

  • Reflection Glossiness – Returns a grayscale image corresponding to the value in the Reflection Glossiness of materials in the scene. It can be used for texture baking when it is necessary to recreate a shader in a real-time engine or to do relighting in a compositing package. Type: RenderChannelGlossiness
  • Reflection Highlight Glossiness – A grayscale image corresponding to the value in the Highlight Glossiness of the materials in the scene. Type: RenderChannelGlossiness
  • Reflection Index – A grayscale image corresponding to the Fresnel IOR value of the materials in the scene.

Examples



Reflection Render Element


Raw Reflection Render Element


Reflection Filter Render Element





Reflection Glossiness Render Element


Reflection Index Render Element


Reflection render elements can be added and subtracted from existing reflections within the scene. * To enable changes to the reflectivity of specific objects or materials during the compositing phase, use Matte Render Elements to isolate and select the objects and materials.


Reflection

The Reflection Render Element stores reflection information calculated from the materials' reflection values in the scene. Surfaces with no reflection values set in their materials contain no information in the render pass and render it black.

The Reflection Render Element is formed by multiplying the Raw Reflection (VRayRawReflection) Render Element by the Reflection Filter (VRayReflectionFilter) Render Element. So, while the raw reflection pass gives the full reflection of objects reflecting in the scene, the reflection filter sets how much of that reflection should come through in the composite. The two are multiplied together to create the Reflection Render Element, representing the scene's reflection.

The Reflection Render Element is a key component in the main Beauty Pass.



The Reflection Render Element is useful for changing the appearance of reflective elements after rendering using compositing or image editing software. Below are a couple of examples of its use.


Reflection Render Element

Original Beauty Composite

Brightened Reflections

Tinted Reflections



Raw Reflection x Reflection Filter = Reflection 


Raw Reflection

The Raw Reflection Render Element stores reflection information calculated from the materials' reflection values in the scene. Surfaces with no reflection values set in their materials contain no information in the render element, meaning these areas are rendered black. When the Raw Reflection Render Element is multiplied by the Reflection Filter (VRayReflectionFilter), the Reflection (VRayReflection) Render Element is produced.

Raw Reflection gives the full reflection of objects reflecting in the scene, while the Reflection Filter sets how much of that reflection should come through in the composite. In other words, the filter defines the strength of the reflection, while the raw image defines what is being reflected in the image. When these two elements are multiplied, the true level of reflection is given as the Reflection Render Element. Using these component parts of the reflection, you can fine-tune the reflection in your final composite.



The Raw Reflection Render Element is useful for changing the appearance of reflective scene elements in compositing or image editing software after the scene is rendered. Below are a couple of examples of its use.


Reflection Filter


The Reflection Filter Render Element stores reflection information calculated from the materials' reflection values in the scene. Surfaces with no reflection values set in their material(s) contain no information in the render pass and render it black.

While the Raw Reflection Render Element gives the full reflection of objects reflecting in the scene, the Reflection Filter shows how much of that reflection should come through in the composite. In other words, the filter defines the strength of the reflection, while the raw image defines what is being reflected in the image. When these two elements are multiplied, the true level of reflection is given and produces Reflection. Using these component parts of the reflection, you can better fine-tune the reflection in your final composite.

The reflection element is a key component in the main Beauty Pass.


Reflection Glossiness



The Reflection Glossiness Render Element stores the image's reflection glossiness as a grayscale image that represents the degree of Reflection Glossiness set for materials in the scene. White areas have the most reflection glossiness, while dark areas have little.

The amount of reflection glossiness for a material is set by its Reflection Glossiness parameter. For example, V-Ray Material (VRayMtl) has a Reflection Glossiness parameter.


Reflection Index

The Reflection Index Render Element returns an image with floating-point values corresponding to the Fresnel IOR values of scene objects' materials.

This render element can enhance or reduce Fresnel IOR effects in the final composite. Note that the values generated in this render element are often above 1, so the image may appear simply black and white. Sampling the pixel values in the white areas will return the precise floating-point value stored, representing the rendered object's Fresnel IOR numbers.

Examples of materials that have Fresnel IOR parameters that could be represented in this render element are V-Ray Material (VRayMtl) and Skin Material (VRaySkinMtl).

The Reflection Index Render Element is useful for changing the appearance of reflective elements after rendering in a compositing or image editing software.


Refraction


Refractions are caused by bending light through different densities of materials that allow light to pass through them, such as glass, water, etc.

Overview

When a material has a refraction value (as set through the Refraction Color and Refraction Amount parameters of a V-RayMtl material), the resulting render displays the appropriate refraction information in the final image as well as in the possible three refraction elements that are used in compositing: Refraction, Raw Refraction, and Refraction Filter.

  • Refraction Render Element – This element is a key component in the main Beauty Pass. It displays the proper refraction according to the values set in the material. It is easy to adjust this element for brightness, coloration, etc., of the refractions in your scene without the need to rerender. This element is often used by itself but can be further controlled by the other two refraction elements listed below.
  • Raw Refraction – This element is a key component of the Refraction Render Element and contains the pure surface refraction before it is multiplied by the refraction filter color. This element must be multiplied by the Refraction Filter for proper refraction in the final composite as intended for the material.
  • Refraction Filter – This element is a key component of the Refraction Render Element. The refraction filter properly attenuates the amount of refraction a surface is designed to have by virtue of the Refraction Amount parameter set for its material. The refraction filter must be multiplied by the raw refraction in the composite.


All of them are of the type: RenderChannelColor

The raw refraction element gives the full refraction of objects refracting in the scene, while the refraction filter sets how much of that refraction should come through in the composite. When these two elements are multiplied, the true level of refraction is given. Using these component parts of the refraction, you can better fine-tune the refraction in your final composite.

Notes

Refracted render channels often override information seen through glossy materials like windows.

Refraction render elements can be changed without re-rendering in a compositing program.

These render elements can be added and subtracted from existing Refractions within the scene.

When a Matte Render Element is used, certain objects or materials within the scene can be isolated at a composite level, and the refractivity of these items can be changed without rerendering.

Refraction

The Refraction Render Element stores refraction information calculated from materials--such as glass or water--that refract objects behind them in the camera's view. This means the brightness, coloration, etc., of the refractions can be adjusted without rerendering.

Any material in a scene with a value set for its Refraction parameter will generate refraction information that can be seen in this render element. A surface with no refraction values set in its material(s) will contain no information in the render element and render black.

The Refraction Render Element is a key component in the main Beauty Element and can easily be used to control the refractions in the Beauty composite.

The Refraction Render Element is already a composite of the Raw Refraction Render Element multiplied by the Refraction Filter Render Element. When finer control over refractions is needed in the composite, add these additional two channels to the output along with the Refraction render element channel.



The Refraction Render Element is useful for changing the appearance of refractive elements after rendering in a compositing or image editing application. Below are a couple of examples of possible uses.


Refraction Render Element

Original Beauty Composite

Brightened Refractions

Tinted Refractions



Raw Refraction x Refraction Filter = Refraction

Raw Refraction



The Raw Refraction Render Element is a color image that stores refraction information calculated from materials' refraction values in the scene. Surfaces with no refraction values set in their materials contain no information in the render element and render it black.

In comparison, the Refraction Filter Render Element (VRayRefractionFilter) is a render element that indicates varying degrees of refraction in the scene through brightness values in the image. Multiplying these render elements together produces the Refraction Render Element (VRayRefraction).

To correctly calculate the Raw Refraction Render Element, the Refraction Render Element must also be added to the list of render elements being calculated during the rendering process to determine all the refraction information in the scene properly.

The Raw Refraction Render Element is useful for changing the appearance of refractive elements after rendering in a compositing or image editing application. Below are examples of possible uses.


Refraction Filter

The Refraction Filter Render Element is an image that stores refraction information calculated from the materials' refraction values in the scene. Materials with no refraction values appear black, while refractive materials appear white (maximum refraction) or gray (lesser amounts of refraction). If any hue (color) is specified in the material's Refractive Color parameter, that hue and value will be represented here in the Refraction Filter and affected by the refraction's Amount parameter.

In comparison, the Raw Refraction Render Element (VRayRawRefraction) is a color render element that considers materials and their colors when rendering refraction. Multiplying these render elements together produces the Refraction Render Element (VRayRefraction).

To correctly calculate the Refraction Filter Render Element, the Refraction Render Element must also be added to the list of render elements being calculated during the rendering process to determine all the refraction information in the scene properly.



The Refraction Filter Render Element is useful for changing the appearance of refractive elements after rendering in a compositing or image editing application. Below are examples of possible uses.



Refraction Render Element


Original Beauty Composite


Refraction Filter Render Element





Brightened Refractions


Tinted Refractions


To properly calculate the refraction information in the Refraction Filter and Raw Refraction Render Elements, the Refraction Render Element must also be rendered simultaneously, even if it's not going to be used in the compositing process. Doing so enables the rendering calculations to include all the refraction information.


Specular


Overview

Type: RenderChannelColor

The Specular Render Element is an image that stores specular reflection (basically put, highlight) information calculated from the material's reflection value in the scene. Specular reflection is defined as the reflection of light from a surface in a single particular reflection, as opposed to a diffuse reflection, which is reflected at many angles.

The brighter the area, the more highlight reflection the object exhibits in the render. Specular highlights are colored if the Reflection Color parameter of a material is colored.



Evaluating the Specular Render Element

In most scenes, the Specular Render Element renders mostly black with some gray or completely black. Only materials that are set up to reflect and reflect a highlight in the rendered scene are rendered as having image value in the render element. Shades of gray (or shades of color) in the Specular Render Element rarely reach full value (white in most cases); a white or full value pixel indicates that the material is completely made up of reflected light at that point, which is rare in realistic scenes. Surfaces with no reflection values set in their material(s) contain no information in the render element and render as black.

Specular light primarily appears on reflective surfaces with a low incidence angle to a bright surface or light source. Lowering the material's gloss value below 1.0 or increasing the IOR can increase this effect.

Common Uses

The Specular Render Element is useful for changing the final image's specular appearance during compositing. Below are a couple of examples of its use.


Specular Render Element

Original Beauty composite

Brightened Specular

Blurred Specular



Underlying Compositing Formula

The Specular Render Element is added to the Beauty composite to form the final image.



We'll leave the advanced Beauty render elements - Atmosphere, Background, Caustics, Self Illumination, and Subsurface Scattering for the next chapter.

Parameters

Most of the above render elements can be stored in the RenderChannelColor plugin. It has the following parameters:

  • name - String
  • alias - int
  • color_mapping - true to apply color mapping to the channel; false otherwise
  • consider_for_aa - boolean
  • filtering - boolean
  • derive_raw_channels - true if raw channels should be derived from the respective color and filter channel
  • vfb_color_corrections - False to disable ALL VFB color corrections(sRGB, curves, white balance, etc...) when saving the channel data to a file or showing it on display. True to apply VFB color corrections when saving the channel data to a file or showing it on a display. If true, some color corrections might still be disabled, based on the type of file being saved.


Examples

The above example renders (not the comparison schematics) are rendered using the file "Render_Elements.vrscene" from the scene bundle. See the comments inside the scene file and comment/uncomment respective #includes for generating advanced render elements, which we'll cover in the next section. Here's the final composited Beauty renderer:



Code example

The render elements available in the scene can be obtained using the following code:


# Compatibility with Python 2.7.
from __future__ import print_function
 
# The directory containing the vray shared object should be present in the PYTHONPATH environment variable.
# Try to import the vray module from VRAY_SDK/python, if it is not in PYTHONPATH
import sys, os
VRAY_SDK = os.environ.get('VRAY_SDK')
if VRAY_SDK:
    sys.path.append(os.path.join(VRAY_SDK, 'python'))
import vray
 
SCENE_PATH = os.path.join(os.environ.get('VRAY_SDK'), 'scenes')
# Change the process working directory to SCENE_PATH in order to be able to load relative scene resources.
os.chdir(SCENE_PATH)
 
def addExampleRenderElements(renderer):
    reManager = renderer.renderElements
    # In Python and JS we use strings:
    print('All render element (channel) identifiers:')
    print(reManager.getAvailableTypes())
    # The RGB channel is always present. It is often referred to as "Beauty" by compositors
    # Alpha is also always included
    # --- BEAUTY ELEMENTS ---
    # "Beauty" elements are the components that make up the main RGB channel,
    # such as direct and indirect lighting, specular and diffuse contributions and so on.
    # Light bounced from diffuse materials (layers)
    reManager.add('diffuse')
    # Light from glossy reflections
    reManager.add('reflection')
    # Refracted light
    reManager.add('refraction')
    # Light from perfect mirror reflections
    reManager.add('specular')
    # Subsurface scattered light
    reManager.add('sss')
    # Light from self-illuimnating materials
    reManager.add('self_illumination')
    # Global illumination, indirect lighting
    reManager.add('gi')
    # Direct lighting
    reManager.add('lighting')
    # Sum of all lighting
    reManager.add('total_light')
    # Shadows, combined with diffuse. Shadowed areas are brighter
    reManager.add('shadow')
    # Reflected light if surfaces were fully reflective
    reManager.add('raw_reflection')
    # Refracted light if surfaces were fully refractive
    reManager.add('raw_refraction')
    # Attenuation factor for reflections. Refl = ReflFilter * RawRefl
    reManager.add('reflection_filter')
    # Attenuation factor for refractions. Refr = RefrFilter * RawRefr
    reManager.add('refraction_filter')
    # Intensity of GI before multiplication with the diffuse filter
    reManager.add('raw_gi')
    # Direct lighting without diffuse color
    reManager.add('raw_light')
    # Sum light without diffuse color
    reManager.add('raw_total_light')
    # Shadows without the diffuse factor
    reManager.add('raw_shadow')
    # Grayscale material glossiness values
    reManager.add('reflection_glossiness')
    # Glossiness for highlights only
    reManager.add('reflection_hilight_glossiness')
    # --- MATTE ELEMENTS ---
    # Matte elements are used for masking out parts of the frame when compositing.
    # Color is based on material ID, see MtlMaterialID plugin
    reManager.add('material_id')
    # Color is based on the objectID of each Node
    reManager.add('node_id')
    # --- GEOMETRIC ELEMENTS ---
    # Geometric data such as normals and depth has various applications
    # in compositing and post-processing.
    # The pure geometric normals, encoded as R=X, G=Y, B=Z
    reManager.add('normals')
    # Normals after bump mapping
    reManager.add('bump_normals')
    # Normalized grayscale depth buffer
    reManager.add('z_depth')
    # The per-frame velocity of moving objects
    reManager.add('velocity')
 
# Create an instance of VRayRenderer for production render mode. The renderer is automatically closed after the `with` block.
with vray.VRayRenderer() as renderer:
    renderer.renderMode = 'production'
     # Register a simple log callback. Always useful for debugging.
    def dumpMsg(renderer, message, level, instant):
        if level == vray.LOGLEVEL_ERROR:
            print("[ERROR]", message)
        elif level == vray.LOGLEVEL_WARNING:
            print("[Warning]", message)
        elif level == vray.LOGLEVEL_INFO:
            print("[info]", message)
        # Uncomment for testing, but you might want to ignore these in real code
        #else: print("[debug]", message)
    renderer.setOnLogMessage(dumpMsg)
    # Load scene from a file.
    renderer.load(os.path.join(SCENE_PATH, 'cornell_new.vrscene'))
    # Resize *after* loading the scene
    renderer.size = (320, 200)   
    # This will add the necessary channel plugins to the scene
    addExampleRenderElements(renderer)
    # Start rendering.
    renderer.startSync()
    # Render elements are available when the first bucket region is ready
    # Here, we simply wait for the entire image to be completed before we access the render elements
    renderer.waitForRenderEnd()
    # Access render elements via the VRayRenderer instance
    allRenderElements = renderer.renderElements.getAll()
    # List all available render elements and process each one
    for re in allRenderElements:
        print ('{0}. {1}, Format({2}), PixelFormat({3})'.format(re.type, re.name, re.binaryFormat, re.defaultPixelFormat))
        # Output render element's data as an image
        # Optionally, specify an image sub-region, or leave blank to get the entire image
        img = re.getImage()
        img.save(re.name + ".png")
        # Similar to the image output, get the raw bytes
        # Again, a sub-region can be specified, or the entire data can be obtained if left blank
        rawData = re.getData()
        # Do something with rawData...
#define VRAY_RUNTIME_LOAD_PRIMARY
#include "vraysdk.hpp"
#include "vrayplugins.hpp"
#include "utils.h"

using namespace VRay;
using namespace VRay::Plugins;
using namespace std;

const char *BASE_PATH = getenv("VRAY_SDK");
string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";

void addExampleRenderElements(VRayRenderer &renderer) {
	RenderElements reManager = renderer.getRenderElements();
	// The RGB channel is always present. It is often referred to as "Beauty" by compositors
	// Alpha is also always included
	// Beauty Elements
	// Light bounced from diffuse materials (layers)
	reManager.add(RenderElement::DIFFUSE, NULL, NULL);
	// Light from glossy reflections
	reManager.add(RenderElement::REFLECT, NULL, NULL);
	// Refracted light
	reManager.add(RenderElement::REFRACT, NULL, NULL);
	// Light from perfect mirror reflections
	reManager.add(RenderElement::SPECULAR, NULL, NULL);
	// Subsurface scattered light
	reManager.add(RenderElement::SSS, NULL, NULL);
	// Light from self-illuminating materials
	reManager.add(RenderElement::SELFILLUM, NULL, NULL);
	// Global illumination, indirect lighting
	reManager.add(RenderElement::GI, NULL, NULL);
	// Direct lighting
	reManager.add(RenderElement::LIGHTING, NULL, NULL);
	// Sum of all lighting
	reManager.add(RenderElement::TOTALLIGHT, NULL, NULL);
	// Shadows, combined with diffuse. Shadowed areas are brighter
	reManager.add(RenderElement::SHADOW, NULL, NULL);
	// Reflected light if surfaces were fully reflective
	reManager.add(RenderElement::RAW_REFLECTION, NULL, NULL);
	// Refracted light if surfaces were fully refractive
	reManager.add(RenderElement::RAW_REFRACTION, NULL, NULL);
	// Attenuation factor for reflections. Refl = ReflFilter * RawRefl
	reManager.add(RenderElement::REFLECTION_FILTER, NULL, NULL);
	// Attenuation factor for refractions. Refr = RefrFilter * RawRefr
	reManager.add(RenderElement::REFRACTION_FILTER, NULL, NULL);
	// Intensity of GI before multiplication with the diffuse filter
	reManager.add(RenderElement::RAWGI, NULL, NULL);
	// Direct lighting without diffuse color
	reManager.add(RenderElement::RAWLIGHT, NULL, NULL);
	// Sum light without diffuse color
	reManager.add(RenderElement::RAWTOTALLIGHT, NULL, NULL);
	// Shadows without the diffuse factor
	reManager.add(RenderElement::RAWSHADOW, NULL, NULL);
	// Grayscale material glossiness values
	reManager.add(RenderElement::VRMTL_REFLECTGLOSS, NULL, NULL);
	// Glossiness for highlights only
	reManager.add(RenderElement::VRMTL_REFLECTHIGLOSS, NULL, NULL);
	// Matte elements
	// Color is based on material ID, see MtlMaterialID plugin
	reManager.add(RenderElement::MTLID, NULL, NULL);
	// Color is based on the objectID of each Node
	reManager.add(RenderElement::NODEID, NULL, NULL);
	// Geometric elements
	// The pure geometric normals, encoded as R=X, G=Y, B=Z
	reManager.add(RenderElement::NORMALS, NULL, NULL);
	// Normals after bump mapping
	reManager.add(RenderElement::BUMPNORMALS, NULL, NULL);
	// Normalized grayscale depth buffer
	reManager.add(RenderElement::ZDEPTH, NULL, NULL);
	// The per-frame velocity of moving objects
	reManager.add(RenderElement::VELOCITY, NULL, NULL);
}

int main() {
	// Change process working directory to SCENE_PATH to be able to load relative scene resources.
	changeCurrentDir(SCENE_PATH.c_str());
	// Load V-Ray SDK library.
	VRayInit init(NULL, true);
	// Create an instance of VRayRenderer for production render mode.
	// The renderer is automatically closed at the end of the current scope.
	VRayRenderer renderer;
	renderer.setRenderMode(VRayRenderer::RENDER_MODE_PRODUCTION);
	// It's recommended to always have a console log
	renderer.setOnLogMessage(logMessage);
	// Load scene from a file.
	renderer.load("cornell_new.vrscene");
	// Resize *after* loading the scene.
	renderer.setImageSize(320, 200);
	// This will add the necessary channel plugins to the scene
	addExampleRenderElements(renderer);
	// Start rendering.
	renderer.startSync();
	// Render elements are available when the first bucket region is ready
	// Here, we simply wait for the entire image to be completed before we access the render elements
	renderer.waitForRenderEnd();
	// Access render elements via the VRayRenderer instance
	std::vector<RenderElement> allRenderElements = renderer.getRenderElements().getAll(RenderElement::Type::NONE);
	// List all available render elements and process each one
	for (const RenderElement& re: allRenderElements) {
		printf("%d. %s, Format(%d), PixelFormat(%d)\n", re.getType(), re.getName().c_str(), re.getBinaryFormat(), re.getDefaultPixelFormat());
		// Output render the element's data as an image
		// Optionally, specify an image sub-region or leave blank to get the entire image
		LocalVRayImage img = re.getImage();
		img->saveToPng(re.getName() + ".png");
		// Similar to the image output, get the raw bytes
		// Again, a sub-region can be specified, or the entire data can be obtained if left blank
		void* data = NULL;
		RenderElement::GetDataOptions options;
		if (size_t dataSize = re.getData(&data, options)) {
			ofstream datFile(re.getName() + ".dat", ios::out | ios::binary);
			datFile.write(reinterpret_cast<const char*>(data), dataSize);
			datFile.close();
			RenderElement::releaseData(data);
		}
	}
	return 0;
}
using System;
using System.IO;
using System.Collections.Generic;
using VRay;
using VRay.Plugins;

namespace _render_elements
{
	class Program
	{
		private static void addExampleRenderElements(VRayRenderer renderer)
		{
			RenderElements reManager = renderer.RenderElements;
			/// --- "BEAUTY" ELEMENTS --- ///
			/// "Beauty" elements are the components that make up the main RGB channel,
			/// such as direct and indirect lighting, specular and diffuse contributions, and so on.
			// The RGB channel is always present. It is often referred to as "Beauty" by compositors
			// Alpha is also always included
			// Light bounced from diffuse materials (layers)
			reManager.Add(RenderElementType.DIFFUSE, "", "");
			// Light from glossy reflections
			reManager.Add(RenderElementType.REFLECT, "", "");
			// Refracted light
			reManager.Add(RenderElementType.REFRACT, "", "");
			// Light from perfect mirror reflections
			reManager.Add(RenderElementType.SPECULAR, "", "");
			// Subsurface scattered light
			reManager.Add(RenderElementType.SSS, "", "");
			// Light from self-illuminating materials
			reManager.Add(RenderElementType.SELFILLUM, "", "");
			// Global illumination, indirect lighting
			reManager.Add(RenderElementType.GI, "", "");
			// Direct lighting
			reManager.Add(RenderElementType.LIGHTING, "", "");
			// Sum of all lighting
			reManager.Add(RenderElementType.TOTALLIGHT, "", "");
			// Shadows, combined with diffuse. Shadowed areas are brighter
			reManager.Add(RenderElementType.SHADOW, "", "");
			// Reflected light if surfaces were fully reflective
			reManager.Add(RenderElementType.RAW_REFLECTION, "", "");
			// Refracted light if surfaces were fully refractive
			reManager.Add(RenderElementType.RAW_REFRACTION, "", "");
			// Attenuation factor for reflections. Refl = ReflFilter * RawRefl
			reManager.Add(RenderElementType.REFLECTION_FILTER, "", "");
			// Attenuation factor for refractions. Refr = RefrFilter * RawRefr
			reManager.Add(RenderElementType.REFRACTION_FILTER, "", "");
			// Intensity of GI before multiplication with the diffuse filter
			reManager.Add(RenderElementType.RAWGI, "", "");
			// Direct lighting without diffuse color
			reManager.Add(RenderElementType.RAWLIGHT, "", "");
			// Sum light without diffuse color
			reManager.Add(RenderElementType.RAWTOTALLIGHT, "", "");
			// Shadows without the diffuse factor
			reManager.Add(RenderElementType.RAWSHADOW, "", "");
			// Grayscale material glossiness values
			reManager.Add(RenderElementType.VRMTL_REFLECTGLOSS, "", "");
			// Glossiness for highlights only
			reManager.Add(RenderElementType.VRMTL_REFLECTHIGLOSS, "", "");
			/// --- MATTE ELEMENTS --- ///
			/// Matte elements are used for masking out parts of the frame when compositing.
			// Color is based on material ID, see MtlMaterialID plugin
			reManager.Add(RenderElementType.MTLID, "", "");
			// Color is based on the objectID of each Node
			reManager.Add(RenderElementType.NODEID, "", "");
			/// --- GEOMETRIC ELEMENTS --- ///
			/// Geometric data such as normals and depth has various applications in compositing and post-processing.
			// The pure geometric normals, encoded as R=X, G=Y, B=Z
			reManager.Add(RenderElementType.NORMALS, "", "");
			// Normals after bump mapping
			reManager.Add(RenderElementType.BUMPNORMALS, "", "");
			// Normalized grayscale depth buffer
			reManager.Add(RenderElementType.ZDEPTH, "", "");
			// The per-frame velocity of moving objects
			reManager.Add(RenderElementType.VELOCITY, "", "");
		}

		static void Main(string[] args)
		{
			string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");
			// Change process working directory to SCENE_PATH to be able to load relative scene resources.
			Directory.SetCurrentDirectory(SCENE_PATH);
			// Create an instance of VRayRenderer for production render mode. The renderer is automatically closed after the `using` block.
			using (VRayRenderer renderer = new VRayRenderer())
			{
				renderer.RenderMode = RenderMode.PRODUCTION;
				// Add a listener for any type of log message.
				renderer.LogMessage += new EventHandler<MessageEventArgs>((source, e) =>
				{
					// You can remove the if for testing, but you might want to ignore Debug in actual code
					if (e.LogLevel != LogLevelType.Debug)
					{
						Console.WriteLine(String.Format("[{0}] {1}", e.LogLevel.ToString(), e.Message));
					}
				});
				// Load scene from a file.
				renderer.Load("cornell_new.vrscene");
				// Resize *after* loading the scene.
				renderer.SetImageSize(320, 200);
				// This will add the necessary channel plugins to the scene
				addExampleRenderElements(renderer);
				// Start rendering.
				renderer.StartSync();
				// Render elements are available when the first bucket region is ready
				// Here, we simply wait for the entire image to be completed before we access the render elements
				renderer.WaitForRenderEnd();
				// Access render elements via the VRayRenderer instance
				IEnumerable<RenderElement> allRenderElements = renderer.RenderElements.GetAll(RenderElementType.NONE);
				// List all available render elements and process each one
				foreach (RenderElement re in allRenderElements)
				{
					Console.WriteLine("{0}. {1}, Format({2}), PixelFormat({3})\n", re.Type, re.Name, re.BinaryFormat, re.DefaultPixelFormat);
					// Output render the element's data as an image
					// Optionally, specify an image sub-region or leave blank to get the entire image
					VRayImage img = re.GetImage();
					img.SaveToPNG(re.Name + ".png");
					// Similar to the image output, get the raw bytes
					// Again, a sub-region can be specified, or the entire data can be obtained if left blank
					RenderElement.GetDataOptions options = new RenderElement.GetDataOptions();
					byte[] rawData = re.GetData(options);
					// Do something with rawData...
				}
			}
		}
	}
}
var path = require('path');
var vray = require(path.join(process.env.VRAY_SDK, 'node', 'vray'));
 
var SCENE_PATH = path.join(process.env.VRAY_SDK, 'scenes');
// Change process working directory to SCENE_PATHtoo be able to load relative scene resources.
process.chdir(SCENE_PATH);
 
var addExampleRenderElements = function(renderer) {
	var reManager = renderer.renderElements;
	// In Python and JS, we use strings:
	console.log('All render element (channel) identifiers:');
	console.log(reManager.getAvailableTypes());
	// The RGB channel is always present. It is often referred to as "Beauty" by compositors
	// Alpha is also always included
	// --- BEAUTY ELEMENTS ---
	// "Beauty" elements are the components that make up the main RGB channel,
	// such as direct and indirect lighting, specular and diffuse contribution, etc.
	// Light bounced from diffuse materials (layers);
	reManager.add('diffuse');
	// Light from glossy reflections
	reManager.add('reflection');
	// Refracted light
	reManager.add('refraction');
	// Light from perfect mirror reflections
	reManager.add('specular');
	// Subsurface scattered light
	reManager.add('sss');
	// Light from self-illuimnating materials
	reManager.add('self_illumination');
	// Global illumination, indirect lighting
	reManager.add('gi');
	// Direct lighting
	reManager.add('lighting');
	// Sum of all lighting
	reManager.add('total_light');
	// Shadows, combined with diffuse. Shadowed areas are brighter
	reManager.add('shadow');
	// Reflected light if surfaces were fully reflective
	reManager.add('raw_reflection');
	// Refracted light if surfaces were fully refractive
	reManager.add('raw_refraction');
	// Attenuation factor for reflections. Refl = ReflFilter * RawRefl
	reManager.add('reflection_filter');
	// Attenuation factor for refractions. Refr = RefrFilter * RawRefr
	reManager.add('refraction_filter');
	// Intensity of GI before multiplication with the diffuse filter
	reManager.add('raw_gi');
	// Direct lighting without diffuse color
	reManager.add('raw_light');
	// Sum light without diffuse color
	reManager.add('raw_total_light');
	// Shadows without the diffuse factor
	reManager.add('raw_shadow');
	// Grayscale material glossiness values
	reManager.add('reflection_glossiness');
	// Glossiness for highlights only
	reManager.add('reflection_hilight_glossiness');
	// --- MATTE ELEMENTS ---
	// Matte elements are used for masking out parts of the frame when compositing.
	// Color is based on material ID, see MtlMaterialID plugin
	reManager.add('material_id');
	// Color is based on the objectID of each Node
	reManager.add('node_id');
	// --- GEOMETRIC ELEMENTS ---
	// Geometric data such as normals and depth has various applications
	// in compositing and post-processing.
	// The pure geometric normals, encoded as R=X, G=Y, B=Z
	reManager.add('normals');
	// Normals after bump mapping
	reManager.add('bump_normals');
	// Normalized grayscale depth buffer
	reManager.add('z_depth');
	// The per-frame velocity of moving objects
	reManager.add('velocity');
}
 
// Create an instance of VRayRenderer for production render mode.
var renderer = vray.VRayRenderer();
renderer.renderMode = "production";
 // It's recommended to always have a console log callback
renderer.on("logMessage", function (message, level, instant) {
	if (level == vray.LOGLEVEL_ERROR)
		console.log("[ERROR] ", message);
	else if (level == vray.LOGLEVEL_WARNING)
		console.log("[Warning] ", message);
	else if (level == vray.LOGLEVEL_INFO)
		console.log("[info] ", message);
	// Uncomment for testing, but you might want to ignore these in real code
	//else console.log("[debug] ", message);
});
// Load scene from a file asynchronously.
renderer.load("cornell_new.vrscene", function(err) {
	if (err) throw err;
	// Resize *after* loading the scene.
	renderer.size = { width: 320, height: 200 };
	// This will add the necessary channel plugins to the scene
	addExampleRenderElements(renderer);
	// Start rendering.
	renderer.startSync();
	// Render elements are available when the first bucket region is ready
	// Here, we simply wait for the entire image to be completed before we access the render elements
	renderer.waitForRenderEnd(function() {
		// Access render elements via the VRayRenderer instance
		var allRenderElements = renderer.renderElements.getAll()
		// List all available render elements and process each one
		allRenderElements.forEach(function (re) {
			console.log(re.type + ". " + re.name + ", Format(" + re.binaryFormat + "), PixelFormat(" + re.defaultPixelFormat + ")");
			// Output render element's data as an image
			// Optionally, specify an image sub-region, or leave blank to get the entire image
			var img = re.getImage();
			img.saveSync(re.name + ".png");
			// Similar to the image output, get the raw bytes
			// Again, a sub-region can be specified, or the entire data can be obtained if left blank
			var rawData = re.getData();
			// Do something with rawData...
		});
		// Closes the renderer.
		renderer.close();
	});
});
  • No labels
Was this helpful?