Book Image

Become a Unity Shaders Guru

By : Mina Pêcheux
5 (1)
Book Image

Become a Unity Shaders Guru

5 (1)
By: Mina Pêcheux

Overview of this book

Do you really know all the ins-and-outs of Unity shaders? It’s time to step up your Unity game and dive into the new URP render pipeline, the Shader Graph tool, and advanced shading techniques to bring out the beauty of your 2D/3D game projects! Become a Unity Shaders Guru is here to help you transition from the built-in render pipeline to the SRP pipelines and learn the latest shading tools. With it, you’ll dive deeper into Unity shaders by understanding the essential concepts through practical examples. First, you’ll discover how to create a simple shading model in the Unity built-in render pipeline, and then in the Unity URP render pipeline and Shader Graph while learning about the practical applications of both. You’ll explore common game shader techniques, ranging from interior mapping to adding neon outlines on a sprite or simulating the wobble of a fish. You’ll also learn about alternative rendering techniques, like Ray Marching. By the end of this book, you’ll have learned to create a wide variety of 2D and 3D shaders with Unity’s URP pipeline (both in HLSL code and with the Shader Graph tool), and be well-versed with some optimization tricks to make your games friendly for low-tier devices as well.
Table of Contents (23 chapters)
Part 1: Creating Shaders in Unity
Part 2: Stepping Up to URP and the Shader Graph
Part 3: Advanced Game Shaders
Part 4: Optimizing Your Unity Shaders
Part 5: The Toolbox

Making 2D outlines

After this brief introduction to 2D sprite shaders, we will move on to another nice topic for 2D shaders: the auto-outlining of sprites, thanks to dynamic and tweakable stroke shaders. Our goal here is to build more and more advanced shaders to introduce new effects gradually and create more complex outlines around our sprites.

We will first begin with a simple outline using one solid color, then we will see how to use post-processing and HDR emissive colors to add glow, and finally, we will study how to make animated shaders that use the current time in their logic.

Implementing a simple outline

First of all, let’s see how to implement a simple sprite outline for a pixel-perfect sprite. This is a simple technique for adding a stroke that relies only on copying and translating. It doesn’t handle corners, so it doesn’t work very well for smooth sprites, but here is how it will look on our sample pixel-perfect sphere:

Figure 11.17 – Pixel-perfect sphere sprite without (left) and with (right) our soon-to-be Outline shader ...