Become a Unity Shaders Guru - Mina Pêcheux - E-Book

Become a Unity Shaders Guru E-Book

Mina Pêcheux

0,0
32,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 597

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Become a Unity Shaders Guru

Create advanced game visuals using code and graphs

Mina Pêcheux

BIRMINGHAM—MUMBAI

Become a Unity Shaders Guru

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Chayan Majumdar

Senior Content Development Editor: Rashi Dubey

Technical Editor: Simran Ali

Copy Editor: Safis Editing

Project Coordinator: Arul Viveaun S

Proofreader: Safis Editing

Indexer: Subalakshmi Govindhan

Production Designer: Jyoti Chauhan

Marketing Coordinator: Nivedita Pandey and Namita Velgekar

First published: July 2023

Production reference: 1130623

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-83763-674-7

www.packtpub.com

Contributors

About the author

Mina Pêcheux is a freelance content creator who has been passionate about game development since an early age. She is a graduate of the French Polytech School of Engineering in applied mathematics and computer science. After a couple of years of working as a data scientist and web developer in start-ups, she turned to freelancing and online instructional content creation to reconnect with what brightens her days: learning new things every day, sharing with others, and creating multi-field projects that mix science, technology, and art.

About the reviewers

Obinna Akpen is a seasoned 2D/3D game developer and e-sports champion with a passion for creating immersive gaming experiences. With over four years of experience in the industry, he has established himself as a highly skilled and innovative professional. Holding a bachelor of science in computer science, Obinna has demonstrated exceptional expertise in Unity and C# scripting, allowing him to develop captivating games that have garnered millions of downloads and a large player base.

Obinna’s talent shines through in his ability to bring creative visions to life. He has a keen eye for detail and a deep understanding of game mechanics, enabling him to design and implement gameplay features that engage players and keep them coming back for more. His contributions to the game development process, from prototyping to optimization, have been instrumental in delivering successful projects.

One of Obinna’s standout skills is his knowledge of shader development, particularly High-Level Shader Language (HLSL), which has been a valuable asset on projects that require advanced visual effects and graphics rendering. His proficiency in this area allows him to create stunning visuals that enhance the overall gaming experience.

In addition to his technical expertise, Obinna is a natural problem-solver and critical thinker. He thrives in fast-paced environments and excels at overcoming challenges to deliver high-quality results within tight deadlines. His ability to analyze and adapt game mechanics showcases his dedication to creating games that provide enjoyable and immersive experiences for players.

Beyond his technical accomplishments, Obinna’s passion for mentoring and teaching sets him apart. Through his involvement in various game development events and initiatives, he has shared his knowledge and expertise with aspiring game developers. His commitment to fostering growth and supporting emerging talent in the gaming industry reflects his belief in the power of collaboration and knowledge sharing.

Obinna’s impact and success have been recognized through multiple awards and industry recognition. His dedication to his craft and his ability to push boundaries in game development have earned him accolades such as the Game Developer of the Year and Most Versatile Gamer of the Year awards. These achievements highlight his outstanding contributions and reinforce his status as a respected professional in the gaming community.

With a combination of technical prowess, creative vision, and a passion for mentorship, Obinna Akpen continues to make a significant impact in the world of game development. His dedication to creating immersive gaming experiences and his commitment to pushing the boundaries of innovation make him a valuable asset to any game development team.

Mohan Reddy Mummareddy is an accomplished Unity3D developer with expertise in Augmented Reality (AR), Virtual Reality (VR), Mixed Reality (MR), and game development. With seven years of experience, he has delivered numerous successful projects, demonstrating proficiency in computer vision and Artificial Intelligence (AI) technologies. Mohan has contributed to the development of iPhone operating system (iOS) applications utilizing light detection and ranging (LIDAR) technology for Machine Learning (ML) training and Unity’s Barracuda for model inference. He has also worked on virtual experience products, leveraging AR/VR/MR and web technologies. Mohan holds a master of technology in AR and VR, a master of business administration in marketing, and a bachelor of technology in electrical and electronics. Passionate about extended reality, he strives to push boundaries and create strong AI-enabled Extended Reality (XR) platforms and solutions.

