public void Update() { // Twitter :) int kern = FindBirds.FindKernel("FindDirection"); if (Input.anyKey) { Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit RH; if (Physics.Raycast(r, out RH, Mathf.Infinity, targetLayer)) { FindBirds.SetFloat("pullAmount", 0.5f); FindBirds.SetVector("totalPullPosition", RH.point); } else { FindBirds.SetFloat("pullAmount", 0.0f); } //FindBirds.SetVector("totalPullPosition", Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), )); } else { FindBirds.SetFloat("pullAmount", 0.0f); } LogicalUpdate(); // Originally housed some other code... }
public void Start() { int kern = FindBirds.FindKernel("FindDirection"); LocationsOfBirds = new ComputeBuffer(MAX_BIRDS, 4 * sizeof(float)); DirectionsOfBirds = new ComputeBuffer(MAX_BIRDS, 4 * sizeof(float)); NewDirections = new ComputeBuffer(MAX_BIRDS, 4 * sizeof(float)); FindBirds.SetBuffer(kern, "Locations", LocationsOfBirds); FindBirds.SetBuffer(kern, "Direction", DirectionsOfBirds); FindBirds.SetBuffer(kern, "NewDirection", NewDirections); }
public void LogicalUpdate() { int kern = FindBirds.FindKernel("FindDirection"); if (otherBirds.Count != 0) { // Cool.... // This will manually change the movement.... FindBirds.SetFloat("FlockDistance", flockRange); FindBirds.SetFloat("DodgeDistance", dodgeDistance); FindBirds.SetInt("NumberOfBirds", otherBirds.Count); FindBirds.SetVector("RuleStrengths", ruleStrengths); Vector4[] birdLocs = new Vector4[otherBirds.Count]; Vector4[] birdDir = new Vector4[otherBirds.Count]; Vector4[] birdNewDir = new Vector4[otherBirds.Count]; for (int i = 0; i < otherBirds.Count; i++) { birdLocs[i] = otherBirds[i].transform.position; birdDir[i] = otherBirds[i].transform.forward; } LocationsOfBirds.SetData(birdLocs, 0, 0, birdLocs.Length); DirectionsOfBirds.SetData(birdDir, 0, 0, birdDir.Length); FindBirds.SetBuffer(kern, "Locations", LocationsOfBirds); FindBirds.SetBuffer(kern, "Direction", DirectionsOfBirds); var CT = System.DateTime.UtcNow; FindBirds.Dispatch(kern, otherBirds.Count, 1, 1); //Debug.Log((System.DateTime.UtcNow- CT).Milliseconds); NewDirections.GetData(birdNewDir, 0, 0, otherBirds.Count); for (int i = 0; i < otherBirds.Count; i++) { if (Mathf.Approximately(birdNewDir[i].w, 0)) { SetNewMovement(otherBirds[i], i, Vector3.zero, new float[] { numRays, searchArc, sphereCheckRad, targetLayer.value, speed, slerpAmount }); } else { SetNewMovement(otherBirds[i], i, new Vector3(birdNewDir[i].x, birdNewDir[i].y, birdNewDir[i].z) / birdNewDir[i].w, new float[] { numRays, searchArc, sphereCheckRad, targetLayer.value, speed, slerpAmount }); } //Debug.Log(birdNewDir[i]); } } }