Skip to content

Commit 26da8dc

Browse files
authored
Quality update of custom post process (#6856)
1 parent 4d6c4fe commit 26da8dc

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

com.unity.render-pipelines.high-definition/Documentation~/Custom-Post-Process.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
11
# Custom Post Process
22

3-
The High Definition Render Pipeline (HDRP) allows you to write your own post-processing effects that automatically integrate into [Volume](Volumes.md). A custom effect needs two files. A **C# Custom Post Process**(C# file) and an associated **FullScreen Shader** (HLSL file). You can generate a template of each:
3+
The High Definition Render Pipeline (HDRP) allows you to write your own post-processing effects that automatically integrate into [Volumes](Volumes.md). A custom effect needs two files:
4+
* A **C# Custom Post Process**(C# file)
5+
* An associated **FullScreen Shader** (HLSL file).
46

5-
* **C# Custom Post Process**: Right click in the Assets folder and select **Create > Rendering > HDRP C# Post Process Volume**.
7+
You can generate a template of each file:
68

7-
* **FullScreen Shader**: Right click in the Assets folder and select **Create > Shader > HDRP > Post Process**.
9+
* **C# Custom Post Process**: Right click in the Assets folder and select **Create** > **Rendering** > **HDRP C# Post Process Volume**.
810

9-
Note that by default, your custom effect does not run if you just add it to a Volume. You also need to add the effect to your Project's list of supported effects. (it's the same list used to order the effect, see the Effect Ordering section).
11+
* **FullScreen Shader**: Right click in the Assets folder and select **Create** > **Shader** > **HDRP** > **Post Process**.
12+
13+
**Note**: By default, your custom effect doesn't run if you just add it to a Volume. You also need to add the effect to your Project's list of supported effects. (it's the same list used to order the effect, see the Effect Ordering section).
1014

1115
## Example
1216

1317
This example shows you how to create a **grayscale** effect. To get started:
1418

15-
1. Create a **C# Custom Post Process** file (right click in the Assets folder: **Create > Rendering > HDRP C# Post Process Volume**) and call it **GrayScale**. Note that, because of how serialization works in Unity, the file name and the class name must be identical or Unity does not serialize it properly.
19+
1. Create a **C# Custom Post Process** file (right click in the Assets folder: **Create** > **Rendering** > **HDRP C# Post Process Volume**) and call it **GrayScale**.
20+
21+
**Note**: Because of how serialization works in Unity, the file name and the class name must be identical or Unity doesn't serialize it properly.
1622

1723
2. Copy the example code from the [GrayScale C# script section](#CSharp) into your **C# Post Process Volume**.
1824

19-
3. Create a full screen post-process Shader (right click in the Assets folder: **Create > Shader > HDRP > Post Process**) and call it **GrayScale**.
25+
3. Create a full screen post-process Shader (right click in the Assets folder: **Create** > **Shader** > **HDRP** > **Post Process**) and call it **GrayScale**.
2026

2127
4. Copy the example code from the [GrayScale Shader section](#Shader) into your post-process Shader.
2228

23-
5. Add the **GrayScale** effect to the list of custom post-processes that your Project executes. To do this, go to **Edit > Project Settings > HDRP Default Settings** and, at the bottom of the **After Post Process** list, click on the **+** and select **GrayScale**.
29+
5. Add the **GrayScale** effect to the list of custom post-processes that your Project executes. To do this, go to **Edit** > **Project Settings** > **HDRP Default Settings** and, at the bottom of the **After Post Process** list, click on the **+** and select **GrayScale**.
2430

25-
6. Now you can add the **GrayScale** post-process override to a **Volumes** in the Scene. To change the effect settings, click the small `all` text just below the foldout arrow and adjust with the **Intensity** slider.
31+
6. Now you can add the **GrayScale** post-process override to **Volumes** in the Scene. To change the effect settings, click the small **all** text just below the foldout arrow and adjust with the **Intensity** slider.
2632

2733
7. Optionally, you can create a custom editor for your post-processing effect. For information on how to do this, see [custom editor](#CustomEditor).
2834

2935
<a name="CSharp"></a>
3036

3137
### GrayScale C# script
3238

33-
This is the C# Custom Post Process file. Custom post-process effects store both configuration data and logic in the same class. To create the settings for the effect, you can either use a pre-existing class that inherits from [VolumeParameter<T>](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@latest/index.html?subfolder=/api/UnityEngine.Rendering.VolumeParameter-1.html), or, if you want to use a property that the pre-existing classes do not include, create a new class that inherits from VolumeParameter<T>.
34-
```CSharp
39+
This is the C# Custom Post Process file. Custom post-process effects store both configuration data and logic in the same class. To create the settings for the effect, you can either use a pre-existing class that inherits from [VolumeParameter<T>](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@latest/index.html?subfolder=/api/UnityEngine.Rendering.VolumeParameter-1.html), or, if you want to use a property that the pre-existing classes don't include, create a new class that inherits from VolumeParameter<T>.
40+
41+
```C#
3542
using UnityEngine;
3643
using UnityEngine.Rendering;
3744
using UnityEngine.Rendering.HighDefinition;
@@ -76,7 +83,7 @@ This example code uses a `ClampedFloatParameter` that you can clamp to a range.
7683

7784
* The third parameter represents the maximum value to clamp the property to.
7885

79-
HDRP calls the `IsActive()`function before the `Render` function to process the effect. If this function returns `false`, HDRP does not process the effect. It is good practice to check every property configuration where the effect either breaks or does nothing. In this example, `IsActive()` makes sure that HDRP can find the `GrayScale.shader` and that the intensity is greater than 0.
86+
HDRP calls the `IsActive()` function before the `Render` function to process the effect. If this function returns `false`, HDRP doesn't process the effect. It's good practice to check every property configuration where the effect either breaks or doesn'thing. In this example, `IsActive()` makes sure that HDRP can find the `GrayScale.shader` and that the intensity is greater than 0.
8087

8188
The **injectionPoint** override allows you to specify where in the pipeline HDRP executes the effect. There are currently five injection points:
8289

@@ -107,7 +114,10 @@ In the `Render` function, you have access to a [CommandBuffer](https://docs.unit
107114

108115
### GrayScale Shader
109116

110-
HDRP gives you total control over the vertex and fragment Shader so you can edit both of them to suit your needs. Note that there are a number of utility functions in [Common.hlsl](https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl) and [Color.hlsl](https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl) that the Shader includes by default. This means that you have access to these utility functions in your effect. For example, the GrayScale Shader uses the Luminance() function to convert a linear RGB value to its luminance equivalent.
117+
HDRP gives you total control over the vertex and fragment Shader so you can edit both of them to suit your needs.
118+
119+
There are several utility functions in [Common.hlsl](https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl) and [Color.hlsl](https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl) that the Shader includes by default. This means that you have access to these utility functions in your effect. For example, the GrayScale Shader uses the `Luminance()` function to convert a linear RGB value to its luminance equivalent.
120+
111121
```glsl
112122
Shader "Hidden/Shader/GrayScale"
113123
{
@@ -195,9 +205,12 @@ Shader "Hidden/Shader/GrayScale"
195205
}
196206
```
197207

198-
If none of your Scenes reference the Shader, Unity does not build the Shader and the effect does not work when you run your application outside of the Editor. To resolve this, either add the Shader to a [Resources folder](https://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html), or go to **Edit > Project Settings > Graphics** and add the Shader to the **Always Included Shaders** list.
208+
If none of your Scenes reference the Shader, Unity doesn't build the Shader and the effect doesn't work when you run your application outside of the Editor. To resolve this, do one of the following:
209+
210+
* Add the Shader to a [Resources folder](https://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html)
211+
* Go to **Edit** > **Project Settings** > **Graphics** and add the Shader to the **Always Included Shaders** list.
199212

200-
:warning: Note that, when HDRP executes your post-process effect, it uses a render target pooling system. It means that you don't know what the current color buffer contains, which is why you should never use any instructions that could show this color buffer. Do not use transparency, blend modes, or the **clip()** instruction in your Shader, otherwise your effect breaks.
213+
**Note**: When HDRP executes your post-process effect, it uses a render target pooling system. It means that you don't know what the current color buffer contains, which is why you should never use any instructions that could display this color buffer. don't use transparency, blend modes, or the **clip()** instruction in your Shader, otherwise your effect breaks.
201214

202215
#### Shader inputs
203216

@@ -218,7 +231,7 @@ By default, the Shader template provides you with the following inputs:
218231

219232
HDRP allows you to customize the order of your custom post-processing effect at each injection point. To order your effects:
220233

221-
1. Go to **Edit > Project Settings > Graphics** and select the [HDRP Global Settings](Default-Settings-Window.md) tab.
234+
1. Go to **Edit** > **Project Settings** > **Graphics** and select the [HDRP Global Settings](Default-Settings-Window.md) tab.
222235

223236
2. Scroll down until you find the **Custom Post Process Orders** section. This section contains three lists, one for each injection point.
224237

@@ -245,8 +258,8 @@ HDRP processes effects from the top of the list to the bottom and the order of e
245258
By default, Unity automatically creates an editor for classes but, if you want more control over how Unity displays certain properties, you can create a custom editor. If you do create a custom editor script, make sure to put it in a folder named **Editor**.
246259

247260
The following is an example of a custom editor for the GrayScale effect:
248-
```
249261

262+
```C#
250263
using UnityEditor.Rendering;
251264

252265
using UnityEngine;
@@ -287,11 +300,12 @@ sealed class GrayScaleEditor : VolumeComponentEditor
287300

288301
}
289302
```
290-
This custom editor is not really useful as it produces the same result as the editor that Unity creates. Custom Volume component editors also support an [additonal properties toggle](More-Options.md). To add it, you have to set hasAdvancedMode override to true. Then, inside the OnInspectorGUI, you can use the isInAdvancedMode boolean to display more properties.
303+
304+
This custom editor isn't useful as it produces the same result as the editor that Unity creates. Custom Volume component editors also support an [additonal properties toggle](More-Options.md). To add it, you have to set the `hasAdvancedMode` override to true. Then, inside `OnInspectorGUI`, you can use the `isInAdvancedMode` Boolean to display more properties.
291305

292306
## Dynamic resolution and DLSS support
293307

294-
If you want to use DLSS and/or dynamic resolution on your pass, and you need to interpolate or sample UVs from color / normal or velocity, you must use the following functions to calculate the correct UVs:
308+
If you want to use DLSS or dynamic resolution on your pass, and you need to interpolate or sample UVs from color, normal, or velocity, you must use the following functions to calculate the correct UVs:
295309

296310
```glsl
297311
#include "Packages/com.unity.render-pipelines.high-dynamic/Runtime/ShaderLibrary/ShaderVariables.hlsl"
@@ -303,20 +317,20 @@ float2 correctUvs = ClampAndScaleUVForBilinearPostProcessTexture(UV); // use the
303317
304318
```
305319

306-
## TroubleShooting
320+
## Troubleshooting
307321

308-
If your effect does not display correctly:
322+
If your effect doesn't display correctly:
309323

310324
* In your Project Settings, make sure this effect is listed under one of the post process order lists (see [Effect Ordering](#EffectOrdering)).
311325

312-
* Check that your effect's Shader compiles and that the reference to the Material in your post process Volume is not null.
326+
* Check that your effect's Shader compiles and that the reference to the Material in your post process Volume isn't null.
313327

314328
* In the Volume that contains your post process, make sure that it has a high enough priority and that your Camera is inside its bounds.
315329

316330
* Check that your shader doesn't contain any **clip()** instructions, that the blend mode is set to Off and the output alpha is always 1.
317331

318-
* If your effect does not work with dynamic resolution, use the _PostProcessScreenSize constant to make it fit the size of the screen correctly. You only need to do this when you use dynamic resolution scaling (DRS), and you need normal / velocity and color.
332+
* If your effect doesn't work with dynamic resolution, use the _PostProcessScreenSize constant to make it fit the size of the screen correctly. You only need to do this when you use dynamic resolution scaling (DRS), and you need normal / velocity and color.
319333

320-
## Known issues and Limitations
334+
## Known issues and limitations
321335

322-
* Renaming a custom post process class name and file will remove it from the list in HDRP Project Settings causing the effect to not be rendered anymore.
336+
* Renaming a custom post process class name and file will remove it from the list in HDRP Project Settings causing the effect not to be rendered anymore.
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)