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); }
public static void CalcSoftOcclusion(Mesh mesh) { GameObject gameObject = new GameObject("Test"); gameObject.layer = 29; gameObject.AddComponent <MeshFilter>().mesh = mesh; gameObject.AddComponent <MeshCollider>(); if (TreeAO.directions == null) { TreeAO.InitializeDirections(); } Vector4[] vector4Array1 = new Vector4[TreeAO.directions.Length]; for (int index = 0; index < TreeAO.directions.Length; ++index) { vector4Array1[index] = new Vector4(TreeAO.GetWeight(1, TreeAO.directions[index]), TreeAO.GetWeight(2, TreeAO.directions[index]), TreeAO.GetWeight(3, TreeAO.directions[index]), TreeAO.GetWeight(0, TreeAO.directions[index])); } Vector3[] vertices = mesh.vertices; Vector4[] vector4Array2 = new Vector4[vertices.Length]; float num1 = 0.0f; for (int index1 = 0; index1 < vertices.Length; ++index1) { Vector4 zero = Vector4.zero; Vector3 v = gameObject.transform.TransformPoint(vertices[index1]); for (int index2 = 0; index2 < TreeAO.directions.Length; ++index2) { float num2 = Mathf.Pow(0.5f, (float)TreeAO.CountIntersections(v, gameObject.transform.TransformDirection(TreeAO.directions[index2]), 3f)); zero += vector4Array1[index2] * num2; } zero /= (float)TreeAO.directions.Length; num1 += zero.w; vector4Array2[index1] = zero; } float num3 = num1 / (float)vertices.Length; for (int index = 0; index < vertices.Length; ++index) { vector4Array2[index].w -= num3; } mesh.tangents = vector4Array2; Object.DestroyImmediate((Object)gameObject); }