Table of Contents

Preface

Part 1: Creating Shaders in Unity

1

Re-Coding a Basic Blinn-Phong Shader with Unity/CG

Technical requirements

Doing a quick study of the Blinn-Phong shading model

Using diffuse lighting for a basic render

Better integrating the object – thanks to ambient lighting

Adding some light reflections with a specular

Setting up our shader in Unity

Checking your project configuration

Creating the shader file

Implementing the diffuse lighting

Adding the ambient and specular components

Injecting the ambient lighting

Computing the specular lighting

Making a top-notch inspector!

Why should I waste time refining an editor inspector?

Faking Booleans?

Improving our glossiness display

A few additional tricks

Summary

Going further

Part 2: Stepping Up to URP and the Shader Graph

2

The Three Unity Render Pipelines

Technical requirements

Using the built-in render pipeline

A handy but limited pipeline

The power of CommandBuffers

Stepping up with the URP render pipeline

A powerful pipeline for all creators

Making shaders and VFX with graphs

Installing the URP

Going realistic with the HDRP render pipeline

Diving deeper into the SRPs

Summary

Going further

3

Writing Your First URP Shader

Technical requirements

Structuring a Unity HLSL shader

Having a peek at shader includes and tags

Including the URP core module

Updating our built-in variables and functions

Picking the right tags for our shader

Writing our unlit URP shader

Summary

Going further

4

Transforming Your Shader into a Lit PBS Shader

Technical requirements

Discovering Unity PBR-related tooling

A quick overview of shader keywords and variants

Taking advantage of the built-in PBR lighting helpers

Adding the right include statements and keywords to our shader

Understanding the PBR data structures

Coding our lit PBS shader logic

Preparing our shader properties

Initializing our data structures

Setting up the vertex and fragment shader functions

Summary

Going further

5

Discovering the Shader Graph with a Toon Shader

Technical requirements

What is the Shader Graph?

A tool for everyone…or not

Installing the Shader Graph

Discovering the Shader Graph tool

Learning the essentials of Shader Graph

An overview of the toon shader

Implementing the albedo feature

Adding alpha clipping

Handling emission

Setting up the lighting

Improving our toon shader

Adding an outline to our shader

Organizing the graph better

Summary

Going further

Part 3: Advanced Game Shaders

6

Simulating Geometry Efficiently

Technical requirements

Using billboarding for in-game UI displays

Understanding the concept of billboarding

Implementing billboarding in Shader Graph

Faking depths and heights with parallax mapping

Reviewing the basics of parallax mapping

Fixing our squash-and-stretch issue

Creating cracked ice with dithering

Taking advantage of the built-in nodes

Creating hundreds of rooms with one cube… and interior mapping

What is interior mapping?

A quick note on cubemaps

Setting up a node-based interior mapping shader

Summary

Going further

Billboarding

Parallax mapping

Interior mapping

7

Exploring the Unity Compute Shaders and Procedural Drawing

Technical requirements

Discovering compute shaders and compute buffers

What are compute shaders?

Using compute buffers to pass data between the CPU and the GPU

Creating and studying the structure of a compute shader

Generating a grid of randomized cubes

Writing a naive C# implementation

Examining the limitations of our CPU implementation

Optimizing the process with compute shaders

Applying a compute shader-based screen effect in URP

Preparing custom URP render assets

Integrating our compute shader in the URP

Summary

Going further

8

The Power of Ray Marching

Technical requirements

Understanding the fundamentals of ray marching

Describing a shape with SDFs

Turning SDFs into renders with the ray marching loop

Upping the ante with basic shading

Entering a world of primitives...

Rendering a sphere with ray marching

Upgrading our procedural generation logic to handle a multi-shape render

Studying a common use case – the rendering of volumetric clouds

Using ray marching for volumetric clouds

Creating clouds in Unity

Summary

Going further

Part 4: Optimizing Your Unity Shaders

9

