Category Archives: shaders

MILA updates

On the nVidia forum you’ll see the Layering Library continues to evolve. New features will include:

  • Improved weighting between layers
  • A Quality control for glossy reflection and refaction (to replace ray count). This handles these effects based on roughness and importance. (Changing the roughness of a surface no longer requires re-tweaking ray counts for smooth renders) Also includes a global scene control defaulted to 1.0 as a String Option This will allow developers to improve and change the algorithm without interrupting the user’s workflow.
  • A new and improved flakes shader that will continue to evolve with more flexibility including cellular noise, different distribution, and shapes. Users can control weight, density, perturbation and more.
Multi-level and color flakes

Multi-level and color flakes

Something to note about the flakes shader is the use scenarios are going to be beyond that of metallic flakes. Think of cosmetics packaging and snow for instance. Some more controls and a node-based design will help you to combine these in more ways. The previous issues with repeating patterns found in the flake shader have also been resolved.

**IMPORTANT: A change in controls will often cause a break in Maya for previous scenes. You may find your assigned shader groups are no longer attached to a material. Also, the current documents need updated in the next release**

Flake Applied as Glossy Reflection Layer Bump

Flake Applied as Glossy Reflection Layer Bump (more subtly can be used to simulate “orange peel” effect)

Flake as a Weight to red Glossy Reflection
Flake as a Weight to red Glossy Reflection

Using Framebuffers with the Layering Library (MILA)

You can take a brief look at the main structure of the MILA shaders inside Maya in the first post explaining their usage: The Layering Library (MILA)

One of the most important things to remember about MILA is how the framebuffer passes work.

The builtin framebuffers use the modern framebuffer mechanism in mentalray that uses a named framebuffer and type.

Your main framebuffers are additive; this means in compositing you simply add or plus the passes together to create your beauty. This avoids other operations that might cause problems like multiplication. Multiplying in compositing causes problems with edges and makes it impossible to recreate the beauty render. It also complicates compositing objects onto one another or plates.

Your main passes are (First given as a Light Path Expression (LPE)):

  • L<RD>E  or direct_diffuse
  • L.+<RD>E or indirect_diffuse
  • L<RG>E or direct_glossy
  • L.+<RG>E or indirect_glossy
  • L<RS>E or direct_specular
  • L.+<RS>E or indirect_specular
  • L.+<TD>E or diffuse_transmission
  • L.+<TG>E or glossy_transmission
  • L.+<TS>E or specular_transmission
  • LTVTE and/or front_scatter and back_scatter
  • emission (in LPE, emission is actually a light)

Direct effects are usually the result of the light source.

Indirect effects are usually the result of light from other objects.

Why include LPE? LPE makes specifying passes the same for all rendering solutions. This idea unifies the conventions used for getting the same data regardless of renderer used.

You also have the option to add custom shaders on top of this in the material root node. Keep in mind that what is added here may increase render time since they are run separately from the material and we typically reserve them for inexpensive utility passes like noise, fresnel, and ID mattes.

The Root node, the mila_material This includes the ability to create and attach custom framebuffers for output

The Root node, the mila_material This includes the ability to create and attach custom framebuffers for output

Getting these framebuffer passes from Maya requires a bit of a workaround using a legacy user pass system rediscovered by Brenton. I find it to be easier than using Custom Color with the exception you have to keep track of the names of your passes and spell them correctly to match up. MILA also makes it a universal solution since all shaders are set to automatically write to these buffers without more work. This is part of the idea behind LPE: the  light path stored is always the same for the LPE chosen regardless of renderer. Making this automatic is an easy decision in this case.

For the passes built into MILA you simply need to have the framebuffers ready with the correct name and MILA will write to them automatically. Keep in mind that Maya’s current system overwrites data written to their default passes like “diffuse” so you cannot use those or the same names if they are used in the scene.

Fist: Select the miDefaultOptions node

select miDefaultOptions;

Second create a framebuffer:

AEmrUserBuffersAppend miDefaultOptions.frameBufferList;

The above command creates a user framebuffer seen as default below.

A new user framebuffer

A new user framebuffer

You have two selections above: Data Type and whether or not to interpolate (filter) the result.

You typically want to interpolate results for color framebuffers like direct diffuse, ID mattes, fresnel passes, etc. You do NOT want to interpolate data buffers like z-depth, normals, world points, etc.

