Technically, a shader is the function that outputs final pixel color for screen presentation.
But things is not that simple, cause it's just a description for programmers. A shader is not just a function but also has more somewhat emotional touch.
In the past, the shader language is super complicated, so only programmers can handle it, and could produce reliable and quality results.
As time goes on, hardwares have been improved. These days, emotional touch has much more priority than technical efficiency.
Explaining full details about rendering pipeline needs tremendous amount of expertise, so we skip all details.
Send vertex data which includes vertex index, position, normal, color, and such to GPU.
Translate object coordinate to camera coordinate.
Convert 3D object to 2D image
Calculate light, put shadow, sample texture, etc.
Basically there's three ways to write shader using ShaderLab.
- Use only ShaderLab language.
- Surface Shader
- Vertex & Fragment Shader
- Very light computation cost.
- Good hardware compatibility.
- Using Unity specific language, so not very well mixed with other shader syntax.
- Because of this, it's obsolete now.
- Basic lighting and the complex part of vertex shader are automatically handled.
- But when it comes to optimization, it's hard to reach quality result.
- And it's hard to use the case when the advanced technic should be applied.
- Hard to learn, but you can manually control all the part, so it's easy to optimize and good for applying advanced technic.
- Directional Light: Has only information like direction, intensity and color. The cheapest light.
- Point Light: The light proceeds as sphere shape. Has heavier computational cost than directional light.
- Spot Light: Highlights specific area. Also has heavy computational cost, so you should think about performance when use this kind of light.