示例#1
0
        public void Update(Element[] newPositions)
        {
            var rs  = game.GraphicsDevice;
            var map = game.GetService <LayerService>().MapLayer;

            var dbox = rs.DeviceContext.MapSubresource(stagingBuffer, 0, MapMode.Write, MapFlags.None);

            Utilities.Write(dbox.DataPointer, newPositions, 0, newPositions.Length);
            rs.DeviceContext.UnmapSubresource(stagingBuffer, 0);

            rs.DeviceContext.ClearUnorderedAccessView(rwUAV, Int4.Zero);

            rs.DeviceContext.CopyResource(stagingBuffer, dataBuffer);

            cBuffer.Data.LeftBottom   = leftBottomMerc;
            cBuffer.Data.RightTop     = rightTopMerc;
            cBuffer.Data.Offset       = map.Offset;
            cBuffer.Data.Zoom         = map.Zoom;
            cBuffer.Data.AgentsCount  = (uint)Capacity;
            cBuffer.Data.CellStep     = CellStep;
            cBuffer.Data.Width        = Width;
            cBuffer.Data.Height       = Height;
            cBuffer.Data.MaxAgents    = MaxAgents;
            cBuffer.Data.MinAgents    = MinAgents;
            cBuffer.Data.Transparency = Transparency;
            cBuffer.UpdateCBuffer();

            cBuffer.SetCBufferCS(0);

            computeShader.SetComputeShader((int)HeatMapFlags.HM_ADD);

            rs.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, rwUAV);
            rs.DeviceContext.ComputeShader.SetShaderResource(0, dataSRV);

            rs.DeviceContext.Dispatch(Width / 16, Height / 16, 1);

            rs.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null);
            rs.DeviceContext.ComputeShader.SetShaderResource(0, null);
            rs.DeviceContext.ComputeShader.SetConstantBuffer(0, null);


            cBuffer.SetCBufferCS(0);

            computeShader.SetComputeShader((int)HeatMapFlags.HM_DRAW);

            rs.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, finalTextureUAV);
            rs.DeviceContext.ComputeShader.SetShaderResource(0, rwSRV);
            //rs.DeviceContext.ComputeShader.SetShaderResource(1, pallete);
            pallete.SetCS(1);

            rs.DeviceContext.Dispatch(Width / 16, Height / 16, 1);

            rs.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null);
            rs.DeviceContext.ComputeShader.SetShaderResource(0, null);
            rs.DeviceContext.ComputeShader.SetShaderResource(1, null);
            rs.DeviceContext.ComputeShader.SetConstantBuffer(0, null);


            // Guassian Blur
            if (Blur)
            {
                //Horizontal Blur
                computeShader.SetComputeShader((int)HeatMapFlags.HM_GAUS_BLUR | (int)HeatMapFlags.BLUR_HORIZ);

                rs.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, tempUAV);
                rs.DeviceContext.ComputeShader.SetShaderResource(0, FinalSRV);

                rs.DeviceContext.Dispatch(1, Height, 1);

                rs.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null);
                rs.DeviceContext.ComputeShader.SetShaderResource(0, null);

                //Vertical Blur
                computeShader.SetComputeShader((int)HeatMapFlags.HM_GAUS_BLUR | (int)HeatMapFlags.BLUR_VERT);

                rs.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, finalTextureUAV);
                rs.DeviceContext.ComputeShader.SetShaderResource(0, tempSRV);

                rs.DeviceContext.Dispatch(1, Height, 1);

                rs.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null);
                rs.DeviceContext.ComputeShader.SetShaderResource(0, null);

                //////////////////
            }

            //rs.DeviceContext.CopyResource(dataBuffer, readBuffer);
            //
            //var dPointer = rs.DeviceContext.MapSubresource(readBuffer, 0, MapMode.Read, MapFlags.None);
            //
            //Vector2[] vecs = new Vector2[10000];
            //unsafe {
            //	Vector2* p = (Vector2*) dPointer.DataPointer;
            //	for (int i = 0; i < 10000; i++) {
            //		vecs[i] = p[i];
            //	}
            //}
            //
            //rs.DeviceContext.UnmapSubresource(readBuffer, 0);
        }