You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: com.unity.render-pipelines.high-definition/Documentation~/Custom-Post-Process.md
+38-24Lines changed: 38 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,44 @@
1
1
# Custom Post Process
2
2
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).
4
6
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:
6
8
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**.
8
10
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).
10
14
11
15
## Example
12
16
13
17
This example shows you how to create a **grayscale** effect. To get started:
14
18
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.
16
22
17
23
2. Copy the example code from the [GrayScale C# script section](#CSharp) into your **C# Post Process Volume**.
18
24
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**.
20
26
21
27
4. Copy the example code from the [GrayScale Shader section](#Shader) into your post-process Shader.
22
28
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**.
24
30
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.
26
32
27
33
7. Optionally, you can create a custom editor for your post-processing effect. For information on how to do this, see [custom editor](#CustomEditor).
28
34
29
35
<aname="CSharp"></a>
30
36
31
37
### GrayScale C# script
32
38
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#
35
42
usingUnityEngine;
36
43
usingUnityEngine.Rendering;
37
44
usingUnityEngine.Rendering.HighDefinition;
@@ -76,7 +83,7 @@ This example code uses a `ClampedFloatParameter` that you can clamp to a range.
76
83
77
84
* The third parameter represents the maximum value to clamp the property to.
78
85
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.
80
87
81
88
The **injectionPoint** override allows you to specify where in the pipeline HDRP executes the effect. There are currently five injection points:
82
89
@@ -107,7 +114,10 @@ In the `Render` function, you have access to a [CommandBuffer](https://docs.unit
107
114
108
115
### GrayScale Shader
109
116
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.
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.
199
212
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.
201
214
202
215
#### Shader inputs
203
216
@@ -218,7 +231,7 @@ By default, the Shader template provides you with the following inputs:
218
231
219
232
HDRP allows you to customize the order of your custom post-processing effect at each injection point. To order your effects:
220
233
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.
222
235
223
236
2. Scroll down until you find the **Custom Post Process Orders** section. This section contains three lists, one for each injection point.
224
237
@@ -245,8 +258,8 @@ HDRP processes effects from the top of the list to the bottom and the order of e
245
258
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**.
246
259
247
260
The following is an example of a custom editor for the GrayScale effect:
248
-
```
249
261
262
+
```C#
250
263
usingUnityEditor.Rendering;
251
264
252
265
usingUnityEngine;
@@ -287,11 +300,12 @@ sealed class GrayScaleEditor : VolumeComponentEditor
287
300
288
301
}
289
302
```
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.
291
305
292
306
## Dynamic resolution and DLSS support
293
307
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:
@@ -303,20 +317,20 @@ float2 correctUvs = ClampAndScaleUVForBilinearPostProcessTexture(UV); // use the
303
317
304
318
```
305
319
306
-
## TroubleShooting
320
+
## Troubleshooting
307
321
308
-
If your effect does not display correctly:
322
+
If your effect doesn't display correctly:
309
323
310
324
* In your Project Settings, make sure this effect is listed under one of the post process order lists (see [Effect Ordering](#EffectOrdering)).
311
325
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.
313
327
314
328
* 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.
315
329
316
330
* 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.
317
331
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.
319
333
320
-
## Known issues and Limitations
334
+
## Known issues and limitations
321
335
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.
0 commit comments