Transferred from: http://blog.163.com/wmk_2000_ren/blog/static/138846192201019114117466/
Realized, the Aras great God has given,
http://forum.unity3d.com/threads/shadow-volumes-in-unity-on-the-wiki.9452/
Http://wiki.unity3d.com/index.php/Shadow_Volumes_in_Alpha
The principle also has a ready-made paper to explain clearly. Can not be on Google, link back to fill ...
I'm almost using Chinese to retell the whole process.
First, the reason is based on Alpha because the template cache is not always available, and Alpha doesn't have to worry about having no effect. This is achieved using alpha, although not necessarily in the project because of the high fill rate.
Ideas are as follows:
The first step is to change the frame buffer's alpha value to One-fourth.
The second step is to draw the shaded surface. The alpha value of the front becomes twice times and the reverse is halved. At this point, the alpha value of the shaded area becomes 1/2 and 1, not the shaded area.
The third step is to do four framebuffer operation, the first time is to Double alpha, the shadow region's alpha value becomes 1, the other region becomes 1/2. The second is to invert the alpha value, the alpha value of the blend zero Oneminusdstalpha to 0, the other area is 1/2, the alpha is doubled for the third time, the value of the shaded area is 0, and the other area becomes 1, and the fourth time it is assigned the color.
Concrete implementation, will involve some details, more trouble, slowly fill.
"Untiy 3d Shaderlab development of practical explanation" there is also relevant content: source code in the example project Shadowvolumes
(go) The alpha channel-based shadow volume implementation in Unity