Shader Compilation, Branching, and Variants

Technical requirements

Learning some Unity shader compilation tricks

Understanding Unity’s shader caching system

The magic of asynchronicity

Handling AssetBundles

Taking advantage of shader branching and shader variants

Using static branching – fast but restrictive

Turning to dynamic branching – adaptive but slow

Switching to shader variants… or not

Understanding the risks of shader variants

Exploring shader macros and platform-dependent compilation

Identifying the target platform

Checking the version of your tools

Ensuring your coordinates are oriented properly

Additional resources

Summary

Going further

10

Optimizing Your Code, or Making Your Own Pipeline?

Technical requirements

Picking the right shading model

Exploring Unity’s URP built-in shading models

Using the URP shading models

A quick side-note for the built-in render pipeline

Optimizing your runtime performance

Float, half, or fixed?

Avoiding complex mathematical operations

Handling transparency in shaders

Creating SRP Batcher-compatible shaders

Checking that you only compute what’s needed

Having too much flexibility

Creating your own SRP

Why use a custom render pipeline?

Setting up a basic custom SRP

Summary

Going further

Shader code optimization

Custom SRPs

Part 5: The Toolbox

11

A Little Suite of 2D Shaders

Technical requirements

Implementing color-swap, hue-shift, saturate, negate, and pixelate effects

Performing basic operations such as hue-shift, saturate, and negate

Creating a color-swap system

Pixelating a sprite dynamically

Making 2D outlines

Implementing a simple outline

Making our stroke glow

Adding animation to our outline

Having fun with overlay textures, dissolves, and holograms

Showing an overlay texture

Making a tweakable dissolve effect

Creating a hologram effect

Summary

Going further

12

Vertex Displacement Shaders

Technical requirements

Animating fishes and butterflies

Moving fishes thanks to a vertex displacement shader

Displacing a butterfly

Creating waves with vertex displacement

Understanding the importance of mesh resolution

Setting up waves displacement

Computing our displaced normals

Browsing some extra ideas

Unity’s official vertex displacement tutorial

Alan Zucconi’s interactive map

Cyanilux’s melting candle

Summary

Going further

13

Wireframes and Geometry Shaders

Technical requirements

Understanding the principles and limitations of geometry shaders

What are geometry shaders?

Some notable limitations of geometry shaders

Watching out for incompatibility with Apple devices

Creating a URP wireframe shader

Preparing our URP wireframe shader

Implementing the geometry stage in our shader

Making fixed-width antialiased wireframe edges

Summary

Going further

14

Screen Effect Shaders

Technical requirements

Using fullscreen shaders in URP

The case of the built-in render pipeline

Switching our fullscreen effects over to URP

A little example – turning our render grayscale

Creating a security camera effect

Implementing the color tinting and scanlines

Improving the effect with postprocessing

Making a fullscreen box blur

What is a box blur?

Creating a box blur Sub Graph

Setting up the 2D box blur screen effect

Summary

Going further

Appendix: Some Quick Refreshers on Shaders in Unity

Rendering 3D scenes on a 2D screen

A typical 3D rendering pipeline

Using shaders in Unity

Exploring SubShader and Pass tags

Recalling the basics of z-buffering and blending modes

Culling and depth testing

Blending modes for the quick win

Reviewing textures and UV mapping

Wrapping a 2D image on a 3D shape

Broadening our definition of a texture

Using textures in a Unity shader

Summary

Index

Other Books You May Enjoy

Part 1: Creating Shaders in Unity

Before we dive into Unity’s new render pipelines and modern shader creation tools, let’s first take a bit of time to re-familiarize ourselves with the process of creating shaders in Unity. In this introductory part, we’ll start with a quick reminder of how to implement the well-known Blinn-Phong shading model in Unity’s built-in render pipeline.

In this part, we will cover the following chapter:

Chapter 1, Re-Coding a Basic Blinn-Phong Shader with Unity/CG


Tausende von E-Books und Hörbücher

Ihre Zahl wächst ständig und Sie haben eine Fixpreisgarantie.