You are previewing Mastering Unity Shaders and Effects.
O'Reilly logo
Mastering Unity Shaders and Effects

Book Description

Harness the power of Unity 5 tools to write shaders and create stunning effects for next generation games

About This Book

  • Leverage the power of Unity 5 compatible shaders to create a variety of realistic surfaces

  • Create amazing visual effects for your Unity 5.x games by blending advanced post-processing techniques and lighting effects

  • Add that extra visual edge to your games by learning pro level techniques

  • Who This Book Is For

    This book is for users who are familiar with creating Unity projects and are looking for the next step to create stunning high-end visuals in their game project using the latest tools and features. You are expected to understand the creation of basic Unity projects, game object types, and scene navigation. You will need some basic programming experience in C# or JavaScript.

    What You Will Learn

  • Build your own custom shaders to suit a variety of organic and inorganic surfaces

  • Create amazing visual effects using Unity 5's improved toolset

  • Compare the advantages of Metallic and Specular workflows in Unity's Physically Based Lighting System

  • Take your Unity 5 project to the next level with advanced real-time and baked lighting methods

  • Design powerful particle effects

  • Find out how shaders, materials, and scripts work together within the Unity framework

  • Develop high-end and optimized game visuals suitable for mobile devices and other platforms

  • In Detail

    With the inclusion of Physically Based Shading and the Standard Shader, Unity has changed the game for independent and large scale developers alike. Never before has it been so easy to create startling high quality visuals in games and other interactive projects.

    This book will give you a solid understanding of the interaction of shaders, lighting and effects in Unity 5, and give you some great ideas for how you can maximize the visual impact of your own games for PC, mobile and other platforms. In the sequence of chapters you will find solutions to some of the major challenges to the creation of responsive and realistic looking games.

    As you work on example scenes, you will get to know the syntax of ShaderLab and CG languages, creating simple and complex shader solutions for a variety of different surface effects. You will see how Unity’s responsive lighting solutions can be harnessed to build immersive and appealing game experiences.

    Style and approach

    This is the most up-to-date resource on creating amazing visual effects for your Unity 5.x games. With the perfect mix of advanced techniques and their illustrations in real-world examples, this is the most comprehensive advanced guide on Unity shaders and effects you’ll find.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Mastering Unity Shaders and Effects
      1. Mastering Unity Shaders and Effects
      2. Credits
      3. About the Author
      4. About the Reviewer
        1. Why subscribe?
        2. Free access for Packt account holders
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      7. 1. Getting to Grips with Standard Shaders
        1. Creating the project
        2. Importing the project files
        3. Loading and navigating the spacecraft maintenance scene
          1. Creating the astronaut material
          2. Creating a material for the astronaut's accessories
            1. Making objects transparent
          3. Creating the spacecraft material
            1. Creating the spacecraft's decal material
          4. Creating the planet material
          5. Setting up the skybox
          6. Adjusting the scene lighting and adding effects
        4. Summary
      8. 2. Creating Custom Shaders
        1. Opening the project
          1. Opening the scene
          2. Creating our first custom shader
            1. Seeing the shader in action
            2. Adding a texture to the moon shader
            3. Making the moon shader compatible with the scene lighting
        2. Creating better transparency for the astronaut's helmet
          1. Creating a custom transparent shader
          2. Editing the new glass shader
            1. Creating the inner surface of the helmet
              1. Separating front and back faces
        3. Improving the planet's atmosphere
          1. Creating the custom planet shader
          2. Applying the planet shader
          3. Editing the planet shader
            1. Adding new properties to the planet shader
            2. Adding the atmosphere shader pass
              1. Setting the planet material inputs
        4. Summary
      9. 3. Working with Lighting and Light-Emitting Surfaces
        1. Looking at the scene light setup
          1. Adding emissive properties to a material
          2. Adding the Bloom effect
            1. Adding a reflection probe
        2. Creating a wireframe emissive material for the planet-surface scanner
          1. Viewing the wireframe emissive shader in the scene
          2. Adding the wireframe shader's second pass
            1. Completing the planet scan projection effect
        3. Summary
      10. 4. Animating Surfaces with Code and Shaders
        1. Starting the scene
        2. Creating a dynamic warning light effect
          1. Animating the light
        3. Animating the control panel illumination
          1. Animating UV coordinates
        4. Animating the planet projection display
          1. Creating an animated hotspot on the planet
            1. Creating the hotspot geometry
            2. Creating the hotspot material
            3. Writing the hotspot animation script
            4. Setting up the hotspot variables and finalizing the effect
        5. Summary
      11. 5. Exploring Transparent Surfaces and Effects
        1. Starting the scene
          1. Creating the dust cloud material
          2. Adding fog to the scene
          3. Animating the dust cloud transparency
            1. Switching the cloud texture atlas positions
        2. Creating a better transparent glass material
        3. Setting up the whirlwind effect
        4. Summary
      12. 6. Working with Specular and Metallic Surfaces
        1. Starting the scene
          1. Altering the crate's secondary material at runtime
          2. Applying a secondary albedo texture
          3. Creating a custom decal shader for the crate
          4. Switching the decal texture at runtime
        2. Locating and modifying shader light models
          1. Modifying the shader lighting model
          2. Adding specularity to our custom lighting model
        3. Summary
      13. 7. Shaders for Organic Surfaces
        1. Start the scene
        2. Understanding the complexities of human skin
        3. Creating the skin shader
          1. Adding complexity to the skin shader
          2. Writing the custom lighting model
            1. Adding the thickness map input to the shader
        4. Creating the eye material
          1. Creating the custom eye shader
        5. Creating the hair material
          1. Creating the custom hair shader
        6. Summary
      14. 8. Custom Particle Shaders – Smoke, Steam, and Fluids
        1. Starting the scene
        2. Adding a particle system
          1. Adjust the particle system parameters
          2. Setting up a new material for the particle system
        3. Creating the particle shader
          1. Adding a color to the particle shader
          2. Adding the steam particle effect
            1. Adjusting the steam particle's parameters
            2. Completing the steam particle effect
            3. Setting up the steam particle material
          3. Creating the slime-drip effect
            1. Creating the floor damage effect
            2. Writing the control script
            3. Modifying the drop prefab
        4. Summary
      15. 9. Optimizing Shaders for Mobile
        1. Starting the scene
          1. Building the scene for a device
            1. Building for Android
            2. Building for iOS
            3. Viewing the frame rate in the Profiler
        2. Writing a simple mobile shader
          1. Replacing shaders in scene materials
        3. Writing an advanced mobile shader
        4. Summary