示例#1
0
        internal static void Init()
        {
            MyGPUEmitters.Init();

            m_resetSystem = true;

            m_csInitDeadList   = MyShaders.CreateCs("Transparent/GPUParticles/InitDeadList.hlsl", null);
            m_csResetParticles = MyShaders.CreateCs("Transparent/GPUParticles/Reset.hlsl", null);
            m_csEmit           = MyShaders.CreateCs("Transparent/GPUParticles/Emit.hlsl", null);
            m_csEmitSkipFix    = MyShaders.CreateCs("Transparent/GPUParticles/EmitSkipFix.hlsl", null);
            m_csSimulate       = MyShaders.CreateCs("Transparent/GPUParticles/Simulation.hlsl", null);

            var macrosRender    = new[] { new ShaderMacro("STREAKS", null), new ShaderMacro("LIT_PARTICLE", null) };
            var macrosRenderOIT = new[] { new ShaderMacro("STREAKS", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) };

            m_vs    = MyShaders.CreateVs("Transparent/GPUParticles/Render.hlsl", macrosRender);
            m_ps    = MyShaders.CreatePs("Transparent/GPUParticles/Render.hlsl", macrosRender);
            m_psOIT = MyShaders.CreatePs("Transparent/GPUParticles/Render.hlsl", macrosRenderOIT);

            var macroDebug = new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null) };

            m_psDebugUniformAccum    = MyShaders.CreatePs("Transparent/GPUParticles/Render.hlsl", MyShaders.ConcatenateMacros(macrosRender, macroDebug));
            m_psDebugUniformAccumOIT = MyShaders.CreatePs("Transparent/GPUParticles/Render.hlsl", MyShaders.ConcatenateMacros(macrosRenderOIT, macroDebug));

            InitDevice();
        }
示例#2
0
        internal static void Init()
        {
            MyGPUEmitters.Init();

            m_resetSystem = true;

            m_csInitDeadList   = MyShaders.CreateCs("Particles/InitDeadList.hlsl", null);
            m_csResetParticles = MyShaders.CreateCs("Particles/Reset.hlsl", null);
            m_csEmit           = MyShaders.CreateCs("Particles/Emit.hlsl", null);
            m_csSimulate       = MyShaders.CreateCs("Particles/Simulation.hlsl", null);

            var macrosRender    = new[] { new ShaderMacro("STREAKS", null), new ShaderMacro("LIT_PARTICLE", null) };
            var macrosRenderOIT = new[] { new ShaderMacro("STREAKS", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) };

            m_vs    = MyShaders.CreateVs("Particles/Render.hlsl", macrosRender);
            m_ps    = MyShaders.CreatePs("Particles/Render.hlsl", macrosRender);
            m_psOIT = MyShaders.CreatePs("Particles/Render.hlsl", macrosRenderOIT);

            InitDevice();
        }
示例#3
0
        internal static void Run(ISrvBindable depthRead, ISrvBindable gbufferNormalsRead)
        {
            // The maximum number of supported GPU particles
            ISrvBindable textureArraySrv;
            int          emitterCount = MyGPUEmitters.Gather(m_emitterData, out textureArraySrv);

            if (emitterCount == 0)
            {
                return;
            }

            // Unbind current targets while we run the compute stages of the system
            //RC.DeviceContext.OutputMerger.SetTargets(null);
            // global GPU particles setup
            RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
            RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
            RC.SetInputLayout(null);
            RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.ComputeShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.AllShaderStages.SetConstantBuffer(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer);
            RC.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap);
            RC.VertexShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray);
            RC.VertexShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            // If we are resetting the particle system, then initialize the dead list
            if (m_resetSystem)
            {
                ResetInternal();
                m_resetSystem = false;
            }

            MyGpuProfiler.IC_BeginBlock("Emit");
            // Emit particles into the system
            Emit(emitterCount, m_emitterData, depthRead);
            MyGpuProfiler.IC_EndBlock();

            // Run the simulation for this frame
            MyGpuProfiler.IC_BeginBlock("Simulate");
            Simulate(depthRead, gbufferNormalsRead);
            MyGpuProfiler.IC_EndBlock();

            // Copy the atomic counter in the alive list UAV into a constant buffer for access by subsequent passes
            RC.CopyStructureCount(m_activeListConstantBuffer, 0, m_aliveIndexBuffer);

            // Only read number of alive and dead particle back to the CPU in debug as we don't want to stall the GPU in release code

            ProfilerShort.Begin("Debug - ReadCounter");
            MyGpuProfiler.IC_BeginBlock("Debug - ReadCounter");
            int numActiveParticlesAfterSimulation = ReadCounter(m_aliveIndexBuffer);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();

            MyGpuProfiler.IC_BeginBlock("Render");
            Render(textureArraySrv, depthRead);
            MyGpuProfiler.IC_EndBlock();

            RC.ComputeShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            MyStatsDisplay.Write("GPU particles", "Live #", numActiveParticlesAfterSimulation);
        }
