Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         paramsCB.Dispose();
         disposeOfBuffers();
         if (factory != null)
         {
             factory.Dispose();
         }
         if (particleTex != null)
         {
             particleTex.Dispose();
         }
         if (renderShader != null)
         {
             renderShader.Dispose();
         }
         if (computeShader != null)
         {
             computeShader.Dispose();
         }
         if (lay != null)
         {
             lay.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Exemplo n.º 2
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            m_Tex_TempDepth3D[3].Dispose();
            m_Tex_TempDepth3D[2].Dispose();
            m_Tex_TempDepth3D[1].Dispose();
            m_Tex_TempDepth3D[0].Dispose();
            m_Tex_TempTarget.Dispose();

            m_Prim_Cube.Dispose();
            m_Prim_Sphere.Dispose();
            m_Prim_Rectangle.Dispose();
            m_Prim_Quad.Dispose();

            m_CB_DistanceField.Dispose();
            m_CB_Object.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Main.Dispose();

            m_Shader_PostProcess.Dispose();
            m_Shader_SplatDepthStencil[2].Dispose();
            m_Shader_SplatDepthStencil[1].Dispose();
            m_Shader_SplatDepthStencil[0].Dispose();
            m_Shader_RenderScene.Dispose();

            m_Device.Dispose();
            m_Device = null;
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     VertexShader.Dispose();
     PixelShader.Dispose();
     InputLayout.Dispose();
     ConstantBuffer.Dispose();
 }
Exemplo n.º 4
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && components != null)
            {
                components.Dispose();
            }

            m_primitiveCube.Dispose();

            m_shader_displayCube.Dispose();

            m_CB_main.Dispose();
            m_CB_camera.Dispose();

            m_device.Dispose();

            // Forms disposal
            m_notificationForm.Dispose();
            m_preferenceForm.Dispose();
            m_ficheWebPageEditorForm.Dispose();
            m_ficheWebPageAnnotatorForm.Dispose();
            WebServices.HTMLPageRenderer.ExitChromium();

            base.Dispose(disposing);
        }
Exemplo n.º 5
0
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (m_Device == null)
            {
                return;
            }

            m_CB_PostProcess.Dispose();
            m_CB_Downsample.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Main.Dispose();

            m_Tex_DownsampledDepth.Dispose();
            m_Tex_LinearDepth.Dispose();

            m_Tex_TempBuffer2.Dispose();
            m_Tex_TempBuffer.Dispose();

            if (m_Shader != null)
            {
                m_Shader_Glass.Dispose();
                m_Shader.Dispose();
                m_ShaderPostProcess.Dispose();
//				m_ShaderDownsample.Dispose();
                m_ShaderDownsampleCS.Dispose();
                m_ShaderLinearizeDepthCS.Dispose();
            }
            m_Prim_Quad.Dispose();

            m_Device.Exit();

            base.OnFormClosed(e);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();

                m_tex_FalseColors1.Dispose();
                m_tex_FalseColors0.Dispose();

                m_tex_Search_Staging.Dispose();
                m_tex_Search.Dispose();
                m_tex_Obstacles_Staging.Dispose();
                m_tex_Obstacles1.Dispose();
                m_tex_Obstacles0.Dispose();
                m_tex_HeatMap1.Dispose();
                m_tex_HeatMap0.Dispose();
                m_tex_HeatMap_Staging.Dispose();
                m_shader_DrawObstacles.Dispose();
                m_shader_HeatDiffusion1.Dispose();
                m_shader_HeatDiffusion0.Dispose();
                m_shader_RenderHeatMap.Dispose();
                m_CB_Main.Dispose();

                Device temp = m_device;
                m_device = null;
                temp.Dispose();
            }
            base.Dispose(disposing);
        }
Exemplo n.º 7
0
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (m_Device == null)
            {
                return;
            }

            if (m_Shader_Render != null)
            {
                m_Shader_Render.Dispose();
            }

            m_CB_Main.Dispose();

            if (m_Tex_CubeMap != null)
            {
                m_Tex_CubeMap.Dispose();
            }
            if (m_SB_Samples != null)
            {
                m_SB_Samples.Dispose();
            }
            if (m_SB_EmissiveSurfaces != null)
            {
                m_SB_EmissiveSurfaces.Dispose();
            }

            m_Device.Exit();

            base.OnFormClosed(e);
        }
Exemplo n.º 8
0
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            m_tex_Noise4D.Dispose();
            m_tex_Noise.Dispose();
            m_tex_BlueNoise.Dispose();

                        #if TEST_LTC_AREA_LIGHT
            m_tex_MS_LTC.Dispose();
            m_tex_LTC.Dispose();
                        #endif

            m_tex_MSBRDF_Eavg.Dispose();
            m_tex_MSBRDF_E.Dispose();

            m_tex_CubeMap.Dispose();

            m_tex_Accumulator.Dispose();

            m_CB_SH.Dispose();
            m_CB_Render.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Global.Dispose();

            m_shader_Accumulate.Dispose();
            m_shader_Finalize.Dispose();

            m_device.Exit();

            base.OnFormClosed(e);
        }
