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)
1
Part 1: Creating Shaders in Unity
3
Part 2: Stepping Up to URP and the Shader Graph
8
Part 3: Advanced Game Shaders
12
Part 4: Optimizing Your Unity Shaders
15
Part 5: The Toolbox

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “At that point, our URP shader is set up to use the scriptable render feature, which will automatically call the compute shader we prepared in our FillWithRed.compute asset and return a full red opaque color for each pixel on the screen.”

A block of code is set as follows:

using UnityEngine;
using UnityEngine.Rendering;
[CreateAssetMenu(menuName = "Compute Assets/CH07/FillWithRed")]
public class ComputeFillWithRed : URPComputeAsset {
    public override void Render(CommandBuffer commandBuffer,
        int kernelHandle) {}
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

private void _GenerateGrid() {
    _cubes = new List<GameObject>();
    _cubeRenderers = new List<MeshRenderer>();
    _data = new Cube[gridSize * gridSize];
    ...
    for (int x = 0; x < gridSize; x++) {
        for (int y = 0; y < gridSize; y++) {
            ...
            _cubes.Add(g);
            _cubeRenderers.Add(r);
            _data[x * gridSize + y] = new Cube() {
                position = g.transform.position,
                color = color
            };
        }
    }
}

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “To get this incoming vector, we use the View Direction node – and the offset is then computed by multiplying it with a given float value.”

Tips or important notes

Appear like this.