private void Smooth() { var activeLayer = LayerManager.Instance.ActiveLayer; snapshot.SetPositionReal(cursor.transform.position); snapshot.TakeSnapshot(); workBuffer.SetCounterValue(0); var kernel = SmoothShader.FindKernel("PopulateWorkBuffer"); SmoothShader.SetFloat("toolRadius", cursor.Size * 0.8f * (1f / snapshot.transform.localScale.x)); SmoothShader.SetFloat("chunkSize", snapshot.Size); SmoothShader.SetVector("toolCenter", snapshot.transform.InverseTransformPoint(cursor.transform.position) + Vector3.one * snapshot.Size * 0.5f); SmoothShader.SetInt("resolution", snapshot.Resolution); SmoothShader.SetBuffer(populateWorkBufferKernel, "sdf", snapshot.SnapshotSdf); SmoothShader.SetBuffer(populateWorkBufferKernel, "colors", snapshot.SnapshotColors); SmoothShader.SetBuffer(populateWorkBufferKernel, "appendWorkBuffer", workBuffer); SmoothShader.Dispatch(populateWorkBufferKernel, snapshot.Resolution / 8, snapshot.Resolution / 8, snapshot.Resolution / 8); ComputeBuffer.CopyCount(workBuffer, countBuffer, 0); SmoothShader.SetInt("resolution", snapshot.Resolution); SmoothShader.SetBuffer(applyWorkBufferKernel, "entries", countBuffer); SmoothShader.SetBuffer(applyWorkBufferKernel, "sdf", snapshot.SnapshotSdf); SmoothShader.SetBuffer(applyWorkBufferKernel, "colors", snapshot.SnapshotColors); SmoothShader.SetBuffer(applyWorkBufferKernel, "structuredWorkBuffer", workBuffer); SmoothShader.Dispatch(applyWorkBufferKernel, volume / 512, 1, 1); snapshot.ApplySnapshot(); }
private void PopulateWorkBuffer() { snapshot.SetPositionReal(cursor.transform.position); snapshot.TakeSnapshot(); workBuffer.SetCounterValue(0); MoveShader.SetFloat("toolRadius", cursor.Size * (1f / snapshot.transform.localScale.x)); MoveShader.SetVector("toolCenter", snapshot.transform.worldToLocalMatrix.MultiplyPoint(cursor.transform.position) + Vector3.one * snapshot.Size * 0.5f); MoveShader.Dispatch(prepareMoveDataKernel, snapshot.Resolution / 8, snapshot.Resolution / 8, snapshot.Resolution / 8); prevPos = cursor.transform.position; ComputeBuffer.CopyCount(workBuffer, countBuffer, 0); workBufferPopulated = true; }