Book Image

Unity 2018 Shaders and Effects Cookbook - Third Edition

By : John P. Doran, Alan Zucconi
Book Image

Unity 2018 Shaders and Effects Cookbook - Third Edition

By: John P. Doran, Alan Zucconi

Overview of this book

Since their introduction to Unity, shaders have been seen as notoriously difficult to understand and implement in games. Complex mathematics has always stood in the way of creating your own shaders and attaining the level of realism you crave. Unity 2018 Shaders and Effects Cookbook changes that by giving you a recipe-based guide to creating shaders using Unity. It will show you everything you need to know about vectors, how lighting is constructed with them, and how textures are used to create complex effects without the heavy math. This book starts by teaching you how to use shaders without writing code with the post-processing stack. Then, you’ll learn how to write shaders from scratch, build up essential lighting, and finish by creating stunning screen effects just like those in high-quality 3D and mobile games. You'll discover techniques, such as normal mapping, image-based lighting, and animating your models inside a shader. We'll explore how to use physically based rendering to treat light the way it behaves in the real world. At the end, we’ll even look at Unity 2018’s new Shader Graph system. With this book, what seems like a dark art today will be second nature by tomorrow.
Table of Contents (14 chapters)

Mimicking real life with bloom and anti-aliasing

The bloom optical effect aims to mimic the imaging effects of real-world cameras, where things in areas with lights will glow along the edges, thus overwhelming the camera. The bloom effect is very distinctive and you've likely seen it employed in areas in a game that are magical or heaven-like.

Getting ready

Make sure you have completed the Installing the Post Processing Stack recipe before starting this one.

How to do it...

  1. We first create a new Post Processing Profile by right-clicking within the Assets folder in the Project window and then selecting Create | Post Processing Profile. Once selected, it will allow us to rename the item. Go ahead and set the name to BloomProfile.
  2. Select the Post-process volume object and, from the Inspector window, go to the Post Processing Volume component and assign the Profile property to the BloomProflie we just created.
  1. Afterward, select the Game tab, if it hasn't been selected already to see the results of the changes we are about to make in the following steps.
  2. Select the Add effect... button and select Unity | Bloom. Once the effect has been added to the Overrides section of the Post Processing Volume component, select the arrow to open its properties. Check the Intensity property and set it to 3. Afterward, check and set the Threshold to 0.75, the Soft Knee to 0.1, and the Radius to 3:
  1. Next, select the object with the Post Process Layer component attached to it (in the example, it is the FPSController | FirstPersonCharacter object) and, from the Inspector tab, scroll down to the Post Process Layer script. From there, change the Anti-aliasing property dropdown to Fast Approximate Anti-aliasing:
  1. Afterward, save your scene and hit the Play button to check out your project:
The final result of using bloom and anti-aliasing

How it works...

As mentioned before, bloom will make bright things even brighter while adding a glow to lighter areas. In this recipe, you may notice that the path is much lighter than it was previously. This can be used in order to ensure that players will follow the path to get to the next section of gameplay.

For more information on bloom, check out: https://github.com/Unity-Technologies/PostProcessing/wiki/Bloom.

Anti-aliasing attempts to reduce the appearance of aliasing, which is the effect of lines appearing jagged on the screen. This is typically due to the fact that the display the player is using to play the game doesn't have a high enough resolution to be displayed properly. Anti-aliasing will combine colors with nearby lines in order to remove their prominence, at the cost of the game appearing blurry.

For more information on anti-aliasing and what each mode means, check out: https://github.com/Unity-Technologies/PostProcessing/wiki/Anti-aliasing.