base pass
- First directional light is in the base pass
- base pass is drawn no matter if there is a directional light.
- declare in Tags before CGPROGRAM after pass
- vertex light need to be in base pass , declare with VERTEXLIGHT_ON
add pass
- Enable the blending between base and add pass by Blend One One
- support directional / point / spot light : multi_compile_fwdadd
include file
include file aim to reuse code include all the vertex / fragment function code and some variables declaration and includes files.
Include is just simple replace all the code in the included file to the including file.
Include is just simple replace all the code in the included file to the including file.
- a typical including declare is like this. It prevent include the same files twice.
- include file ends with "cginc"
- base pass and add pass can use the same include file
support different lights
- according to different light type calculate the light.dir differently
- UNITY_LIGHT_ATTENUATION(atten , vertextOut , vertextOut. worldPos ) provide the attenuation for point and spot light, it will always be 1 for directional light.
vertex light
- four vertex lights can be used. When pixel lights reach the set limited, Unity switch to vertex light.
- to set the pixel light limitation : edit -> project setting -> quality -> pixel light count
- declare in base pass #pragma multi_compile _ VERTEXLIGHT_ON
- In vertex out structure declare vertexLightcolor to pass the vertex light to fragment function
- light.
- calculate the vertex light using the function ShadePointLight()
- vertex light is put into indirect light
One thing on vertex light is very important
To force vertex light , put the vertex light to not important render mode in light setting
environment Light
- environmental light is captured by spherical harmonic function in Unity.
- the function should only be used in the base pass
- the function should contribute to the indirect diffuse light.
No comments:
Post a Comment