Exemplo n.º 9
0
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (m_Device == null)
            {
                return;
            }

            m_SB_Points2D.Dispose();
            m_SB_Points4D[0].Dispose();
            m_SB_Points4D[1].Dispose();
            m_SB_Velocities4D.Dispose();

            m_CB_Simulation.Dispose();
            m_CB_Camera4D.Dispose();
            m_CB_Camera.Dispose();

            m_PrimQuad.Dispose();

            m_PS_Display.Dispose();
            m_CS_Project4D.Dispose();
            m_CS_Simulator.Dispose();

            m_Device.Exit();

            base.OnFormClosed(e);
        }
Exemplo n.º 10
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            m_Tex_DistanceField[1].Dispose();
            m_Tex_DistanceField[0].Dispose();
            m_Tex_SplatDepthStencil[0].Dispose();
            m_Tex_SplatDepthStencil[1].Dispose();
            m_Tex_TempDepthAccumulatorBA.Dispose();
            m_Tex_TempDepthAccumulatorRG.Dispose();
            m_Tex_TempTarget.Dispose();

            m_Prim_Cube.Dispose();
            m_Prim_Sphere.Dispose();
            m_Prim_Rectangle.Dispose();
            m_Prim_Quad.Dispose();

            m_CB_Object.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Main.Dispose();

            m_Shader_BuildDistanceField[2].Dispose();
            m_Shader_BuildDistanceField[1].Dispose();
            m_Shader_BuildDistanceField[0].Dispose();
            m_Shader_PostProcess.Dispose();
            m_Shader_FinalizeSplat.Dispose();
            m_Shader_SplatDepthStencil.Dispose();
            m_Shader_ClearAccumulator.Dispose();
            m_Shader_RenderScene.Dispose();

            m_Device.Dispose();
            m_Device = null;
        }
Exemplo n.º 11
0
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            m_tex_MS_LTC.Dispose();
            m_tex_LTC.Dispose();

            m_tex_MSBRDF_Eavg.Dispose();
            m_tex_MSBRDF_E.Dispose();

            m_RT_temp0.Dispose();
            m_RT_temp1.Dispose();
            m_tex_FalseColors.Dispose();

            m_shader_RenderLight.Dispose();
            m_shader_RenderScene.Dispose();
            m_shader_RenderScene_Reference.Dispose();
            m_shader_RenderDiff.Dispose();
            m_shader_RenderTestQuad.Dispose();

            m_CB_Main.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Light.Dispose();
            m_CB_TestQuad.Dispose();

            m_prim_disk.Dispose();

            m_device.Exit();

            base.OnFormClosed(e);
        }
Exemplo n.º 12
0
 public void Dispose()
 {
     s_vb0.Dispose();
     s_vb1.Dispose();
     s_ib.Dispose();
     s_material.Dispose();
     _modelViewBuffer.Dispose();
 }
Exemplo n.º 13
0
 public void Dispose()
 {
     _vertexBuffer.Dispose();
     _indexBuffer.Dispose();
     _material.Dispose();
     _worldBuffer.Dispose();
     _inverseTransposeWorldBuffer.Dispose();
 }
 public void Dispose()
 {
     m_CS__Generic.Dispose();
     m_CS__1to16.Dispose();
     m_texBufferCPU.Dispose();
     m_texBufferOut.Dispose();
     m_texBufferIn.Dispose();
     m_CB.Dispose();
 }
Exemplo n.º 15
0
 public void Dispose()
 {
     _vb.Dispose();
     _ib.Dispose();
     _material.Dispose();
     _worldBuffer.Dispose();
     _inverseTransposeWorldBuffer.Dispose();
     s_wireframeRasterizerState.Dispose();
 }
Exemplo n.º 16
0
 /// <summary>
 /// Dispose
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         vertexBuffer.Dispose();
         constBuffer.Dispose();
     }
     base.Dispose(disposing);
 }
Exemplo n.º 17
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            m_Shader_RenderMesh.Dispose();
            m_Prim_Sphere.Dispose();
            m_CB_Mesh.Dispose();
            m_CB_Camera.Dispose();
            m_Device.Dispose();

            base.OnFormClosing(e);
        }
Exemplo n.º 18
0
 public override void DestroyDeviceObjects()
 {
     _shaderSet.Dispose();
     _cubemapTexture.Dispose();
     _cubemapBinding.Dispose();
     _vb.Dispose();
     _ib.Dispose();
     _viewMatrixBuffer.Dispose();
     _rasterizerState.Dispose();
 }
Exemplo n.º 19
0
        public virtual void Dispose()
        {
            if (ConstBuffer != null)
            {
                ConstBuffer.Dispose();
            }

            if (Meshes != null)
            {
                Meshes.Dispose();
            }
        }
Exemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                paramsCB.Dispose();

                simulationBufferSrc.Dispose();
                linksBuffer.Dispose();
                linksPtrBuffer.Dispose();
            }
            base.Dispose(disposing);
        }
 public void Dispose()
 {
     if (m_CS__Remainder != null)
     {
         m_CS__Remainder.Dispose();
     }
     m_CS__1to256.Dispose();
     m_texBufferCPU.Dispose();
     m_texBufferOut.Dispose();
     m_texBufferIn.Dispose();
     m_CB.Dispose();
 }
