Post Processing — Scripted!
Objective: Learn to use the package manager and the Post Processing package
With this tutorial I want to introduce the Post Processing. I am not an artist, but knowing a little more than programming is always helpful.
Post Processing means applying filters and image processing to the game visuals, not affecting the game properties but just how does it appear.
So, let’s put some make up on! The purpose? Step the level up and get close to the visual of great games!
First we have to install a post processing package. Unity Post Processing package is a very good choice.
From window tab, select Package Manager, here you will find a lot of Unity maintained packages and products. Select Packages: Unity Registry and search for the post processing. Once you select it, you can install it via the Install button.
The first step now, is to add a new component to the camera, since all we see in game is what the camera sees. Add the Post-Process Layer component.
Then, you have to create a new layer, as already did, name it Post Processing and assign it to Volume Layer in the camera component.
Now it’s time to create a Post Processing profile.
Create a new empty gameobject and add the Post Process Volume component.
You can set it to global, to operate on all the environment. Global is opposed to local, which means that the post processing will operate only in certain regions. You can also have more than one Volume and assign a priority to each one. Click on New to add a new default profile and on Add effect to start messing around with post processing!
Here we’re going to play with two effects: Colour Grading and Bloom, since I am a fan of HDR and Legolas.
Once the effect is added, you’ll notice a warning saying that HDR colour won’t look right because the default colour space is set to Gamma, while you need Linear. To correct this open the Build Settings, Player Settings, Other Settings and switch the Color Space to Linear.
This will force the project to recompile and will take a couple of minutes. Don’t forget to assign this object too to the Post Processing Layer!!
You can now play a little bit with this powerful effect, personally I’m just good with the activation of HDR mode and ACES tone mapping. Look at the difference before vs after:
Darker shades, much cooler!
Let’s now proceed to the bloom effect. With an intensity of 15, this is what happens to the sprites:
It’s not much yeah?
I had an idea: let’s manipulate it from script!!
Much easier than you think: this script is attached to the Post Processing volume object, first we grab reference to the volume component and then to the bloom effect. In this case, since it is not a Unity component, the processes is a little different and involves out modifier to pass the bloom variable by reference. See documentation for more info.
The core logic is a simple bloom fade in a coroutine, I calculate the fading steps, starting from a base time step.
What more? Call the method when an explosion occurs and pass the clip length as time parameter t. Let’s light things up!!