//Manager function for checking every third vertices to see if behind the camera, for each triangle that //is behind the plane will return the center of the triangle void checkNearPlaneCollisions() { Vector3[] vertices = mesh.vertices; Plane[] p = GeometryUtility.CalculateFrustumPlanes(secondaryCamera); for (int i = 0; i < vertices.Length; i += 3) { if (!pointAlreadyPassed.Contains(vertices[i])) { if (vertexIsBehindPlane(vertices[i], p[4])) { pointAlreadyPassed.Add(vertices[i]); //Getting center of a vertice for spawning high detail model Vector3 centerOfTriangle = ((vertices[i] + vertices[i + 1] + vertices[i + 2]) / 3); Vector3 highDetailPos = centerOfTriangle; Color clr = mesh.colors[i]; highDetailPos.z = (centerOfTriangle.z - (secondaryCamera.transform.position.z + secondaryCamera.nearClipPlane)) * 2f; highDetailPos.z += secondaryCamera.transform.position.z + secondaryCamera.nearClipPlane; //Send coordinates to Pool Manager GameObject star = highDetailStarPool.CreateOrPool(highDetailPos, Quaternion.identity); MeshRenderer starRenderer = star.GetComponent <MeshRenderer>(); Material starMaterial = starRenderer.material; starMaterial.color = mesh.colors[i]; starRenderer.material = starMaterial; float scale = setScale(true); star.transform.localScale = new Vector3(scale, scale, scale); UnityEngine.Debug.Log("Star-added: " + centerOfTriangle.z + " " + (secondaryCamera.transform.position.z + secondaryCamera.nearClipPlane) + " " + highDetailPos.z, star); } } } }