Skip to content

Latest commit

 

History

History
136 lines (72 loc) · 10.2 KB

README_MRTKStandardShader.md

File metadata and controls

136 lines (72 loc) · 10.2 KB

MRTK Standard Shader

Standard shader examples

MRTK Standard shading system utilizes a single, flexible shader that can achieve visuals similar to Unity's Standard Shader, implement Fluent Design System principles, and remain performant on mixed reality devices.

Example Scenes

You can find the shader material examples in the MaterialGallery scene under: MixedRealityToolkit.Examples/Demos/StandardShader/Scenes/ All materials in this scene are using the MRTK/Standard shader.

Material Gallery

You can find a comparison scene to compare and test the MRTK/Standard shader against the Unity/Standard shader example in the StandardMaterialComparison scene under: MixedRealityToolkit.Examples/Demos/StandardShader/Scenes/

Material Comparison

Architecture

The MRTK/Standard shading system is an "uber shader" that uses Unity's shader program variant feature to auto-generate optimal shader code based on material properties. When a user selects material properties in the material inspector they only incur performance cost for features they have enabled.

A custom material inspector exists for the MRTK/Standard shader called MixedRealityStandardShaderGUI.cs. The inspector automatically enables/disables shader features based on user selection and aides in setting up render state. For more information about each feature please hover over each property in the Unity Editor for a tooltip.

Material Inspector

Performance

One of the primary advantages to using the MRTK Standard shader over the Unity standard shader is performance. The MRTK Standard Shader is extensible to only utilize the features enabled. However, the MRTK Standard shader has also been written to deliver comparable aesthetic results as the Unity Standard shader but at a much lower cost. One simple way to compare shader performance is via the number of operations that needs to be performed on the GPU. Of course, the magnitude of calculations may fluctuate by features enabled and other rendering configurations. But, in general, the MRTK Standard shader performs significantly less computation than the Unity Standard shader.

Unity Standard shader statistics example

Unity Standard Shader Statistics

MRTK Standard shader statistics example

MRTK Standard Shader Statistics

Note

These results can be generated by selecting and viewing a shader asset in the Unity inspector then clicking the Compile and show code button.

Lighting

The MRTK/Standard uses a simple approximation for lighting. Because this shader does not calculate for physical correctness and energy conservation, it renders quickly and efficient. Blinn-Phong is the primary lighting technique which is blended with Fresnel and image based lighting to approximate physically based lighting. The shader supports the following lighting techniques:

Directional Light

The shader will respect the direction, color, and intensity of the first Unity Directional Light in the scene (if enabled). Dynamic point lights, spot lights, or any other Unity light will not be considered in real time lighting.

Spherical Harmonics

The shader will use Light Probes to approximate lights in the scene using Spherical Harmonics if enabled. Spherical harmonics calculations are performed per vertex to reduce calculation cost.

Lightmapping

For static lighting the shader will respect lightmaps built by Unity's Lightmapping system simply mark the renderer as static (or lightmap static) to use lightmaps.

Hover Light

A Hover Light is a Fluent Design System paradigm that mimics a "point light" hovering near the surface of an object. Often used for far away cursor lighting the application can control the properties of a Hover Light via the HoverLight.cs. Up to 3 Hover Lights are supported at a time.

Proximity Light

A Proximity Light is a Fluent Design System paradigm that mimics a "gradient inverse point light" hovering near the surface of an object. Often used for near cursor lighting the application can control the properties of a Proximity Light via the ProximityLight.cs. Up to 2 Proximity Lights are supported at a time.

Lightweight Scriptable Render Pipeline Support

The MRTK contains an upgrade path to allow developers to utilize Unity's Lightweight Scriptable Render Pipeline (LWRP) with MRTK shaders. Tested in Unity 2019.1.1f1 and Lightweight RP 5.7.2 package. or instructions on getting started with the LWRP please see this page.

To perform the MRTK upgrade select: Mixed Reality Toolkit -> Utilities -> Upgrade MRTK Standard Shader for Lightweight Render Pipeline

lwrp upgrade

After the upgrade occurs the MRTK/Standard shader will be altered and any magenta (shader error) materials should be fixed. To verify the upgrade successfully occurred please check the console for: Upgraded Assets/MixedRealityToolkit/StandardAssets/Shaders/MixedRealityStandard.shader for use with the Lightweight Render Pipeline.

Texture Combiner

To improve parity with the Unity Standard shader per pixel metallic, smoothness, emissive, and occlusion values can all be controlled via channel packing. For example:

channel map example

When you use channel packing, you only have to sample and load one texture into memory instead of four separate ones. When you write your texture maps in a program like Substance or Photoshop, you can pack hand pack them like so:

Channel Property
Red Metallic
Green Occlusion
Blue Emission (Greyscale)
Alpha Smoothness

Or, you can use the MRTK Texture Combiner Tool. To open the tool select: Mixed Reality Toolkit -> Utilities -> Texture Combiner which will open the below window:

texture combiner example

This windows can be automatically filled out by selecting a Unity Standard shader and clicking "Autopopulate from Standard Material." Or, you can manually specify a texture (or constant value) per red, green, blue, or alpha channel. The texture combination is GPU accelerated and does not require the input texture to be CPU accessible.

Additional Feature Documentation

Below are extra details on a handful of features details available with the MRTK/Standard shader.

Performant plane, sphere, and box shape clipping with the ability to specify which side of the primitive to clip against (inside or outside). You can find a scene that demonstrates advanced usage of clipping primitives in the ClippingExamples scene under: MixedRealityToolkit.Examples/Demos/StandardShader/Scenes/

primitive clipping

ClippingPlane.cs, ClippingSphere.cs, and ClippingBox.cs can be used to easily control clipping primitive properties.

primitive clipping gizmos

Built in configurable stencil test support to achieve a wide array of effects. Such as portals:

stencil test

Instanced color support to give thousands of GPU instanced meshes unique material properties:

instanced properties

Triplanar mapping is a technique to programmatically texture a mesh. Often used in terrain, meshes without UVs, or difficult to unwrap shapes. This implementation supports world or local space projection, the specification of blending smoothness, and normal map support. Note, each texture used requires 3 texture samples, so please use sparingly in performance critical situations.

triplanar

A checkbox to control albedo optimizations. As an optimization albedo operations are disabled when no albedo texture is specified. This is useful for controlling remote texture loading.

Simply check this box:

albedo assignment

Per pixel clipping textures, local edge based anti aliasing, and normal map scaling are supported.

normal map scale

Vertex extrusion in world space. Useful for visualizing extruded bounding volumes or transitions in/out meshes.

normal map scale

See also