Exemplo n.º 22
0
 /// <summary>
 /// Called on program close.
 /// Disposes of variables taking up resources.
 /// </summary>
 public void Dispose()
 {
     swapChain.Dispose();
     device.Dispose();
     deviceContext.Dispose();
     renderForm.Dispose();
     raymarchShaderBuffer.Dispose();
     noiseTextureBuffer.Dispose();
     foreach (var buffer in primitivesBuffer)
     {
         buffer.Dispose();
     }
 }
Exemplo n.º 23
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            m_closing = true;
            if (m_Device == null)
            {
                return;
            }

                        #if DEBUG
            if (m_Shader_ToneMapping != null)
            {
                m_Shader_ToneMapping.Dispose();
            }
            if (m_Shader_ComputeAutoExposure != null)
            {
                m_Shader_ComputeAutoExposure.Dispose();
            }
            if (m_Shader_FinalizeHistogram != null)
            {
                m_Shader_FinalizeHistogram.Dispose();
            }
            if (m_Shader_ComputeTallHistogram != null)
            {
                m_Shader_ComputeTallHistogram.Dispose();
            }
            if (m_Shader_RenderHDR != null)
            {
                m_Shader_RenderHDR.Dispose();
            }

            m_Buffer_AutoExposureTarget.Dispose();
            m_Buffer_AutoExposureSource.Dispose();
            m_Tex_Histogram.Dispose();
            m_Tex_TallHistogram.Dispose();
            m_Tex_HDR.Dispose();
            if (m_Tex_CubeMap != null)
            {
                m_Tex_CubeMap.Dispose();
            }

            m_CB_AutoExposure.Dispose();
            m_CB_ToneMapping.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Main.Dispose();

            m_Device.Exit();
            m_Device = null;
                        #endif

            base.OnFormClosing(e);
        }
Exemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SafeDispose(ref factory);

                paramsCB.Dispose();

                injectionVB.Dispose();
                simulationSrcVB.Dispose();
                simulationDstVB.Dispose();
            }
            base.Dispose(disposing);
        }
Exemplo n.º 25
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            e.Cancel = false;
            base.OnFormClosing(e);

            m_CB_Camera.Dispose();
            m_shader_renderCube.Dispose();
            m_prim_cube.Dispose();

            Device temp = m_device;

            m_device = null;
            temp.Dispose();
        }
Exemplo n.º 26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SafeDispose(ref factory);

                paramsCB.Dispose();

                injectionBuffer.Dispose();
                simulationBufferSrc.Dispose();
                simulationBufferDst.Dispose();
            }
            base.Dispose(disposing);
        }
Exemplo n.º 27
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         paramsCB.Dispose();
         disposeOfBuffers();
         if (factory != null)
         {
             factory.Dispose();
         }
         if (shader != null)
         {
             shader.Dispose();
         }
     }
 }
Exemplo n.º 28
0
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (m_Device == null)
            {
                return;
            }

            m_Prim_Cube.Dispose();
            m_Prim_Sphere.Dispose();
            m_Prim_Quad.Dispose();

            m_SB_Photons[1].Dispose();
            m_SB_Photons[0].Dispose();
            m_SB_PhotonInfos.Dispose();

            m_Tex_Noise4D.Dispose();
            m_Tex_Noise.Dispose();
            m_Tex_AccumPhoton3D.Dispose();
            m_Tex_AccumPhotonCube.Dispose();
            m_Tex_VolumeDensity.Dispose();
            m_Tex_Scattering.Dispose();
            m_Tex_HeightMap.Dispose();
            m_Tex_TempBackBuffer.Dispose();

            m_CB_PostProcess.Dispose();
            m_CB_RayMarch.Dispose();
            m_CB_RenderSphere.Dispose();
            m_CB_RenderRoom.Dispose();
            m_CB_TracePhotons.Dispose();
            m_CB_GenerateDensity.Dispose();
            m_CB_Camera.Dispose();
            m_CB_Global.Dispose();

            m_Shader_PostProcess.Dispose();
            m_Shader_RenderSphere.Dispose();
            m_Shader_RenderRoom.Dispose();
            m_Shader_RayMarcher.Dispose();
            m_Shader_TracePhotons.Dispose();
            m_Shader_InitPhotons.Dispose();
            m_Shader_ClearAccumulator.Dispose();
            m_shader_GenerateDensity.Dispose();
            m_Shader_UpdateHeightMap.Dispose();

            m_Device.Exit();

            base.OnFormClosed(e);
        }
Exemplo n.º 29
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            Device device = m_device;

            m_device = null;

            m_octree.Dispose();

            m_CB_Main.Dispose();
            m_CB_camera.Dispose();

            m_shader_RenderDistanceField.Dispose();

            device.Dispose();
        }
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            Device D = m_device;

            m_device = null;

            m_Prim_Cube.Dispose();

            m_CB_Camera.Dispose();
            m_CB_Main.Dispose();

            m_Shader_renderScene.Dispose();

            D.Dispose();
        }
