Book Image

Unity 4 Game Development HOTSHOT

By : Jate Wittayabundit
Book Image

Unity 4 Game Development HOTSHOT

By: Jate Wittayabundit

Overview of this book

<p>Immerse yourself in the world of high-end game design by partaking in challenging missions. Start off by working with the Sprite Mode, then learn the basics of creating a UI system for an RPG, and work your way through the game virtually embodying your greatest hero or heroine.</p> <p>Every project is designed to push your Unity skills to the limit and beyond. You will start by creating a 2D platform game with the new 2D sprite feature and move on to the Unity GUI system. Then, you will create a 3D character and make it move. By the end of this book, you will know how to post the player's score to the hi-score board.</p>
Table of Contents (19 chapters)
Unity 4 Game Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Shader programming – Ambient and Specular light


In this step, we will add Ambient and Specular light to our shader script as well as create our custom lighting models.

Note

The custom lighting model is basically the function that will be used to calculate our surface shader, which is the output of the surf() function's interaction with the lights.

The surf() function is the function that will take any UVs or data we need as input and fill in the output structure SurfaceOutput (the predefined structure, such as Albedo, Normal, Emission, Specular, Gloss, and Alpha).

Engage thrusters

Let's get started. Go to MonoDevelop, open the MyShader file, and go to the Properties section and add the highlighted script:

Properties {
  _AmbientColor ("Ambient Color", Color) = (0.5, 0.5, 0.5, 1.0)
  _SpecularColor ("Specular Color", Color) = (0.17, 0.42, 0.75, 1.0)
  _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
  _MainTex ("Diffuse (RGBA)", 2D) = "white" {}
  _BumpMap ("Bumpmap", 2D) = "bump" {}
}

Next...