void Update() { m_FlockShader.SetFloat("_MaxSpeed", m_MaxSpeed); m_FlockShader.SetFloat("_MaxTurnSpeed", m_MaxTurnSpeed); m_FlockShader.SetFloat("_NeighbouringDistance", m_NeighbouringDistance); m_FlockShader.SetFloat("_SeperationDistance", m_SeperationDistance); m_FlockShader.SetVector("_TargetPos", m_Target.position); m_FlockShader.SetInt("_FishCount", m_FishCount); m_FlockShader.SetFloat("_DeltaTime", Time.deltaTime); m_FlockShader.SetBuffer(m_KernelID, "_SourceFish", m_FishBuffers[m_CurrentSourceBuffer]); m_FlockShader.SetBuffer(m_KernelID, "_TargetFish", m_FishBuffers[1 - m_CurrentSourceBuffer]); ComputeThreadGroupHelper helper = new ComputeThreadGroupHelper( m_FlockShader, m_KernelID); int xGroupCount, yGroupCount, zGroupCount; helper.GetGroupCountForElementCount(m_FishCount, 0, 0, out xGroupCount, out yGroupCount, out zGroupCount); m_FlockShader.Dispatch(m_KernelID, xGroupCount, yGroupCount, zGroupCount); m_FishMaterialInstance.SetBuffer("_SourceFish", m_FishBuffers[m_CurrentSourceBuffer]); Graphics.DrawMeshInstancedIndirect(m_FishMesh, 0, m_FishMaterialInstance, new Bounds(transform.position, Vector3.one * 500), m_ArgsBuffer); m_CurrentSourceBuffer = 1 - m_CurrentSourceBuffer; }
/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { m_Shader.SetFloat("_Time", Time.time); int xGroupCount, yGroupCount, zGroupCount; ComputeThreadGroupHelper groupHelper = new ComputeThreadGroupHelper( m_Shader, m_KernelID); groupHelper.GetGroupCountForElementCount(m_Texture.width, m_Texture.height, 0, out xGroupCount, out yGroupCount, out zGroupCount); m_Shader.Dispatch(m_KernelID, xGroupCount, yGroupCount, zGroupCount); }
private void Awake() { InitTexture(); if (m_Shader != null) { m_KernelID = m_Shader.FindKernel("CSMain"); m_Shader.SetTexture(m_KernelID, "Result", m_Texture); int xGroupCount, yGroupCount, zGroupCount; ComputeThreadGroupHelper groupHelper = new ComputeThreadGroupHelper( m_Shader, m_KernelID); groupHelper.GetGroupCountForElementCount(m_Texture.width, m_Texture.height, 0, out xGroupCount, out yGroupCount, out zGroupCount); m_Shader.Dispatch(m_KernelID, xGroupCount, yGroupCount, zGroupCount); } }