Exemplo n.º 31
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect Camera Joint sample");

            RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
            RenderContext context = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            DX11DepthStencil depthStencil = new DX11DepthStencil(device, swapChain.Width, swapChain.Height, eDepthFormat.d24s8);

            //VertexShader vertexShader = ShaderCompiler.CompileFromFile<VertexShader>(device, "ColorJointView.fx", "VS");
            SharpDX.D3DCompiler.ShaderSignature signature;
            VertexShader vertexShader = ShaderCompiler.CompileFromFile(device, "CameraJointView.fx", "VS_Color", out signature);
            PixelShader pixelShader = ShaderCompiler.CompileFromFile<PixelShader>(device, "CameraJointView.fx", "PS_Color");

            VertexShader vertexShaderLine = ShaderCompiler.CompileFromFile<VertexShader>(device, "CameraJointView.fx", "VS");
            PixelShader pixelShaderLine = ShaderCompiler.CompileFromFile<PixelShader>(device, "CameraJointView.fx", "PS_White");

            JointTableIndexBuffer indexBuffer = new JointTableIndexBuffer(device, 6);

            DX11IndexedGeometry cube = device.Primitives.Box(new Box()
            {
                Size = new Vector3(0.05f)
            });
            DX11InstancedIndexedDrawer drawer = new DX11InstancedIndexedDrawer();
            cube.AssignDrawer(drawer);

            InputLayout layout;
            var bc = new ShaderBytecode(signature);
            cube.ValidateLayout(bc, out layout);

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            Color4[] statusColor = new Color4[]
            {
                Color.Red,
                Color.Yellow,
                Color.Green
            };

            cbCamera camera = new cbCamera();
            camera.Projection = Matrix.PerspectiveFovLH(1.57f, 1.3f, 0.1f, 100.0f);
            camera.View = Matrix.Translation(0.0f, 0.0f, 2.0f);

            camera.Projection.Transpose();
            camera.View.Transpose();

            ConstantBuffer<cbCamera> cameraBuffer = new ConstantBuffer<cbCamera>(device);
            cameraBuffer.Update(context, ref camera);

            DX11StructuredBuffer colorTableBuffer = DX11StructuredBuffer.CreateImmutable<Color4>(device, statusColor);

            bool doQuit = false;
            bool doUpload = false;

            int bodyCount = 0;
            KinectBody[] bodyFrame = null;
            BodyCameraPositionBuffer positionBuffer = new BodyCameraPositionBuffer(device);
            BodyJointStatusBuffer statusBuffer = new BodyJointStatusBuffer(device);

            KinectSensorBodyFrameProvider provider = new KinectSensorBodyFrameProvider(sensor);
            provider.FrameReceived += (sender, args) => { bodyFrame = args.FrameData; doUpload = true; };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            context.Context.OutputMerger.DepthStencilState = device.DepthStencilStates.LessReadWrite;
            context.Context.Rasterizer.State = device.RasterizerStates.BackCullSolid;

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (doUpload)
                {
                    var tracked = bodyFrame.TrackedOnly();
                    bodyCount = tracked.Count();

                    positionBuffer.Copy(context, tracked);
                    statusBuffer.Copy(context, tracked);
                    drawer.InstanceCount = tracked.Count() * Microsoft.Kinect.Body.JointCount;
                }

                context.RenderTargetStack.Push(depthStencil, false,swapChain);
                context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black);
                depthStencil.Clear(context);

                /*Position buffer and cbuffers are the same data and in same slot,
                 * so we bind them only once*/
                context.Context.VertexShader.SetShaderResource(0, positionBuffer.ShaderView);
                context.Context.VertexShader.SetConstantBuffer(0, cameraBuffer.Buffer);

                //Draw lines
                context.Context.PixelShader.Set(pixelShaderLine);
                context.Context.VertexShader.Set(vertexShaderLine);

                //Attach index buffer, null topology since we fetch
                indexBuffer.AttachWithLayout(context);
                indexBuffer.Draw(context,bodyCount);

                //Draw cubes
                cube.Bind(context, layout);
                context.Context.VertexShader.Set(vertexShader);
                context.Context.PixelShader.Set(pixelShader);

                context.Context.VertexShader.SetShaderResource(1, statusBuffer.ShaderView);
                context.Context.VertexShader.SetShaderResource(2, colorTableBuffer.ShaderView);

                cube.Draw(context);

                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            depthStencil.Dispose();
            context.Dispose();
            device.Dispose();

            positionBuffer.Dispose();
            statusBuffer.Dispose();
            colorTableBuffer.Dispose();

            cameraBuffer.Dispose();

            provider.Dispose();
            cube.Dispose();
            layout.Dispose();

            pixelShader.Dispose();
            vertexShader.Dispose();

            pixelShaderLine.Dispose();
            vertexShaderLine.Dispose();
            indexBuffer.Dispose();

            sensor.Close();
        }
