MatCap
- The full name of MatCap is Material Capture, which stores lighting information in a texture material. By sampling the x-y component along the model's normal line, and hence it obtains the lighting information of the normal line in this direction.
Reference
- Please refer to the links below for a description of the MatCap material.
https://www.youtube.com/watch?v=Yg5ULaS2jMk or http://wiki.unity3d.com/index.php/MatCap
Usage Tips
- The official guide suggests we to calculate capture in a general way.
//MatCap General
half2 MatCapUV ;
matCapUV.x = dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal);
matCapUV.y = dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal);
matCapUV = matCapUV * 0.5 + 0.5;
- However, the effect generated by this general method will cause stretching and deformation when the object (model) is not centered.
- I made a small adjustment, normalizing the normal coefficient according to view posiiton.
//MatCap Normalization
// float3 N = normalize(UnityObjectToWorldNormal(v.normal));
// float3 viewPos = UnityObjectToViewPos(v.vertex);
float2 MatCapUV (in float3 N,in float3 viewPos)
{
float3 viewNorm = mul((float3x3)UNITY_MATRIX_V, N);
float3 viewDir = normalize(viewPos);
float3 viewCross = cross(viewDir, viewNorm);
viewNorm = float3(-viewCross.y, viewCross.x, 0.0);
float2 matCapUV = viewNorm.xy * 0.5 + 0.5;
return matCapUV;
}
- If you don't need a normal map here, you can calculate it directly in VS.
Copyright © 2015 Powered by MWeb, Theme used GitHub CSS.