public void BeginCamera(Camera camera) { m_camera = camera; m_threadGroupsX = Mathf.CeilToInt((float)camera.pixelWidth / THREADS_PER_GROUP); m_threadGroupsY = Mathf.CeilToInt((float)camera.pixelHeight / THREADS_PER_GROUP); m_renderTarget = _renderTargetsRepository.GetRT(camera); m_shapeData.Clear(); m_shapes.GetShapeData(m_shapeData); _buffer = new ComputeBuffer(m_shapeData.Count, ShapeData.GetStructSize()); _buffer.SetData(m_shapeData); }
private void RenderInPlace() { var shapesData = new List <ShapeData>(); _shapes.GetShapeData(shapesData); _computeShader.SetMatrix(CamToWorldMatrixProp, _camera.cameraToWorldMatrix); _computeShader.SetMatrix(InvProjectionMatrixProp, _camera.projectionMatrix.inverse); _computeShader.SetTexture(0, DestinationTextureProp, _renderTexture); if (shapesData.Count > 0) { using (var computeBuffer = new ComputeBuffer(shapesData.Count, ShapeData.GetStructSize())) { int threadGroupsX = Mathf.CeilToInt((float)_camera.pixelWidth / 8); int threadGroupsY = Mathf.CeilToInt((float)_camera.pixelHeight / 8); computeBuffer.SetData(shapesData); _computeShader.SetBuffer(0, BufferProp, computeBuffer); _computeShader.SetInt(BufferLengthProp, computeBuffer.count); _computeShader.Dispatch(0, threadGroupsX, threadGroupsY, 1); } } }