Exemplo n.º 32
0
        private void GenerateHeightMaps()
        {
            ShaderBytecode shaderByteCode = ShaderBytecode.CompileFromFile(@"Data/Shaders/TerrainCompute.hlsl", "initTerrain", "cs_5_0", Shader.ShaderFlags);
            ComputeShader initTerrain = new ComputeShader(_context.DirectX.Device, shaderByteCode);
            shaderByteCode.Dispose();
            shaderByteCode = ShaderBytecode.CompileFromFile(@"Data/Shaders/TerrainCompute.hlsl", "initWater", "cs_5_0", Shader.ShaderFlags);
            ComputeShader initWater = new ComputeShader(_context.DirectX.Device, shaderByteCode);
            shaderByteCode.Dispose();
            shaderByteCode = ShaderBytecode.CompileFromFile(@"Data/Shaders/TerrainCompute.hlsl", "applyRandomDisplacement", "cs_5_0", Shader.ShaderFlags);
            _baseTerrainGeneration = new ComputeShader(_context.DirectX.Device, shaderByteCode);
            shaderByteCode.Dispose();
            shaderByteCode = ShaderBytecode.CompileFromFile(@"Data/Shaders/TerrainCompute.hlsl", "flowsCalculation", "cs_5_0", Shader.ShaderFlags);
            _flowsCalculation = new ComputeShader(_context.DirectX.Device, shaderByteCode);
            shaderByteCode.Dispose();
            shaderByteCode = ShaderBytecode.CompileFromFile(@"Data/Shaders/TerrainCompute.hlsl", "updateWaterLevel", "cs_5_0", Shader.ShaderFlags);
            _updateWaterLevel = new ComputeShader(_context.DirectX.Device, shaderByteCode);
            shaderByteCode.Dispose();

            Texture2DDescription textureDescription = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R32_Float,
                Height = TextureSize,
                Width = TextureSize,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            ConstantBuffer<ComputeData> computeBuffer = new ConstantBuffer<ComputeData>(_context);
            _context.DirectX.DeviceContext.ComputeShader.SetConstantBuffer(1, computeBuffer.Buffer);

            foreach (Face face in _faces)
            {
                Texture2D terrainTexture = new Texture2D(_context.DirectX.Device, textureDescription);
                face.TerrainSrv = new ShaderResourceView(_context.DirectX.Device, terrainTexture);
                face.TerrainUav = new UnorderedAccessView(_context.DirectX.Device, terrainTexture);
                terrainTexture.Dispose();

                Texture2D waterTexture = new Texture2D(_context.DirectX.Device, textureDescription);
                face.WaterSrv = new ShaderResourceView(_context.DirectX.Device, waterTexture);
                face.WaterUav = new UnorderedAccessView(_context.DirectX.Device, waterTexture);
                waterTexture.Dispose();

                Texture2D flowsTexture = new Texture2D(_context.DirectX.Device, textureDescription);
                face.FlowsLeftUav = new UnorderedAccessView(_context.DirectX.Device, flowsTexture);
                flowsTexture.Dispose();

                flowsTexture = new Texture2D(_context.DirectX.Device, textureDescription);
                face.FlowsTopUav = new UnorderedAccessView(_context.DirectX.Device, flowsTexture);
                flowsTexture.Dispose();

                flowsTexture = new Texture2D(_context.DirectX.Device, textureDescription);
                face.FlowsRightUav = new UnorderedAccessView(_context.DirectX.Device, flowsTexture);
                flowsTexture.Dispose();

                flowsTexture = new Texture2D(_context.DirectX.Device, textureDescription);
                face.FlowsBottomUav = new UnorderedAccessView(_context.DirectX.Device, flowsTexture);
                flowsTexture.Dispose();

                _context.DirectX.DeviceContext.ComputeShader.SetUnorderedAccessView(0, face.TerrainUav);
                _context.DirectX.DeviceContext.ComputeShader.SetUnorderedAccessView(1, face.WaterUav);

                _context.DirectX.DeviceContext.ComputeShader.Set(initTerrain);
                computeBuffer.Update(new ComputeData(TextureSize - 1 - BatchSize, 0, 0, 0.0f));
                _context.DirectX.DeviceContext.Dispatch(TextureSize / BatchSize, TextureSize / BatchSize, 1);

                _context.DirectX.DeviceContext.ComputeShader.Set(initWater);
                computeBuffer.Update(new ComputeData(TextureSize - 1 - BatchSize, 0, 0, 0.05f));
                _context.DirectX.DeviceContext.Dispatch(TextureSize / BatchSize, TextureSize / BatchSize, 1);

                _context.DirectX.DeviceContext.ComputeShader.Set(initTerrain);
                computeBuffer.Update(new ComputeData(TextureSize - 1 - BatchSize, BatchSize / 2, BatchSize / 2, 0.5f));
                _context.DirectX.DeviceContext.Dispatch(TextureSize / BatchSize - 1, TextureSize / BatchSize - 1, 1);
            }

             _planeBuffer = new ConstantBuffer<PlaneData>(_context);

            initTerrain.Dispose();
            computeBuffer.Dispose();
        }
