PacktLib: Unity Shaders and Effects Cookbook

Unity Shaders and Effects Cookbook


About the Author

About the Reviewers


Diffuse Shading


Creating a basic Surface Shader

Adding properties to a Surface Shader

Using properties in a Surface Shader

Creating a custom diffuse lighting model

Creating a Half Lambert lighting model

Creating a ramp texture to control diffuse shading

Creating a faked BRDF using a 2D ramp texture

Using Textures for Effects


Scrolling textures by modifying UV values

Animating sprite sheets

Packing and blending textures

Normal mapping

Creating procedural textures in the Unity editor

Photoshop levels effect

Making Your Game Shine with Specular


Utilizing Unity3D's built-in Specular type

Creating a Phong Specular type

Creating a BlinnPhong Specular type

Masking Specular with textures

Metallic versus soft Specular

Creating an Anisotropic Specular type

Reflecting Your World

Creating Cubemaps in Unity3D

Simple Cubemap reflection in Unity3D

Masking reflections in Unity3D

Normal maps and reflections in Unity3D

Fresnel reflections in Unity3D

Creating a simple dynamic Cubemap system

Lighting Models


The Lit Sphere lighting model

The diffuse convolution lighting model

Creating a vehicle paint lighting model

Skin shader

Cloth shading



Creating transparency with alpha

Transparent cutoff shader

Depth sorting with render queues

GUI and transparency

Vertex Magic


Accessing a vertex color in a Surface Shader

Animating vertices in a Surface Shader

Using vertex color for terrains

Mobile Shader Adjustment


What is a cheap Shader?

Profiling your Shaders

Modifying your Shaders for mobile

Making Your Shader World Modular with CgIncludes


CgInclude files that are built into Unity

Creating a CgInclude file to store lighting models

Building Shaders with #define directives

Screen Effects with Unity Render Textures


Setting up the screen effects script system

Brightness, saturation, and contrast with screen effects

Basic Photoshop-like blend modes with screen effects

The Overlay blend mode with screen effects

Gameplay and Screen Effects


Creating an old movie screen effect

Creating a night vision screen effect