With the release of 2018.3, Shader Graph introduces a new Master Node for the High Definition Render Pipeline (HDRP). This new Master Node (called Lit Master) makes many of the advanced shading features found in HDRP accessible in Shader Graph!
These HD Lit Advanced Features, or HD Lit AF, include coat-mask, iridescence, translucency, subsurface scattering, and anisotropy.
This blog post will introduce you to some of these advanced features, and show you how to use them to create beautiful assets in HDRP using Shader Graph. You can download the sample project created for this blog post from GitHub. This simple project contains a bonsai tree and butterfly that make heavy use of iridescence and translucency.
Before you start creating your absurdly beautiful scenes, there are a few important clauses to be aware of. First, this master node only works within the HDRP. Second, there are no shading equivalents in the Lightweight Render Pipeline (LWRP) for the advanced shading options you will find on this node. If you only need the basic inputs for a PBR surface, we recommend sticking to the PBR master node.
The quickest way to launch into HDRP is to select the High-Definition RP template from the launcher or Unity Hub. The example butterfly project also uses HDRP.
If you are creating a new project with the High-Definition RP template, we recommend you update the version of HDRP in the project from 4.1.0-preview to 4.6.0-preview. To update the version of HDRP, launch the Package Manager from Window > Package Manager. Select the High Definition RP package from the package list. In the top right, you will see an Update to button. Make sure the version to the right of that is 4.6.0, and then hit the Update to button.
Once you’re working in an HDRP Project, you can create a new HD Lit Shader Graph from Create > Shader > Lit Graph. Right away, you will see some of the new input options available. If you have used the HD Lit material in HDRP, this should look more or less the same, but if you haven’t, BentNormal and CoatMask may be unfamiliar terms to you.
Increasing the CoatMask value past 0 (up to a max of 1) will add a clear “coat” effect to your surface. This means your object will look like it has a thin transparent layer of shiny sealant on top of it. Imagine painting an epoxy coating onto your mesh. One popular use of Coat Mask is when creating materials to simulate the look of car paint.
The material assigned to this apple is transitioning between CoatMask value 0 to 1.
Even though CoatMask is a default input on the Lit Master Node, make sure you only use it if it is important for creating the look you are going for. Increasing Coat Mask to anything past 0 will increase the cost of your Shader.
BentNormal allows for input of a special type of map that improves the indirect lighting (GI) for your asset. When used in combination with an AO map it can also provide specular occlusion, which means that you can add occlusion into the reflection on your mesh. You can generate bent normal maps from applications such as Substance Designer, XNormal, or Knald. (However, for your bent normal maps to work correctly, make sure you use Cosine distribution when generating them.)
To use your bent normal map for Specular Occlusion, you must set the Specular Occlusion Mode in the shader settings to From AO And Bent Normal. You can access these settings by selecting the gear icon in the top right corner of the Shader Graph Master Node.
There are four options available for Specular Occlusion: Off, From AO only, From AO and Bent Normal, and Custom.
Selecting Custom creates a new input on the Master Node, giving full Specular Occlusion control to the user. For example, plugging zero into this input will disable all reflections.
The settings menu on the Master Node is loaded with Lit AF options. It is where you can select which advanced material type you plan to utilize in your Shader Graph, as well as set other useful surface information, such as whether the surface is opaque or transparent.
Changing these settings can add additional input options to your Master Node and, depending on the combination of settings you enable, you may end up with a very large node (and an extremely expensive shader).
The sample butterfly project makes heavy use of the Iridescence and Translucency advanced Material Types.
Let's start by taking a look at the butterfly!
A butterfly's wing is a complicated surface made up of multiple layers of tiny scales; these make butterfly wings appear dusty to the human eye. The scales have a high amount of reflectivity and lay on top of a layer of chitin — a transparent protein, which is the main building block of exoskeletons.
This biological information, when translated to our shading model, means the butterfly wing is transparent, iridescent, and metal!
Iridescence is the phenomenon of certain surfaces gradually changing color as the angle of illumination on their surface changes. It is one of the advanced shading features only available in the HDRP.
This video illustrates iridescence in action: our use of iridescence changes the color of our butterfly’s wings as it flaps:
When you switch to Material Type Iridescence, two new options will appear on the material node: IridescenceMask and IridescenceThickness.
You can use this simple graph to easily see the effect of these two new inputs.
From these images, you can see how the Iridescence Mask modulates the intensity of the iridescence effect from 0 to 1 (black to white), and how the Iridescent Thickness changes the color gradient created by the Iridescence effect.
If you wish to be physically accurate when using Iridescence, it is helpful to know that IridescenceThickness is an nm value. The 0 - 1 range from the connected input remaps to 0 - 3000nm.
This specific butterfly is a Morpho butterfly, thus the backside of its wings are actually a totally different color and pattern.
To achieve this effect, there are two sets of wings with normals facing opposite directions. To create the effect that light is traveling through the wings, these bottom faces are shaded using the translucent material type.
A translucent material simulates light passing through a surface and varies the strength of that light using a thickness map and diffusion profile.
There are three “flavors” of material types that use a Diffusion Profile: Subsurface Scattering, Subsurface Scattering with Transmission, and Translucent (which is just transmission).
Transmission means that the light is able to fully penetrate the object and exit through the other side (used on the butterfly). Materials utilizing Transmission have an option to add a thickness map to modulate the intensity of light passing through the surface.
To understand how to use the diffusion profile, it is helpful to have knowledge of Subsurface Scattering and how to use it.
Subsurface Scattering is used for surfaces that are somewhat translucent. Many surface types fall into this category including foliage, fruits and vegetables, precious stones, fabric, teeth, eyes, and skin. When light enters the surface of these materials, it scatters around inside the materials and then exists the surface, potentially at a different point from where it entered.
Surfaces utilizing Subsurface Scattering will exhibit a softening of the overall lighting effect, bleeding of light into neighboring areas, and blurring of small surface details.
The further light penetrates into the object, the more the lighting becomes attenuated and diffused. This “distance” that the light can penetrate is a value controlled by the thickness map, whereby the thinner your values (closer to black in the map), the more apparent the effect of Subsurface Scattering becomes.
You can paint a thickness map by hand, or generate one in an external application such as Substance Designer or Maya. To generate a map, invert your mesh surface normals, bake ambient occlusion, and then invert the ambient occlusion map.
The total amount and angle of the scatter, as well as the resulting color (and color seen from the light bleeding), is controlled by the Diffusion Profile.
In the HDRP, Diffusion Profile Settings is a unique type of asset that houses Diffusion Profiles.
If you are using the sample project or launched into an HD project using the project template, you will already have a Diffusion Profile Settings asset. If you need to create a new one, you can do so with Create > Rendering > Diffusion Profile Settings. You will also need to assign it to your HD Render Pipeline Asset. You can easily locate your HD asset from Project Settings > Graphics > Scriptable Render Pipeline Settings.
If the Settings asset exists, that asset will contain a reference to the current Diffusion Profile Settings you are using in your project.
The butterfly project contains two custom Diffusion Profiles — one for the back faces of the wings, and one for the leaves on the tree.
The Diffusion Profile contains a number of customization options to allow control over how lighting scatters through the mesh.
The Scattering Distance controls the intensity of the light scatter as well as the color. Put simply, this allows you to control how much from each color channel the light absorbs or reflects, based on the material of the object. For example, human skin can have a reddish color because as light scatters, it becomes colored by blood and tissue beneath the skin.
The Index of Refraction relates to the angle at which light bends as it enters the surface. This is a measurable value, and there are many online resources documenting the IOR of common materials. For example, the IOR is 1.4 for human skin, and between 1.3 and 1.5 for many other materials.
Texturing Mode will only work on objects using Subsurface Scattering. In most cases, you will use pre/post-scatter as it will blur your albedo, thus softening the look of your lighting. However, if your albedo already contains softening due to existing Subsurface Scattering (such as that existing on a scan or photograph), you can use post-scatter only.
The remaining options only work when using Transmission (Translucent or Subsurface Scattering with Transmission). Changing the Transmission Mode changes the logic used for shadowing. You should usually only use Thin for extremely thin objects such as leaves, and Regular for all other cases.
Transmission Tint is an additional color for exiting light that blends with the existing scatter color. The thickness remap lets you remap your 0 to 1 thickness map to a range appropriate for your asset.
For thin objects, such as the butterfly wing and our tree leaves, simple Translucency (Transmission only) is fine. For larger or thicker objects, it becomes important to also simulate the effect of light scattering and exiting at different points across the surface (not just the light transmitting through it). This is where Subsurface Scattering or Subsurface Scattering with Transmission should be applied.
Using Shader Graph to implement these advanced shading techniques drastically reduces iteration time. Tweaking and adjusting your visuals can require numerous iterations, but Shader Graph’s quick workflow makes this easier.
Because Shader Graph can relieve much of the burden of specific texture requirements, I was able to achieve the desired visuals using only three textures: the diffuse map, a main body normal map, and a tiling detail normal map. With Shader Graph and some experimentation, I discovered I could reuse channels from my diffuse map and reuse my normal data to drive the smoothness values, without having to author additional textures. Beyond the inherent freedom of quicker iteration and experimentation that comes with not having to write code, the ability to easily move back and forth between properties and in-line values proved powerful for iteration. For example, if I find that I am frequently changing a value, I can right-click and select Convert to Property. Now, when I save my shader, that property is available in the Inspector of any material I create from that shader.
During the iteration process on the appearance of my butterfly, I ended up exposing many in-line values as properties. This allowed me to fine-tune my butterfly in the game view, with accurate and correct lighting, post-processing, and animation (which proved essential for achieving my desired iridescent look).
Here, you can see how easy it is to change the visual appearance of the butterfly based on the parameters exposed.
Lastly, because both sides of the butterfly wings are similar but need to use different material types and textures, I converted the wing logic into a subgraph, while leaving my customizable properties as inputs. This allowed me to edit both faces of the wings simultaneously even though they were two different advanced material types.
As another example of how Shader Graph allows for quick iteration, we can look at the leaves on the bonsai tree. I changed my mind a lot when choosing the colors I wanted for the leaves of my bonsai tree. It was Fall when I built this scene, and it felt fitting to give the scene a Fall vibe.
After trying various colors, I eventually decided that I wanted to create a green-to-orange transition, as though the tree was in the process of changing color. However, I didn’t want to edit my leaf texture. Luckily, using Shader Graph, I was able to change the color using a gradient that changes based on the world position of the tree’s geometry. Leaves at different heights would receive different colors from the gradient. I also added noise to break up the uniformity of the gradient, making it more natural and organic in appearance. All these changes were possible without having to jump back into my texture authoring software.
It also meant that I didn’t need to bake the color into my texture map, and was able to reuse other channels in the map for grayscale texture requirements, such as the translucency thickness map.
Furthermore, if I enabled control over my leaf gradient through properties, I was able animate the leaves changing color over a period of time.
The HD Lit Shader Graph Master Node will open up new possibilities for creating surfaces that utilize the Advanced Shading options found in HDRP. We can’t wait to see the visual potential of your scenes elevated with these new HD Lit AF options that are now exposed in the user-friendly Shader Graph workflow. Keep your eyes open for other new Shader Graph updates! The Unity Shader Graph team is excited to continue empowering our artists in making beautiful content.
If you are interested in learning more technical details about the HD Render Pipeline, check out the presentation from SIGGRAPH here.