Exemplo n.º 33
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect Simple point cloud view sample");

            RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
            RenderContext context = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            VertexShader vertexShader = ShaderCompiler.CompileFromFile<VertexShader>(device, "ColoredPointCloudView.fx", "VS");
            PixelShader pixelShader = ShaderCompiler.CompileFromFile<PixelShader>(device, "ColoredPointCloudView.fx", "PS");

            DX11NullInstancedDrawer nulldrawer = new DX11NullInstancedDrawer();
            nulldrawer.VertexCount = Consts.DepthWidth;
            nulldrawer.InstanceCount = Consts.DepthHeight;
            DX11NullGeometry nullGeom = new DX11NullGeometry(device, nulldrawer);
            nullGeom.Topology = SharpDX.Direct3D.PrimitiveTopology.PointList;

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            cbCamera camera = new cbCamera();
            camera.Projection = Matrix.PerspectiveFovLH(1.57f * 0.5f, 1.3f, 0.01f, 100.0f);
            camera.View = Matrix.Translation(0.0f, 0.0f, 2.0f);

            camera.Projection.Transpose();
            camera.View.Transpose();

            ConstantBuffer<cbCamera> cameraBuffer = new ConstantBuffer<cbCamera>(device);
            cameraBuffer.Update(context, ref camera);

            bool doQuit = false;
            bool uploadCamera = false;
            bool uploadRgb = false;

            CameraRGBFrameData cameraFrame = new CameraRGBFrameData();
            DynamicCameraRGBTexture cameraTexture = new DynamicCameraRGBTexture(device);

            DepthToColorFrameData depthToColorFrame = new DepthToColorFrameData();
            DynamicDepthToColorTexture depthToColorTexture = new DynamicDepthToColorTexture(device);

            KinectSensorDepthFrameProvider provider = new KinectSensorDepthFrameProvider(sensor);
            provider.FrameReceived += (sender, args) => { cameraFrame.Update(sensor.CoordinateMapper, args.DepthData); depthToColorFrame.Update(sensor.CoordinateMapper, args.DepthData); uploadCamera = true; };

            //Get coordinate map + rgb
            ColorRGBAFrameData colorFrame = new ColorRGBAFrameData();
            DynamicColorRGBATexture colorTexture = new DynamicColorRGBATexture(device);
            KinectSensorColorRGBAFrameProvider colorProvider = new KinectSensorColorRGBAFrameProvider(sensor);
            colorProvider.FrameReceived += (sender, args) => { colorFrame = args.FrameData; uploadRgb = true; };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (uploadCamera)
                {
                    cameraTexture.Copy(context.Context, cameraFrame);
                    depthToColorTexture.Copy(context.Context, depthToColorFrame);
                    uploadCamera = false;
                }

                if (uploadRgb)
                {
                    colorTexture.Copy(context.Context, colorFrame);
                    uploadRgb = false;
                }

                context.RenderTargetStack.Push(swapChain);
                context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black);

                context.Context.VertexShader.Set(vertexShader);
                context.Context.PixelShader.Set(pixelShader);

                context.Context.VertexShader.SetShaderResource(0, cameraTexture.ShaderView);
                context.Context.VertexShader.SetShaderResource(1, colorTexture.ShaderView);
                context.Context.VertexShader.SetShaderResource(2, depthToColorTexture.ShaderView);

                context.Context.VertexShader.SetSampler(0, device.SamplerStates.LinearClamp);

                context.Context.VertexShader.SetConstantBuffer(0, cameraBuffer.Buffer);

                nullGeom.Bind(context, null);
                nullGeom.Draw(context);

                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            cameraBuffer.Dispose();
            cameraTexture.Dispose();

            provider.Dispose();

            pixelShader.Dispose();
            vertexShader.Dispose();
            sensor.Close();

            colorTexture.Dispose();
            colorProvider.Dispose();

            depthToColorFrame.Dispose();
            depthToColorTexture.Dispose();
        }
Exemplo n.º 34
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect Simple hd face sample");

            RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
            RenderContext context = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            VertexShader vertexShader = ShaderCompiler.CompileFromFile <VertexShader>(device, "HdFaceView.fx", "VS");
            PixelShader pixelShader = ShaderCompiler.CompileFromFile<PixelShader>(device, "HdFaceView.fx", "PS");

            HdFaceIndexBuffer faceIndexBuffer = new HdFaceIndexBuffer(device, 1);
            DynamicHdFaceStructuredBuffer faceVertexBuffer = new DynamicHdFaceStructuredBuffer(device, 1);

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            cbCamera camera = new cbCamera();
            camera.Projection = Matrix.PerspectiveFovLH(1.57f*0.5f, 1.3f, 0.01f, 100.0f);
            camera.View = Matrix.Translation(0.0f, 0.0f, 0.5f);

            camera.Projection.Transpose();
            camera.View.Transpose();

            ConstantBuffer<cbCamera> cameraBuffer = new ConstantBuffer<cbCamera>(device);
            cameraBuffer.Update(context, ref camera);

            bool doQuit = false;
            bool doUpload = false;

            KinectBody[] bodyFrame = null;
            KinectSensorBodyFrameProvider provider = new KinectSensorBodyFrameProvider(sensor);

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            FaceModel currentFaceModel = new FaceModel();
            FaceAlignment currentFaceAlignment = new FaceAlignment();

            SingleHdFaceProcessor hdFaceProcessor = new SingleHdFaceProcessor(sensor);
            hdFaceProcessor.HdFrameReceived += (sender, args) => { currentFaceModel = args.FaceModel; currentFaceAlignment = args.FaceAlignment; doUpload = true; };

            provider.FrameReceived += (sender, args) =>
            {
                bodyFrame = args.FrameData;
                var body = bodyFrame.TrackedOnly().ClosestBodies().FirstOrDefault();
                if (body != null)
                {
                    hdFaceProcessor.AssignBody(body);
                }
                else
                {
                    hdFaceProcessor.Suspend();
                }
            };

            context.Context.Rasterizer.State = device.RasterizerStates.WireFrame;

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (doUpload)
                {
                    var vertices = currentFaceModel.CalculateVerticesForAlignment(currentFaceAlignment).ToArray();
                    faceVertexBuffer.Copy(context, vertices);
                    doUpload = false;
                }

                context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black);

                if (hdFaceProcessor.IsValid)
                {
                    context.RenderTargetStack.Push(swapChain);
                    context.Context.VertexShader.SetShaderResource(0, faceVertexBuffer.ShaderView);
                    context.Context.VertexShader.SetConstantBuffer(0, cameraBuffer.Buffer);

                    //Draw lines
                    context.Context.PixelShader.Set(pixelShader);
                    context.Context.VertexShader.Set(vertexShader);

                    //Attach index buffer, null topology since we fetch
                    faceIndexBuffer.AttachWithLayout(context);
                    faceIndexBuffer.Draw(context, 1);
                    context.RenderTargetStack.Pop();
                }

                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            cameraBuffer.Dispose();
            faceIndexBuffer.Dispose();
            faceVertexBuffer.Dispose();

            provider.Dispose();
            pixelShader.Dispose();
            vertexShader.Dispose();

            hdFaceProcessor.Dispose();
            sensor.Close();
        }