示例#4
0
 internal static void OnSessionEnd()
 {
     MyGPUEmitters.OnSessionEnd();
     m_resetSystem = true;
 }
示例#5
0
        internal static void Run(MyBindableResource depthRead)
        {
            // The maximum number of supported GPU particles
            SharpDX.Direct3D11.ShaderResourceView textureArraySRV;
            int emitterCount = MyGPUEmitters.Gather(m_emitterData, out textureArraySRV);

            if (emitterCount == 0)
            {
                return;
            }

            // Unbind current targets while we run the compute stages of the system
            //RC.DeviceContext.OutputMerger.SetTargets(null);
            // global GPU particles setup
            RC.SetDS(MyDepthStencilState.DefaultDepthState);
            RC.SetRS(MyRender11.m_nocullRasterizerState);
            RC.SetIL(null);
            RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.DeviceContext.ComputeShader.SetSamplers(0, SamplerStates.StandardSamplers);
            RC.DeviceContext.PixelShader.SetSamplers(0, SamplerStates.StandardSamplers);
            RC.SetCB(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer);
            RC.DeviceContext.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap);
            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray.SRV);
            RC.DeviceContext.VertexShader.SetSamplers(0, SamplerStates.StandardSamplers);

            // If we are resetting the particle system, then initialize the dead list
            if (m_resetSystem)
            {
                ResetInternal();
                m_resetSystem = false;
            }

            MyGpuProfiler.IC_BeginBlock("Emit");
            // Emit particles into the system
            Emit(emitterCount, m_emitterData);
            MyGpuProfiler.IC_EndBlock();

            // Run the simulation for this frame
            MyGpuProfiler.IC_BeginBlock("Simulate");
            Simulate(depthRead);
            MyGpuProfiler.IC_EndBlock();

            // Copy the atomic counter in the alive list UAV into a constant buffer for access by subsequent passes
            RC.DeviceContext.CopyStructureCount(m_activeListConstantBuffer, 0, m_aliveIndexBuffer.m_UAV);

            // Only read number of alive and dead particle back to the CPU in debug as we don't want to stall the GPU in release code
#if DEBUG
            m_numDeadParticlesAfterSimulation   = ReadCounter(m_deadListBuffer);
            m_numActiveParticlesAfterSimulation = ReadCounter(m_aliveIndexBuffer);
#endif

            MyGpuProfiler.IC_BeginBlock("Render");
            Render(textureArraySRV, depthRead);
            MyGpuProfiler.IC_EndBlock();

            RC.DeviceContext.ComputeShader.SetSamplers(0, SamplerStates.StandardSamplers);

            /*Debug.WriteLine(string.Format("dead particles @ start {0} dead after emit {1} dead after sim {2} active after sim {3}",
             *  m_numDeadParticlesOnInit, m_numDeadParticlesAfterEmit,
             *  m_numDeadParticlesAfterSimulation, m_numActiveParticlesAfterSimulation));*/
        }