public static void InitializeDirections()
{
float z = (1f + Mathf.Sqrt(5f)) / 2f;
directions = new Vector3[60];
directions[0] = new Vector3(0f, 1f, 3f * z);
directions[1] = new Vector3(0f, 1f, -3f * z);
directions[2] = new Vector3(0f, -1f, 3f * z);
directions[3] = new Vector3(0f, -1f, -3f * z);
directions[4] = new Vector3(1f, 3f * z, 0f);
directions[5] = new Vector3(1f, -3f * z, 0f);
directions[6] = new Vector3(-1f, 3f * z, 0f);
directions[7] = new Vector3(-1f, -3f * z, 0f);
directions[8] = new Vector3(3f * z, 0f, 1f);
directions[9] = new Vector3(3f * z, 0f, -1f);
directions[10] = new Vector3(-3f * z, 0f, 1f);
directions[11] = new Vector3(-3f * z, 0f, -1f);
int offset = 12;
offset = PermuteCuboid(directions, offset, 2f, 1f + (2f * z), z);
offset = PermuteCuboid(directions, offset, 1f + (2f * z), z, 2f);
offset = PermuteCuboid(directions, offset, z, 2f, 1f + (2f * z));
offset = PermuteCuboid(directions, offset, 1f, 2f + z, 2f * z);
offset = PermuteCuboid(directions, offset, 2f + z, 2f * z, 1f);
offset = PermuteCuboid(directions, offset, 2f * z, 1f, 2f + z);
for (int i = 0; i < directions.Length; i++)
{
directions[i] = directions[i].normalized;
}
}
public static void CalcSoftOcclusion(Mesh mesh) { GameObject gameObject = new GameObject("Test"); gameObject.layer = 29; MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>(); meshFilter.mesh = mesh; gameObject.AddComponent <MeshCollider>(); if (TreeAO.directions == null) { TreeAO.InitializeDirections(); } Vector4[] array = new Vector4[TreeAO.directions.Length]; for (int i = 0; i < TreeAO.directions.Length; i++) { array[i] = new Vector4(TreeAO.GetWeight(1, TreeAO.directions[i]), TreeAO.GetWeight(2, TreeAO.directions[i]), TreeAO.GetWeight(3, TreeAO.directions[i]), TreeAO.GetWeight(0, TreeAO.directions[i])); } Vector3[] vertices = mesh.vertices; Vector4[] array2 = new Vector4[vertices.Length]; float num = 0f; for (int j = 0; j < vertices.Length; j++) { Vector4 vector = Vector4.zero; Vector3 v = gameObject.transform.TransformPoint(vertices[j]); for (int k = 0; k < TreeAO.directions.Length; k++) { float num2 = (float)TreeAO.CountIntersections(v, gameObject.transform.TransformDirection(TreeAO.directions[k]), 3f); num2 = Mathf.Pow(0.5f, num2); vector += array[k] * num2; } vector /= (float)TreeAO.directions.Length; num += vector.w; array2[j] = vector; } num /= (float)vertices.Length; for (int l = 0; l < vertices.Length; l++) { Vector4[] expr_1D4_cp_0 = array2; int expr_1D4_cp_1 = l; expr_1D4_cp_0[expr_1D4_cp_1].w = expr_1D4_cp_0[expr_1D4_cp_1].w - num; } mesh.tangents = array2; UnityEngine.Object.DestroyImmediate(gameObject); }