Exemplo n.º 35
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect Simple filtered point cloud view sample");

            RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
            RenderContext context = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            ComputeShader computeShader = ShaderCompiler.CompileFromFile<ComputeShader>(device, "PointCloudFilter.fx", "CS_Filter");

            VertexShader vertexShader = ShaderCompiler.CompileFromFile<VertexShader>(device, "PointCloudJointView.fx", "VS");
            PixelShader pixelShader = ShaderCompiler.CompileFromFile<PixelShader>(device, "PointCloudJointView.fx", "PS");

            BodyCameraPositionBuffer positionBuffer = new BodyCameraPositionBuffer(device);
            DX11StructuredBuffer colorTableBuffer = DX11StructuredBuffer.CreateImmutable<Color4>(device, ColorTable);

            DX11NullGeometry nullGeom = new DX11NullGeometry(device);
            nullGeom.Topology = SharpDX.Direct3D.PrimitiveTopology.PointList;
            InstancedIndirectBuffer indirectDrawBuffer = new InstancedIndirectBuffer(device);

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            cbCamera camera = new cbCamera();
            camera.Projection = Matrix.PerspectiveFovLH(1.57f * 0.5f, 1.3f, 0.01f, 100.0f);
            camera.View = Matrix.Translation(0.0f, 0.0f, 2.0f);

            camera.Projection.Transpose();
            camera.View.Transpose();

            ConstantBuffer<cbCamera> cameraBuffer = new ConstantBuffer<cbCamera>(device);
            cameraBuffer.Update(context, ref camera);

            bool doQuit = false;
            bool uploadCamera = false;
            bool uploadBodyIndex = false;
            bool uploadBody = false;

            CameraRGBFrameData rgbFrame = new CameraRGBFrameData();
            DynamicCameraRGBTexture cameraTexture = new DynamicCameraRGBTexture(device);

            KinectSensorDepthFrameProvider provider = new KinectSensorDepthFrameProvider(sensor);
            provider.FrameReceived += (sender, args) => { rgbFrame.Update(sensor.CoordinateMapper, args.DepthData); uploadCamera = true; };

            BodyIndexFrameData bodyIndexFrame = null;
            DynamicBodyIndexTexture bodyIndexTexture = new DynamicBodyIndexTexture(device);
            KinectSensorBodyIndexFrameProvider bodyIndexProvider = new KinectSensorBodyIndexFrameProvider(sensor);
            bodyIndexProvider.FrameReceived += (sender, args) => { bodyIndexFrame = args.FrameData; uploadBodyIndex = true; };

            AppendPointCloudBuffer pointCloudBuffer = new AppendPointCloudBuffer(device);

            KinectBody[] bodyFrame = null;
            KinectSensorBodyFrameProvider bodyFrameProvider = new KinectSensorBodyFrameProvider(sensor);
            bodyFrameProvider.FrameReceived += (sender, args) => { bodyFrame = args.FrameData; uploadBody = true; };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (uploadCamera)
                {
                    cameraTexture.Copy(context.Context, rgbFrame);
                    uploadCamera = false;
                }

                if (uploadBodyIndex)
                {
                    bodyIndexTexture.Copy(context.Context, bodyIndexFrame);
                    uploadBodyIndex = false;
                }

                if (uploadBody)
                {
                    positionBuffer.Copy(context, bodyFrame.TrackedOnly().ClosestBodies());
                    uploadBody = false;
                }

                //Prepare compute shader
                context.Context.ComputeShader.Set(computeShader);
                context.Context.ComputeShader.SetShaderResource(0, cameraTexture.ShaderView);
                context.Context.ComputeShader.SetShaderResource(1, bodyIndexTexture.RawView); //Set raw view here, we do not sample

                context.Context.ComputeShader.SetUnorderedAccessView(0, pointCloudBuffer.UnorderedView, 0); //Don't forget to set count to 0

                context.Context.Dispatch(Consts.DepthWidth / 8, Consts.DepthHeight / 8, 1); //No iDivUp here, since it's not needed
                context.Context.ComputeShader.SetUnorderedAccessView(0, null); //Make runtime happy, and if we don't unbind we can't set as srv
                context.Context.CopyStructureCount(indirectDrawBuffer.ArgumentBuffer, 0, pointCloudBuffer.UnorderedView);

                //Draw filter buffer
                context.RenderTargetStack.Push(swapChain);
                context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black);

                context.Context.VertexShader.Set(vertexShader);
                context.Context.PixelShader.Set(pixelShader);

                context.Context.VertexShader.SetShaderResource(0, pointCloudBuffer.ShaderView);
                context.Context.VertexShader.SetShaderResource(1, positionBuffer.ShaderView);
                context.Context.VertexShader.SetShaderResource(2, colorTableBuffer.ShaderView);
                context.Context.VertexShader.SetConstantBuffer(0, cameraBuffer.Buffer);

                nullGeom.Bind(context, null);
                context.Context.DrawInstancedIndirect(indirectDrawBuffer.ArgumentBuffer, 0);

                context.Context.VertexShader.SetShaderResource(0, null); //Make runtime happy

                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            cameraBuffer.Dispose();
            cameraTexture.Dispose();
            bodyIndexTexture.Dispose();

            provider.Dispose();
            bodyIndexProvider.Dispose();

            pixelShader.Dispose();
            vertexShader.Dispose();
            sensor.Close();

            positionBuffer.Dispose();
            colorTableBuffer.Dispose();

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();
        }
