Example #1
0
        public void LinearizeDepth(RenderTargetSurface dst, ShaderResource src)
        {
            throw new NotImplementedException();
                #if false
            Debug.Assert(Game.IsServiceExist <Camera>());

            var camera = Game.GetService <Camera>();

            bufLinearizeDepth.Data.linearizeDepthA = 1.0f / camera.FrustumZFar - 1.0f / camera.FrustumZNear;
            bufLinearizeDepth.Data.linearizeDepthB = 1.0f / camera.FrustumZNear;
            bufLinearizeDepth.UpdateCBuffer();


            var isDepthMSAA = (src.SampleCount > 1);
            var depthShader = (int)(isDepthMSAA ? ShaderFlags.RESOLVE_AND_LINEARIZE_DEPTH_MSAA : ShaderFlags.LINEARIZE_DEPTH);

            string signature;

            SetDefaultRenderStates();

            using (new PixEvent()) {
                bufLinearizeDepth.SetCBufferPS(0);

                shaders.SetPixelShader(depthShader);
                shaders.SetVertexShader(depthShader);

                dst.SetViewport();
                device.SetRenderTargets(dst);
                src.SetPS(0);

                device.Draw(Primitive.TriangleList, 3, 0);
            }
            device.ResetStates();
                #endif
        }
Example #2
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);
        }