Skip to content

Commit 44192ea

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.3] Refactor the Shader Graph doc section about Custom Lighting sample
1 parent e213167 commit 44192ea

7 files changed

Lines changed: 220 additions & 170 deletions

Packages/com.unity.shadergraph/Documentation~/Shader-Graph-Sample-Custom-Lighting-Components.md

Lines changed: 59 additions & 102 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Get started with the Custom Lighting sample
2+
3+
Use the templates and sub graphs included in the **Custom Lighting** sample to get started with lighting model customization in Shader Graph.
4+
5+
> [!NOTE]
6+
> To use the **Custom Lighting** templates and sub graphs, you first need to [import the sample in your project](ShaderGraph-Samples.md#add-samples).
7+
8+
## Start from a shader graph template
9+
10+
To use one of the available Custom Lighting templates as a starting point to customize lighting in a prebuilt shader graph asset, follow these steps:
11+
12+
1. [Create a shader graph asset from a template](create-shader-graph.md).
13+
14+
1. In the [template browser](template-browser.md), select one of the templates from the **URP Custom Lighting** section.
15+
16+
1. Select **Create**.
17+
18+
1. Open the created shader graph asset in the Shader Graph window if the window doesn't open automatically.
19+
20+
## Start from an empty shader graph
21+
22+
To use one of the available Lighting Model sub graphs as a starting point to customize lighting in an empty shader graph asset, follow these steps:
23+
24+
1. [Create a shader graph asset with a preset target](create-shader-graph.md#create-a-shader-graph-with-a-preset-target) and select **URP** > **Unlit Shader Graph**.
25+
26+
1. Open the created shader graph asset in the Shader Graph window if the window doesn't open automatically.
27+
28+
1. Go to the [**Create Node** menu](Create-Node-Menu.md) and add one of the sub graphs from the **Custom Lighting** > **Lighting Models** section.
29+
30+
1. Connect the **Lit** output port of the added sub graph to the **Base Color** input port of the Master Stack.
31+
32+
1. To allow the Unlit target to correctly support custom lighting models, set the [Graph Settings](Graph-Settings-Tab.md) as follows:
33+
* Enable **Keep Lighting Variants**.
34+
* Disable **Default Decal Blending** and **Default SSAO**.
35+
36+
## Additional resources
37+
38+
* [Create a shader graph asset](Create-Shader-Graph.md)
39+
* [Add and connect nodes](Create-Node-Menu.md)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Introduction to lighting model customization with Shader Graph
2+
3+
You can customize lighting models to do the following:
4+
5+
* Improve rendering performance. You can remove or simplify one or more types of lighting calculations and sacrifice visual quality for rendering speed.
6+
7+
* Make your lighting look different from Unity's default lighting. For example, to make your project look like a watercolor painting or a pen and ink drawing.
8+
9+
10+
## Lighting model customization examples
11+
12+
The assets available in the **Custom Lighting** sample allow you to [get started with lighting model customization](Shader-Graph-Sample-Custom-Lighting-Get-Started.md) in different contexts and for various purposes.
13+
14+
| **Context** | **Description** | **Template** |
15+
| :--- | :--- | :--- |
16+
| Model for devices where performance is critical | With XR or low-end mobile devices where performance is critical, you likely need to reduce the cost of calculations in your shaders. For example, you might skip any fog, specular, reflections, light cookies, or SSAO support and only keep the basics. | [Custom Lighting Basic](Shader-Graph-Sample-Custom-Lighting-Templates.md#custom-lighting-basic) |
17+
| Simplified URP model with performance optimization | If you need to optimize performance in URP, you might want to use a Blinn model, which is similar to the main lighting in URP but slightly cheaper for specular highlights. The Blinn model slightly affects the redering quality but renders faster in most cases. | [Custom Lighting Simple](Shader-Graph-Sample-Custom-Lighting-Templates.md#custom-lighting-simple) |
18+
| Posterization model for cartoon appearance | You can alter the lighting in a shader graph to achieve stylized effects such as posterization, to give the visuals of your project the appearance of a cartoon. | [Custom Lighting Toon](Shader-Graph-Sample-Custom-Lighting-Templates.md#custom-lighting-toon) |
19+
| Lit URP model customization | You might want to explore the process of lighting customization directly from a shader based on the Lit URP model. | [Custom Lighting URP](Shader-Graph-Sample-Custom-Lighting-Templates.md#custom-lighting-urp) |
20+
| Other types of lighting customization | You can use any of the [Lighting Model](Shader-Graph-Sample-Custom-Lighting-Lighting-Models.md) sub graphs available in the **Custom Lighting** sample to create any type of lighting that you need within your own shader graphs. These sub graphs use a recommended pattern that illustrates how Unity expects custom lighting models to be defined. | N/A |
21+
22+
23+
## Limitations
24+
25+
Before you start to customize lighting models with Shader Graph, be aware of the following limitations:
26+
27+
### Shader Graph doesn't support deferred rendering
28+
29+
Customizable lighting is only intended to be used when you set the render type to Forward or Forward+ in the Render Asset.
30+
31+
When you set the render type to Deferred or Deferred+, it's not possible to control the lighting directly in an object’s shader, because the lighting occurs in a pass that is not directly connected to the object's shader.
32+
33+
If you need to customize lighting in a deferred rendering context, you have to [write shaders in code](xref:um-shader-writing) instead of using Shader Graph.
34+
35+
### Handling multiple light sources in Shader Graph requires HLSL coding
36+
37+
To support multiple light sources in Shader Graph, you have to write a small amount of code.
38+
39+
For the main directional light, you can create custom lighting in Shader Graph without coding. However, the part of the graph that does multiple light calculations requires the use of a [Custom Function node](Custom-Function-Node.md), because Shader Graph doesn’t support `For` loops.
40+
41+
The sample includes multiple examples of Additional Lights nodes, but if you want to create your own, you need to know a little bit of HLSL coding.
Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
1-
# Lighting Models
1+
# Lighting Model sub graph reference
22

3-
Use any of these subgraphs with the Unlit material type to create lighting that is defined in the Shader Graph. To know how to use these subgraphs, refer to the [main page](Shader-Graph-Sample-Custom-Lighting.md#examples).
3+
Explore the Lighting Model sub graphs used in the [URP Custom Lighting templates](Shader-Graph-Sample-Custom-Lighting-Templates.md) included in the Custom Lighting sample.
44

5-
All of the following subgraphs include the ApplyDecals subgraph to blend decal data, and the Debug Lighting and Debug Materials subgraph nodes to support the debug rendering modes (available in the Rendering Debugger window). They also include a subgraph from the Core Lighting Models category to define the behavior of the lighting itself as described below.
5+
These sub graphs are available in the [**Create Node** menu](Create-Node-Menu.md) under the **Lighting** > **Light Models** section.
66

7-
## Lit Basic
8-
The Lit Basic lighting model does very simple lighting and leaves out most lighting features to render as fast as possible. It calculates simple diffuse lighting and a simple form of ambient lighting. It does not support fog, reflections, specular, light cookies, or any other lighting features. But it does render fast and is ideal for low-end mobile devices and XR headsets.
7+
> [!NOTE]
8+
> To use any of these sub graphs, you must include it in a shader graph set up with the **Universal** (URP) target and the **Unlit** material type.
99
10-
## Lit Colorize
11-
The Colorize lighting model is an example of custom behavior type you can create when you can control the lighting model. The main directional light renders the scene in grayscale with no color. Color is introduced with point lights, which allows you to control where the scene has color based on where you place the point lights in the scene.
10+
## Common sub graph structure
1211

13-
## Lit Simple
14-
The Lit Simple lighting model is the same as the URP lighting model, except it uses the Blinn formula for the specular highlights. This makes it slightly cheaper to render than standard URP while looking fairly similar. If you still need all of the lighting features (specular, fog, screen space ambient occlusion, reflections, etc), but you want to make the lighting cheaper, this may be a good choice.
12+
Each Lighting Model sub graph includes the following:
13+
* The [ApplyDecals](Shader-Graph-Sample-Custom-Lighting-Components.md#general) sub graph, to blend decal data with the original material properties.
14+
* The [Debug Lighting and Debug Materials](Shader-Graph-Sample-Custom-Lighting-Components.md#debug) sub graphs, to support the debug rendering modes (available in the Rendering Debugger window).
15+
* A sub graph from the [Core Models](Shader-Graph-Sample-Custom-Lighting-Components.md#core-models) category, to define the lighting behavior according to the model.
1516

16-
## Lit Toon
17-
The Lit Toon lighting model uses a Posterize operation to break the smooth lighting gradient into distinct bands of shading. It simulates the look of cartoons where lighting is rendered with distinct colors of paint rather than smooth gradients.
17+
> [!NOTE]
18+
> The ApplyDecals, DebugLighting, and DebugMaterials sub graph nodes aren’t strictly required. They enable the decals and debug rendering modes, which are core engine features. When you don't use these features, the corresponding sub graph nodes don't affect your project's performance.
1819
19-
## Lit URP
20-
The Lit URP lighting model closely matches the lighting that the Universal Render Pipeline does by default. If you want to start with the URP lighting and then alter it, this is the node to use.
20+
## Available Lighting Model sub graphs
2121

22+
### Lit Basic
23+
24+
This lighting model does very simple lighting and leaves out most lighting features to render as fast as possible. It calculates simple diffuse lighting and a simple form of ambient lighting. It does not support fog, reflections, specular, light cookies, or any other lighting features. But it does render fast and is ideal for low-end mobile devices and XR headsets.
25+
26+
### Lit Colorize
27+
28+
This lighting model is an example of custom behavior type you can create when you can control the lighting model. The main directional light renders the scene in grayscale with no color. Color is introduced with point lights, which allows you to control where the scene has color based on where you place the point lights in the scene.
29+
30+
### Lit Simple
31+
32+
This lighting model is the same as the URP lighting model, except it uses the Blinn formula for the specular highlights. This makes it slightly cheaper to render than standard URP while looking fairly similar. If you still need all of the lighting features (specular, fog, screen space ambient occlusion, reflections, etc), but you want to make the lighting cheaper, this may be a good choice.
33+
34+
### Lit Toon
35+
36+
This lighting model uses a Posterize operation to break the smooth lighting gradient into distinct bands of shading. It simulates the look of cartoons where lighting is rendered with distinct colors of paint rather than smooth gradients.
37+
38+
### Lit URP
39+
40+
This lighting model closely matches the lighting that the Universal Render Pipeline does by default. If you want to start with the URP lighting and then alter it, this is the node to use.
41+
42+
## Additional resources
43+
44+
* [Introduction to lighting model customization](Shader-Graph-Sample-Custom-Lighting-Introduction.md)
45+
* [Get started with the Custom Lighting sample](Shader-Graph-Sample-Custom-Lighting-Get-Started.md)
46+
* [URP Custom Lighting template reference](Shader-Graph-Sample-Custom-Lighting-Templates.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# URP Custom Lighting template reference
2+
3+
Explore the prebuilt URP Custom Lighting shader graph templates included in the Custom Lighting sample.
4+
5+
> [!NOTE]
6+
> These templates are available in the [template browser](template-browser.md) under the **URP Custom Lighting** section. Don't edit the corresponding assets in the **Assets** > **Samples** > **Shader Graph** folder of your project.
7+
8+
Each Custom Lighting template includes a specific [Lighting Model sub graph](Shader-Graph-Sample-Custom-Lighting-Lighting-Models.md).
9+
10+
## Custom Lighting Basic
11+
12+
This template uses a basic lighting model that calculates diffuse lighting for multiple light sources. To reduce the cost of calculations, this shader does not support fog, specular, reflections, light cookies, and SSAO, but you can reintegrate any of these features if needed. This model makes the lighting as cheap as possible by only including the basic requirements. This type of lighting model is ideal for XR or low-end mobile devices where performance is critical.
13+
14+
## Custom Lighting Simple
15+
16+
This template uses a lighting model designed to be similar to the main lighting used by URP. It uses a slightly cheaper Blinn model for specular highlights, which reduces the quality but speeds up the rendering in most cases.
17+
18+
## Custom Lighting Toon
19+
20+
This template uses a lighting model that posterizes the lighting to give it the appearance of a cartoon. This shows you how you can alter lighting in the graph to achieve stylized effects that give your project a unique appearance.
21+
22+
## Custom Lighting URP
23+
24+
This template uses the same lighting formula as the Lit URP model. You can use it as a starting point if you want to begin with URP as is and then make changes.
25+
26+
## Additional resources
27+
28+
* [Introduction to lighting model customization](Shader-Graph-Sample-Custom-Lighting-Introduction.md)
29+
* [Get started with the Custom Lighting sample](Shader-Graph-Sample-Custom-Lighting-Get-Started.md)
Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
11
# Custom Lighting
2-
![The Shader Graph Custom Lighting Sample: A collection of Shader Graph subgraphs that serve as building blocks for building user interface elements.](images/CustomLightingSample.png)
32

4-
The Shader Graph Custom Lighting sample shows how you can create your own custom lighting in Shader Graph and provides dozens of example templates, shaders, and subgraphs to help you get started with your own custom lighting.
3+
![An example scene with custom lighting effects.](images/CustomLightingSample.png)
54

6-
Documentation for this set of samples is broken into two pages:
5+
Use the additional templates and sub graphs provided in the **Custom Lighting** sample to get started with lighting model customization in Shader Graph.
76

8-
* [Lighting Models](Shader-Graph-Sample-Custom-Lighting-Lighting-Models.md)
9-
* [Components](Shader-Graph-Sample-Custom-Lighting-Components.md)
10-
11-
## Limitations
12-
Before making your own custom lighting model in Shader Graph, be aware of the following limitations:
13-
14-
* Customizable lighting is only intended to be used when the render type is set to Forward or Forward+ in the Render Asset.
15-
16-
When the render type is set to Deferred or Deferred+, it's not possible to control the lighting directly in an object’s shader, because the lighting occurs in a pass that is not directly connected to the object's shader.
17-
18-
If you need to customize lighting in deferred rendering context, you have to write code instead of using Shader Graph.
19-
20-
* To support multiple light sources, you have to write a small amount of code.
21-
22-
For the main directional light, you can create custom lighting 100% in Shader Graph. However, the part of the graph that does multiple light calculations requires the use of a Custom Function node, because Shader Graph doesn’t support `For` loops.
23-
24-
The sample includes multiple examples of Additional Lights nodes, but if you want to create your own, you need to know a little bit of HLSL coding.
25-
26-
27-
## Motivations
28-
There are two main reasons you might want to customize the lighting model in Shader Graph:
29-
30-
* Improve rendering performance by leaving out one or more types of lighting calculations, sacrificing visual quality for rendering speed.
31-
32-
* Make your lighting look different from the lighting that Unity already provides. For example, you might want your project to look like a watercolor painting, like it’s drawn with pen and ink, etc.
33-
34-
## Examples
35-
The sample includes the following subgraph examples in the Shader Graph node library:
36-
37-
* Lighting / Light Models / Lit Basic
38-
* Lighting / Light Models / Lit Colorize
39-
* Lighting / Light Models / Lit Simple
40-
* Lighting / Light Models / Lit Toon
41-
* Lighting / Light Models / Lit URP
42-
43-
To get customized lighting with any of these subgraphs:
44-
1. Add the subgraph to an empty Shader Graph.
45-
1. Connect the Lit output port to the Base Color input port on the Unlit Master Stack.
46-
1. To allow the Unlit target to correctly support custom lighting models, make sure to set the Graph inspector as follows:
47-
* Enable *Keep Lighting Variants*.
48-
* Disable *Default Decal Blending* and *Default SSAO*.
49-
50-
Notice that each of the above subgraphs use the following:
51-
* The ApplyDecals subgraph to blend decal data with the original material properties.
52-
* The Debug Lighting and Debug Materials subgraph nodes to support the debug rendering modes (available in the Rendering Debugger window).
53-
* A subgraph from the Core Lighting Models category to define the behavior of the lighting itself.
54-
55-
While the ApplyDecals, DebugLighting, and DebugMaterials subgraph nodes aren’t strictly required, they are included in the lighting model subgraphs to enable these core engine features: decals and debug rendering modes. When these features are not in use, the ApplyDecals, DebugLighting, and DebugMaterials subgraph nodes don't add any performance cost to the shader overall. You can use them without worrying that you’re slowing down your project.
56-
57-
You can create any type of lighting that you want, but the above subgraphs show you a recommended pattern to illustrate how Unity expects custom lighting models to be defined.
7+
| **Topic** | **Description** |
8+
| :--- | :--- |
9+
| [Introduction to lighting model customization with Shader Graph](Shader-Graph-Sample-Custom-Lighting-Introduction.md) | Learn about the purpose and limitations of lighting model customization in Shader Graph and get an overview of the use cases covered in the **Custom Lighting** sample. |
10+
| [Get started with the Custom Lighting sample](Shader-Graph-Sample-Custom-Lighting-Get-Started.md) | Start your lighting customization from either a prebuilt shader graph template or a lighting model sub graph in your own shader graph. |
11+
| [URP Custom Lighting template reference](Shader-Graph-Sample-Custom-Lighting-Templates.md) | Explore the prebuilt shader graph templates included in the sample. |
12+
| [Lighting Model sub graph reference](Shader-Graph-Sample-Custom-Lighting-Lighting-Models.md) | Explore the Lighting Model sub graphs included in the sample and used in the URP Custom Lighting templates. |
13+
| [Component sub graph reference](Shader-Graph-Sample-Custom-Lighting-Components.md) | Explore the Component sub graphs used as building blocks for the Lighting Model sub graphs included in the sample. |

Packages/com.unity.shadergraph/Documentation~/TableOfContents.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,11 @@
353353
* [How to make shapes that adapt to the aspect ratio of the UI element](Shader-Graph-Sample-UGUI-Shaders-How-tos-aspect-ratio.md)
354354
* [Notes on performance](Shader-Graph-Sample-UGUI-Shaders-Notes-on-performance.md)
355355
* [Custom Lighting](Shader-Graph-Sample-Custom-Lighting.md)
356-
* [Lighting Models](Shader-Graph-Sample-Custom-Lighting-Lighting-Models.md)
357-
* [Components](Shader-Graph-Sample-Custom-Lighting-Components.md)
356+
* [Introduction to lighting model customization](Shader-Graph-Sample-Custom-Lighting-Introduction.md)
357+
* [Get started with the Custom Lighting sample](Shader-Graph-Sample-Custom-Lighting-Get-Started.md)
358+
* [URP Custom Lighting template reference](Shader-Graph-Sample-Custom-Lighting-Templates.md)
359+
* [Lighting Model sub graph reference](Shader-Graph-Sample-Custom-Lighting-Lighting-Models.md)
360+
* [Component sub graph reference](Shader-Graph-Sample-Custom-Lighting-Components.md)
358361
* [Terrain Shaders](Shader-Graph-Sample-Terrain.md)
359362
* [Texture Packing Schemes](Shader-Graph-Sample-Terrain-Packing.md)
360363
* [Shaders](Shader-Graph-Sample-Terrain-Shaders.md)

0 commit comments

Comments
 (0)