You can see the typical data types that should not be interpolated at the bottom of the list. These data types are not interpolated by mental ray because it is mathematically incorrect for compositing. They also require high precision so you will notice they default to Floating Point 32-bit data.

Framebuffer Data Types - Data Passes

Framebuffer Data Types – Data Passes

I have not used the LPE for direct diffuse because Maya does not allow angled brackets and other symbols in text fields for names at this point. After creating and naming your passes, you can then add them to the camera Output Shaders as the last step to render them.

mental ray tab, add an output pass

mental ray tab, add an output pass

When you create an entry you will see a Output Pass that looks like the default one below.

Default Output Shader

Default Output Shader

Since we have already created passes, you can select the “Use User Buffer” option, then in the dropdown “user Buffer” menu, select the pass you want. Below is the direct_diffuse example:

Direct Diffuse Output Shader

Direct Diffuse Output Shader

I then select the following options:

  • File Mode: I want to write to the rendered file
  • Image Format: OpenEXR, I have already specified 16-half float and EXR as my rendering format in the main Render Settings editor.
  • File Name Postfix: I leave this blank. This way all of the passes are written to the same EXR and packed together as layers.

You can follow this same method when adding user passes to the mila_material root. Be sure and name them the same as the pass you will create and then reference in the camera Output Shader

Added Color and Vector buffers

Added Color and Vector buffers

Keep in mind that the usual Maya Default passes for data will still work with MILA and you can select those as well instead of adding those default passes here. It’s useful here if you need different or additional data per shader. ID Mattes are very useful in this case. And in fact, this shader can detect and use the user_data shaders for you to assign ID groups and other data to objects. This means you can render complex scenes with fewer shaders and still organize the passes logically. This will be a future explanation since this introduces a new workflow/pipeline for getting information from Maya while avoiding the Render Layers system when possible.

In the example file below you’ll see I am driving some parameters of the shader with attached object data. This has a few benefits. One such benefit is the data follows the object rather than the shader and you can change the result of the shader by manipulating the object user_data. I also have a single sphere in one ID matte group but also included with another group of ID mattes, giving me different ways to handle the object in post.

You can find an example workflow in this Maya File [removed since MILA updates broke it, need to make a new one]. The scene has the default framebuffers and a couple ID mattes set up. You can play with the materials and quality to get other buffers to show a result (for example, emission is empty because I am not using that effect.) I also have single-layer materials. Try mixing and matching and seeing the resulting framebuffers. Be sure and attach your own HDRI to the Maya IBL Image.

(Maya 2013 SP2)

Additional layering/mixing is left to user experimentation.

The Layering Library (MILA) UI: BETA SHADERS

*These materials have been released for Maya 2015. The below post applies to the Beta shaders. There have been changes to the materials and SIGNIFICANT changes to how they are presented/integrated inside Maya 2015. Please see the newer posts on these.*

Shaders were previously announced for future beta here and have been released today.

Below are the UIs and brief descriptions of the various parts of the Layering Library known as MILA. More complex examples and Phenomenon© will become later posts. But this should get you started on the basics. The next post will show how to create framebuffers in Maya using the legacy user framebuffer mechanism. Since framebuffers are simply named and built-in, it makes for easy rendering without making connections in Maya.

This library is currently designed as a flexible replacement for (at a minimum) the fast_sss, metalllic paint, car paint, and mia_material shaders. (You should have hopefully abandoned Lambert, Blinn, Phong, etc quite some time ago in mental ray. . .)

This begins the bridge to more modern flexible rendering by following the nVidia Material Definition Language. You may find this a little familiar if you have used the iray layered material.

The image below is rendered from the Unified Sampling post with MILA: glossy reflection, scattering, and diffuse reflection. The lighting is Environment Lighting Mode and final gathering. Depth of Field and image rendered brute force with Unified Sampling.

MILA multi-threaded scattering at work

MILA multi-threaded scattering at work

The shaders introduce several important things:

  • Built-in framebuffers handled by the root node.
  • Better importance sampling
  • Improved glossy reflection with a default linear curve
  • Scattering node that no longer uses a pre-process or lightmapping phase and is multi-threaded
  • Default physical correctness and energy conservation (without the emission node) regardless of layering/mixing
  • Shared light loops that improve performance when layering shaders
  • Framebuffers that provide a mathematically correct workflow in compositing by outputting additive passes
  • Framebuffers that introduce you to the Light Path Expression grammar and concepts
  • Correct lighting scale without need for 1/pi multiplication with modern lighting like the user_ibl_env and the Native IBL
  • etc.

