Game Development Reference
In-Depth Information
From the explanaion, we know that we need to deal with the vertex and pixel shader
programming when we want to write a shader program. For example, if we want to create a
shader, we will need to get the vertex data from our geometry, calculate the data, and pass it
out to the pixel level. At the pixel level, we will calculate the color of the geometry, light, and
shadow, and then we will get the result.
However, this can be very complex when we have to handle lighing manually. That's why
we are using the surface shaders, so we don't have to deal with various types of lightning,
rendering, and so on.
If you check out the ShaderLab link in Unity, you will see that there are a lot of things
to do, but don't be afraid because we don't need to understand everything that's there to
create our custom shader. In the next step, we will create the custom lighing models in
surface shaders.
Shader programming—Ambient and
specular light
In this step, we will add the ambient and specular light to our script as well as create our
custom lighing models.
The custom lighing model is basically the funcion that will be used to
calculate our surface shader, which is the output of ( surf() funcion)
interacion with the lights.
surf() funcion is the funcion 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
1. Go to MonoDevelop, open MyShader.shader file, and go to the Properties
secion and add the highlighted script as follows:
Properties {
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_AmbientColor ("Ambient Color", Color) = (0.1, 0.1, 0.1, 1.0)
_SpecularColor ("Specular Color", Color) = (0.12, 0.31, 0.47, 1.0)
_Glossiness ("Gloss", Range(1.0,512.0)) = 80.0
}
 
Search WWH ::




Custom Search