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: README.md
+151-1Lines changed: 151 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,157 @@ The package contains 8 example effect which are included as a sample. Samples ca
38
38
39
39
## Tutorial
40
40
41
-
**TODO**
41
+
First, we need a c# shader and a script for our custom effect. We will create a grayscale effect for the sake of simplicity.
42
+
43
+
First, lets create the C# script. We will call it `GrayScaleEffect.cs`. The name of the file must match the volume component class name to comply with Unity Serialization rules. In the file write the following:
As you can see, the code consists of two classes: the volume component and the renderer. The volume component only holds data and will appear as a volume profile option. The renderer is rensponsible for rendering the effect and read the effect parameters from the volume component. The volume component and renderer is decoupled from each other which opens up many options while implementing your effects. For example:
116
+
1. You can have a one-to-one relationship between your volume component and renderer (as we did above).
117
+
2. You can have a renderer without any corresponding volume component if it does not need any data from the volumes.
118
+
3. You can have a renderer that reads from multiple volume components (see [GrayAndInvertEffect.cs](Samples~/Examples/Scripts/PostProcessing/GrayAndInvertEffect.cs) as an example).
119
+
4. You can have multiple renderers read from the same volume component(s).
120
+
121
+
The option #3 is especially useful for writing uber effect shaders that can do multiple effects in the same blit to enhance performance.
122
+
123
+
Then we create the shader code. Create a shader file with any name you like (I prefer `GrayScale.shader`) and replace its content with the following code:
Since vertex shaders rarely contain any logic specific to the effect, we use a default vertex shader `FullScreenTrianglePostProcessVertexProgram` which is included in `Packages/com.yetman.render-pipelines.universal.postprocess/ShaderLibrary/Core.hlsl`. The fragment shader is the one reponsible for reading the original pixel color, calculating the grayscale color and blending the two colors together.
166
+
167
+
Now that we have our custom effect, we need to add a `CustomPostProcess` renderer feature to the foward renderer as seen in the next image. You can also add a `SceneNormals` renderer feature if you want to use scene normals in an effect (such as Edge Detection).
The `CustomPostProcess` renderer feature contains 3 lists that represent 3 injection points in the `ScriptableRenderer` as seen in the next image. The three injection points are:
172
+
***After Opaque and Sky** where we can apply effects before the transparent geometry is rendered.
173
+
***Before Post Process** which happens after the transparent geometry is rendered and before the builtin post processing is applied.
174
+
***After Post Process** which happens at the very end before the result is blit to the camera target.
175
+
176
+
The ordering of the effects in a list is the same order in which they are executed (from top to bottom). You can re-order the effects as you see fit. **Note** that the effect must be added to the renderer feature to be rendered, otherwise, it will be ignored. So we added `GrayScale` to its list `After Post Process`.
177
+
178
+

179
+
180
+
Then we will create a volume in the scene (or use an existing volume) and add a `GrayScale Effect` volume component to it as seen in the next image.
181
+
182
+

183
+
184
+
Now you can override the `Blend` parameter and see the view becoming grayscale.
Other stuff we didn't explain but can be seen in the samples:
189
+
* Merge effects and read from more than one volume component (see [GrayAndInvertEffect.cs](Samples~/Examples/Scripts/PostProcessing/GrayAndInvertEffect.cs) and [GrayAndInvert.shader](Samples~/Examples/Resources/Shaders/PostProcessing/GrayAndInvert.shader)).
190
+
* Create temporary render targets inside the renderer (see [StreakEffect.cs](Samples~/Examples/Scripts/PostProcessing/StreakEffect.cs)).
191
+
* Create persistent render targets inside the renderer (see [AfterImageEffect.cs](Samples~/Examples/Scripts/PostProcessing/AfterImageEffect.cs)).
0 commit comments