Why use MILA? Beyond their forward looking design there are some more logical reasons to use these shaders.

These shaders free the developer and artist in a few different ways.

For developers using the MILA API, you can create your own components to share in the framework. This means you can create and update a component at a time. By building phenomenon from the networks, your updates and additions can be made immediately available without coding and compiling multiple monolithic shaders. Debugging individual pieces can also be easier and faster before creating a phenomenon.

For artists it introduces better performance, more flexibility, and a workflow designed for future shading and lighting. While all the components may seem tedious to begin setting up in Maya, these can be Phenomenized easily. This means shaders can be used and shared as Phenomenon over and over again with a simplified UI. For example: opaque objects do not require shaders with controls like “refraction” or “translucency”. You can greatly reduce the control set and expose what you need, even setting your own defaults for specific materials to re-use later. (Some useful Phenomenon come with the package)

Caveats in Maya for the Beta:

  • These are not integrated shaders by Autodesk as yet, these are as-is
  • Maya does not automatically connect Shadow and Photon shaders to the mila_material node
  • Components make their own unnecessary Shading Group at creation. They are easily removed by using “Delete Unused Shaders” from the Hypershade menu
  • Some convenient global features like per-component samples rely on String Options (found in the miDefaultOptions and explained here)
  • The automatic creation of the UI from the node factory (.mi files) may have errors, these need to be discovered during the Beta
  • Shader updates may break previous scenes saved with MILA shaders
  • Use area lights for lighting!

Some of the above problems can be solved through UI creation with mel. As part of the Beta, you can collaborate on useful AEtemplate and presets for the nodes.

The main components of the node follow a familiar pattern for those of you used to either the DGS material or iray.

From the docs. © nVidia

From the docs. © nVidia

Diffuse Reflection and Transmission

Glossy Reflection and Transmission

Specular Reflection and Transmission

(Scattering is handled separately as well as emission)

Below is an example from the documents on a possible layering scenario at two levels. Keep in mind that layering and mix nodes can also be plugged into one another. This makes layering easier when you need to combine effects or re-use networks you have already built as part of another network.

A one-level layered network from the docs. © nVidia

A two-level layered network from the docs. © nVidia

As I explain some components I assume a familiarity with the mia_material as some of those settings and concepts are repeated here. So instead I will touch on things that have changed or are new.

The mila_material node: This is the root node of the network.

mila_material root without added buffers

mila_material root without added buffers

  • Visibility: this is like the “cutout opacity” of the mia_material

The top shader connection is meant for a layer or mix node explained below.

This contains the built-in framebuffers and a way to expose them at render time by showing them in the primary buffer using the “Show Framebuffer” integer. In Maya this can be enumerated in the .mi file to make the UI more intuitive.

The additional “Extra” framebuffers can be specified here to run other shaders and utilities when the shader is executed. An example would be an Extra Color for a label or ID pass used in compositing.

The mila_layer node: Used to layer components, other layer nodes, and mix nodes together.

Fresnel weighting of diffuse colors

Fresnel weighting of diffuse colors

Below is the default empty node with the familiar “Thin Walled” parameter from the mia_material

The default Layering Node

The default Layering Node

The below example has a single top layer added. Each new layer added is beneath the previous layer when it is rendered. (Top – down design)

Multiple layers with different weights and selective bump mapping applied.

Multiple layers with different weights and selective bump mapping applied.

Adding unbumped reflection makes the components below appear encased.

Adding unbumped reflection makes the components below appear encased.

The Layering node with a layer added to the top.

The Layering node with a layer added to the top.

  • Shader: for adding a component such as mila_glossy_reflection, layer, or mix node
  • On/Off: turn this layer on or off (participate in rendering)
  • Weight: simple scalar value to decide how much weight or energy absorption this layer has
  • Weight Tint: as above but using a color value, this can tint the result returned by the shader component
  • Use Directional Weight: with the feature off, the resulting component has no fresnel or directional falloff curve. The effect is applied evenly over the surface.
  • Fresnel Mode: this mode uses Ior to control the curve used for the component effect, this is familiar from the mia_material “use fresnel” switch
  • Custom Mode:  this is used to apply a Schlick curve that can be manually changed on the shader, this is familair from the mia_material (opportunity to hide/expose the control based on a mel selection of Directional Weight Mode)
  • Bump: per component bump applications, for now in Maya you need to use the Connection Editor since drag and drop or regular connection from the menu fails to work. Maya expects a shader for a bump node and not a vector so it gets confused.