Exemplo n.º 36
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect RGB Joint sample");

            RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
            RenderContext context = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            //VertexShader vertexShader = ShaderCompiler.CompileFromFile<VertexShader>(device, "ColorJointView.fx", "VS");
            SharpDX.D3DCompiler.ShaderSignature signature;
            VertexShader vertexShader = ShaderCompiler.CompileFromFile(device, "ColorJointView.fx", "VS_Color", out signature);
            PixelShader pixelShader = ShaderCompiler.CompileFromFile<PixelShader>(device, "ColorJointView.fx", "PS_Color");

            DX11IndexedGeometry circle = device.Primitives.Segment(new Segment()
            {
                Resolution = 32
            });
            DX11InstancedIndexedDrawer drawer = new DX11InstancedIndexedDrawer();
            circle.AssignDrawer(drawer);

            InputLayout layout;
            var bc = new ShaderBytecode(signature);
            circle.ValidateLayout(bc, out layout);

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            Color4[] statusColor = new Color4[]
            {
                Color.Red,
                Color.Yellow,
                Color.Green
            };

            //Note cbuffer should have a minimum size of 16 bytes, so we create verctor4 instead of vector2
            SharpDX.Vector4 jointSize = new SharpDX.Vector4(0.04f,0.07f,0.0f,1.0f);
            ConstantBuffer<SharpDX.Vector4> cbSize = new ConstantBuffer<SharpDX.Vector4>(device);
            cbSize.Update(context, ref jointSize);

            DX11StructuredBuffer colorTableBuffer = DX11StructuredBuffer.CreateImmutable<Color4>(device, statusColor);

            bool doQuit = false;
            bool doUpload = false;
            bool uploadImage = false;

            KinectBody[] bodyFrame = null;
            BodyColorPositionBuffer positionBuffer = new BodyColorPositionBuffer(device);
            BodyJointStatusBuffer statusBuffer = new BodyJointStatusBuffer(device);

            KinectSensorBodyFrameProvider provider = new KinectSensorBodyFrameProvider(sensor);
            provider.FrameReceived += (sender, args) => { bodyFrame = args.FrameData; doUpload = true; };

            ColorRGBAFrameData rgbFrame = null;
            DynamicColorRGBATexture colorTexture = new DynamicColorRGBATexture(device);
            KinectSensorColorRGBAFrameProvider colorProvider = new KinectSensorColorRGBAFrameProvider(sensor);
            colorProvider.FrameReceived += (sender, args) => { rgbFrame = args.FrameData; uploadImage = true; };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (doUpload)
                {
                    var tracked = bodyFrame.TrackedOnly();
                    var colorSpace = tracked.Select(kb => new ColorSpaceKinectJoints(kb, sensor.CoordinateMapper));

                    positionBuffer.Copy(context, colorSpace);
                    statusBuffer.Copy(context, tracked);
                    drawer.InstanceCount = colorSpace.Count() * Microsoft.Kinect.Body.JointCount;
                }

                if (uploadImage)
                {
                    colorTexture.Copy(context, rgbFrame);
                }

                context.RenderTargetStack.Push(swapChain);
                context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black);

                device.Primitives.ApplyFullTri(context, colorTexture.ShaderView);
                device.Primitives.FullScreenTriangle.Draw(context);

                circle.Bind(context, layout);

                context.Context.PixelShader.Set(pixelShader);
                context.Context.VertexShader.Set(vertexShader);
                context.Context.VertexShader.SetShaderResource(0, positionBuffer.ShaderView);
                context.Context.VertexShader.SetShaderResource(1, statusBuffer.ShaderView);
                context.Context.VertexShader.SetShaderResource(2, colorTableBuffer.ShaderView);
                context.Context.VertexShader.SetConstantBuffer(0, cbSize.Buffer);

                circle.Draw(context);

                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            colorProvider.Dispose();
            colorTexture.Dispose();

            positionBuffer.Dispose();
            statusBuffer.Dispose();
            colorTableBuffer.Dispose();

            cbSize.Dispose();

            provider.Dispose();
            circle.Dispose();
            layout.Dispose();

            pixelShader.Dispose();
            vertexShader.Dispose();

            sensor.Close();
        }