public static void CalcSoftOcclusion(Mesh mesh)
{
GameObject obj2 = new GameObject("Test") {
layer = 0x1d
};
obj2.AddComponent<MeshFilter>().mesh = mesh;
obj2.AddComponent<MeshCollider>();
if (directions == null)
{
InitializeDirections();
}
Vector4[] vectorArray = new Vector4[directions.Length];
for (int i = 0; i < directions.Length; i++)
{
vectorArray[i] = new Vector4(GetWeight(1, directions[i]), GetWeight(2, directions[i]), GetWeight(3, directions[i]), GetWeight(0, directions[i]));
}
Vector3[] vertices = mesh.vertices;
Vector4[] vectorArray3 = new Vector4[vertices.Length];
float num2 = 0f;
for (int j = 0; j < vertices.Length; j++)
{
Vector4 zero = Vector4.zero;
Vector3 v = obj2.transform.TransformPoint(vertices[j]);
for (int m = 0; m < directions.Length; m++)
{
float p = CountIntersections(v, obj2.transform.TransformDirection(directions[m]), 3f);
p = Mathf.Pow(0.5f, p);
zero += (Vector4) (vectorArray[m] * p);
}
zero = (Vector4) (zero / ((float) directions.Length));
num2 += zero.w;
vectorArray3[j] = zero;
}
num2 /= (float) vertices.Length;
for (int k = 0; k < vertices.Length; k++)
{
vectorArray3[k].w -= num2;
}
mesh.tangents = vectorArray3;
Object.DestroyImmediate(obj2);
}