The mila_mix node: Used to simply mix components together. Rather than think of a top -> down approach as in layering, think of simply mixing two paints together. Red and Blue make Purple for example.

Below is the default empty node with the same “Thin Walled” option as well as a way to change the energy conservation to a clamp mode.

The default Mix node

The default Mix node

The below mila_mix example has two components added to the node.

The Mix node with 2 added components to mix

The Mix node with 2 added components to mix

  • Shader: accepts a component, other mix, or layer node
  • On/Off: turn this layer on or off (participate in rendering)
  • Weight: simple scalar value to decide how much weight or energy absorption this layer has
  • Weight Tint: as above but using a color value, this can tint the result returned by the shader component
  • Bump: per component bump applications, for now in Maya you need to use the Connection Editor since drag and drop or regular connection from the menu fails to work. Maya expects a shader for a bump node and not a vector so it gets confused.

The mila_diffuse_reflection node: this is the Lambertian (or Oren-Nayer using roughness) node that is very similar to the mia_material.

There is an added feature, the Rgb Bump vector. This is used to quickly simulate a sub-surface scattering effect when a bump is applied to a diffuse surface. This is not useful without a bump effect applied to the shader in the layer or mix node. This allows colors to be applied to a bump in varying degrees and therefor simulating an inexpensive and shallow scattering effect.

Diffuse reflection, Lambert and Oren-Nayer style diffuse scattering

Diffuse reflection, Lambert and Oren-Nayer style diffuse scattering

The mila_diffuse_transmission node: this is a simple node used for translucency effects.

Diffuse transmission, different shades of grey utilizing 'thin walled'

Diffuse transmission, different shades of grey utilizing ‘thin walled’

There is an indirect multiplier node for controlling indirect interactions such as final gathering

Diffuse Transmission is Translucency

Diffuse Transmission is Translucency

The mila_glossy_reflection node: this is the glossy (blurry or rough) reflection node. This node has received quite a bit of attention and should get a lot of testing to further improve it through feedback.

Glossy reflection with varying roughness.

Glossy reflection with varying roughness.

Glossy Reflection, blurry or rough reflection. Default curve is linear.

Glossy Reflection, blurry or rough reflection. Default curve is linear.

Things to notice that are different than the mia_material:

  • Roughness: this is the amount of blur for the reflection. 0.0 is a mirror-like reflection while 1.0 is diffuse reflection. This is a visually linear curve and the direct reflections now match the indirect reflections, unlike the reflection and specular (direct reflection) response of the mia_material that was originally preferred by artists. Lower ray counts for brute force no longer result in a darker reflection like mia_material. Energy is conserved correctly.
  • Samples: this parameter means the same things as the mia_material but you’ll notice that now 0 samples means ‘take the samples amount from the global string option’ “mila glossy samples” instead of mirror. This is a convenient setting that exists across the shaders so you have one location for setting samples. This is important to simplify rendering and using Unified Sampling. Individual shaders can still be tuned individually if necessary.
  • Visible Area Highlight: an inexpensive application of multiple importance sampling. -1 is the recommended default and allows the shader to choose whether to sample lights indirectly (reflection ray) or a light directly (light sampling). 0.0 is indirect reflection only. 1.0 is direct reflection only. Amounts in-between are mixtures of the schemes. As the roughness increases, so does the possible contribution of direct light sampling. If your area light has insufficient samples or Unified Quality isn’t high enough, these areas will exhibit grain. Using the framebuffers will help you decide where the noise is coming from (indirect or direct glossy reflection).
  • Roughness Exponent: allows the user to change the curve of the glossy parameter from visually linear to something else that might be useful. You may find the amount of 1.5 to be most useful but some testing will help determine the best default for final release.

Important to note: this shader actually performs best with an area light. Spot, point, and directional lights all have zero area to sample and are less intuitive to use when mimicking traditional lighting from the real world. Take a look at the Area Lights 101 post for more ways to simplify and speed up your renders. In the examples here I am using a disc area light with no decay. From the point of interest I aligned it with the sun in the HDR which is also a Native IBL that is emitting light on “automatic” mode.

The mila_glossy_transmission node: this is the glossy (blurry or rough) refraction node. The parameters are similar to above but include ior to refract (bend) rays passing through the object.

Glossy refraction using the same ior of 1.55

Glossy refraction using the same ior of 1.55

Glossy Transmission is blurry or rough refraction

Glossy Transmission is blurry or rough refraction

The mila_specular_reflection node: This node is simply a mirror reflection. It shoots a single ray and can be colored.

Important to note here: this shader is indirect reflection only. This will not generate a highlight for invisible or infinitely small (point) lights. If the light itself must be visible, you must use something that is visible to reflection with an actual size or area such as the user_ibl_rectangle or an area light.

Specular reflection node with various shades of grey tint.

Specular reflection node with various shades of grey tint.

Specular reflection: mirrored, non-glossy surfaces

Specular reflection: mirrored, non-glossy surfaces

The mila_specular_transmission node: Same as above but refracts rays through the object. There is no option to blur the result.

Specular transmission attenuated by grey color to black.

Specular transmission attenuated by grey color to black.

Specular Transmission is for non-glossy refraction

Specular Transmission is for non-glossy refraction

The mila_scatter node: this is the multi-threaded (no lightmap) sub-surface shader. These parameters mean essentially the same thing as the SSS2 shader found in the current documents and Maya 2013. If you are familiar with the new SSS2, then this shader should be simple to control

Subsurface scattering with the front weight attenuated through grey tint

Subsurface scattering with the front weight attenuated through grey tint

The Scattering or SSS node with tinted orange scatter. White is also acceptable/preferred tint to start with.

The Scattering or SSS node with tinted orange scatter. White is also acceptable/preferred tint to start with.

  • Resolution: this is a control that sets the amount of detail the shader will capture in screen space. 2 is the default and means half resolution. 1 is same resolution as render and 0 is double the resolution. Higher numbers decrease the resolution accordingly.

The mila_transparency node: this is simple colored transparency.

This can be layered to create cutout-like effects and transparency in simple cases where ior is not required. But you may find the “thin walled” option in the layering node to be more appropriate.

Simple transparency

Simple transparency

The mila_emission node: this is similar to the “additional color” of the mia_material or incandescence in other materials. It’s simple to use but does not emit light as an object light. Final gather will sample the object as an emitter.

Emission shades of grey multiplied by 2.0 in the shader

Emission shades of grey multiplied by 2.0 in the shader

Emission is for glowing objects (not specifically light emitting, but a fake)

Emission is for glowing objects (not specifically light emitting, but a fake)

The mila_get_roughness node: This utility is so you can use maps painted for the mia_material glossiness inside the mila_glossy nodes without major modification.

A helper to use older maps painted for mia_material glossiness inside MILA

A helper to use older maps painted for mia_material glossiness inside MILA

The mila_get_normal node: this is used to get and alter the normal for bump maps.

This is not needed in Maya. You can manually connect a Maya bump node to the layer or mix node with the connection editor. This node is needed in 3ds Max.

An adapter for bump mapping, not required in Maya, the native bump node works with the help of the connection editor

An adapter for bump mapping, not required in Maya, the native bump node works with the help of the connection editor

NEXT: How to create framebuffers for MILA inside Maya.

The Layering Library (MILA shaders)

If you head over to the NVIDIA-ARC forum, you’ll see a beginning explanation developer thread to testing the Layering Library. This thread will continue to expand. (You must be a registered forum user. Also, the forum does not recognize users automatically for spam reasons, you need to participate by making a post at some point. This also prevents Bots from swarming the board. Once the shader package is linked you may be able to make a post and download it.)

You can participate there and come back to the blog time to time to see other examples and explanations on the shader library.

These shaders begin the transition to other modern techniques with a flexible selection of components. The features include (but not a complete list):

  • Built-in framebuffer outputs
  • Better importance sampling for faster renders
  • Components as separate building blocks for arbitrary layering. A single library can make shaders for many different things from car paint to skin and more.
  • Non-lightmapping scattering shaders (multi-threaded)
  • Light Path Expression options for specifying framebuffer passes
  • Layers maintain energy conservation without user interaction
  • and more. . .

You’ll also notice a re-branding continuing on the site. The main website address is now: http://www.nvidia-arc.com

They are looking for images to use on the main banner, you can even try your hand at some images with the new shaders!