Exemple #1
0
        private static void ResetInternal()
        {
            InitDeadList();

            RC.ComputeShader.SetUav(0, m_particleBuffer);
            RC.ComputeShader.Set(m_csResetParticles);
            RC.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);
        }
Exemple #2
0
        // Init the dead list so that all the particles in the system are marked as dead, ready to be spawned.
        private static void InitDeadList()
        {
            RC.ComputeShader.Set(m_csInitDeadList);

            RC.ComputeShader.SetUav(0, m_deadListBuffer, 0);

            // Disaptch a set of 1d thread groups to fill out the dead list, one thread per particle
            RC.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);
        }
Exemple #3
0
        internal static IBorrowedUavTexture Skip()
        {
            IBorrowedUavTexture borrowedUav = MyManagers.RwTexturesPool.BorrowUav("MyLuminanceAverage.Skip", Format.R32G32_Float);

            RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.ComputeShader.SetUav(0, borrowedUav);
            RC.ComputeShader.Set(m_skipShader);
            RC.Dispatch(1, 1, 1);
            RC.ComputeShader.SetUav(0, null);
            //luminance_reduction_skip
            return(borrowedUav);
        }
Exemple #4
0
        // Per-frame emission of particles into the GPU simulation
        private static void Emit(int emitterCount, MyGPUEmitterData[] emitterData, ISrvBindable depthRead)
        {
            // update emitter data
            var mapping = MyMapping.MapDiscard(m_emitterStructuredBuffer);
            int maxParticlesToEmitThisFrame = 0;

            for (int i = 0; i < emitterCount; i++)
            {
                mapping.WriteAndPosition(ref emitterData[i]);

                if (emitterData[i].NumParticlesToEmitThisFrame > maxParticlesToEmitThisFrame)
                {
                    maxParticlesToEmitThisFrame = emitterData[i].NumParticlesToEmitThisFrame;
                }
            }
            mapping.Unmap();

            int numThreadGroupsX = align(maxParticlesToEmitThisFrame, MAX_PARTICLE_EMIT_THREADS) / MAX_PARTICLE_EMIT_THREADS;
            int numThreadGroupsY = align(emitterCount, MAX_EMITTERS) / MAX_EMITTERS;

            // update emitter count
            mapping = MyMapping.MapDiscard(m_emitterConstantBuffer);
            mapping.WriteAndPosition(ref emitterCount);
            mapping.WriteAndPosition(ref numThreadGroupsX);
            mapping.Unmap();

            if (maxParticlesToEmitThisFrame > 0)
            {
                // Set resources but don't reset any atomic counters
                RC.ComputeShader.SetUav(0, m_particleBuffer);
                RC.ComputeShader.SetUav(1, m_deadListBuffer);
                RC.ComputeShader.SetUav(2, m_skippedParticleCountBuffer, 0);

                RC.ComputeShader.SetConstantBuffer(1, m_emitterConstantBuffer);

                RC.ComputeShader.SetSrv(0, depthRead);
                RC.ComputeShader.SetSrv(1, m_emitterStructuredBuffer);

                RC.ComputeShader.Set(m_csEmit);
                RC.Dispatch(numThreadGroupsX, numThreadGroupsY, 1);
                RC.ComputeShader.SetConstantBuffer(1, null);

                RC.ComputeShader.Set(m_csEmitSkipFix);
                // Disaptch a set of 1d thread groups to fill out the dead list, one thread per particle
                RC.Dispatch(1, 1, 1);
            }
        }
Exemple #5
0
        internal static void Prefilter(IUavArrayTexture probe, IUavArrayTexture prefiltered)
        {
            RC.ComputeShader.Set(m_prefilter);

            var  mipLevels = prefiltered.MipmapLevels;
            var  side      = prefiltered.Size.X;
            uint probeSide = (uint)probe.Size.X;

            IConstantBuffer constantBuffer = MyCommon.GetObjectCB(32);

            RC.ComputeShader.SetConstantBuffer(1, constantBuffer);

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

            for (int j = 0; j < 6; ++j)
            {
                int mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint  samplesNum     = i == 0 ? 1u : 64u;
                    uint  mipSideUint    = (uint)mipSide;
                    uint  ju             = (uint)j;
                    float mipLevelFactor = 1 - (i / (float)(mipLevels - 1));

                    var mapping = MyMapping.MapDiscard(constantBuffer);
                    mapping.WriteAndPosition(ref samplesNum);
                    mapping.WriteAndPosition(ref probeSide);
                    mapping.WriteAndPosition(ref mipSideUint);
                    mapping.WriteAndPosition(ref ju);
                    mapping.WriteAndPosition(ref mipLevelFactor);
                    mapping.Unmap();

                    RC.ComputeShader.SetUav(0, prefiltered.SubresourceUav(j, i));
                    RC.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.SetSrv(0, null);

            RC.ComputeShader.Set(null);
        }
Exemple #6
0
        internal static void Blend(IUavArrayTexture dst, IUavArrayTexture src0, IUavArrayTexture src1, float blendWeight)
        {
            //MyImmediateRC.RC.Context.CopyResource(src1.Resource, dst.Resource);

            RC.ComputeShader.Set(m_blend);

            var mipLevels = dst.MipmapLevels;
            var side      = dst.Size.X;

            RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(32));

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

            for (int j = 0; j < 6; ++j)
            {
                var mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint samplesNum = i == 0 ? 1u : 64u;

                    var blendConstantData = new MyBlendData {
                        field0 = 0, field1 = 0, MipSide = (uint)mipSide, field2 = 0, W = blendWeight
                    };
                    var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(32));
                    mapping.WriteAndPosition(ref blendConstantData);
                    mapping.Unmap();

                    RC.ComputeShader.SetSrv(0, src0.SubresourceSrv(j, i));
                    RC.ComputeShader.SetSrv(1, src1.SubresourceSrv(j, i));

                    // The single parameter version of SetUnorderedAccessView allocates
                    RC.ComputeShader.SetUav(0, dst.SubresourceUav(j, i));
                    RC.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.SetSrv(0, null);
            RC.ComputeShader.SetSrv(1, null);

            RC.ComputeShader.Set(null);
        }
        // Per-frame simulation step
        private static void Simulate(ISrvBindable depthRead)
        {
            RC.ComputeShader.SetRawUav(0, m_particleBuffer.m_uav);
            RC.ComputeShader.SetRawUav(1, m_deadListBuffer.m_uav);
            RC.ComputeShader.SetRawUav(2, m_aliveIndexBuffer.m_uav, 0);
            RC.ComputeShader.SetRawUav(3, m_indirectDrawArgsBuffer.m_uav);

            RC.ComputeShader.SetSrv(0, depthRead);
            RC.ComputeShader.SetRawSrv(1, m_emitterStructuredBuffer.Srv);

            RC.ComputeShader.Set(m_csSimulate);

            RC.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.SetUav(1, null);
            RC.ComputeShader.SetUav(2, null);
            RC.ComputeShader.SetUav(3, null);
        }
Exemple #8
0
        internal static IBorrowedUavTexture Run(ISrvBindable src, ISrvBindable avgLum, ISrvBindable bloom, bool enableTonemapping = true)
        {
            IBorrowedUavTexture dst;

            if (MyRender11.FxaaEnabled)
            {
                dst = MyManagers.RwTexturesPool.BorrowUav("DrawGameScene.Tonemapped", Format.R8G8B8A8_UNorm);
            }
            else
            {
                dst = MyManagers.RwTexturesPool.BorrowUav("DrawGameScene.Tonemapped", Format.R10G10B10A2_UNorm);
            }

            RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16));

            RC.ComputeShader.SetUav(0, dst);
            RC.ComputeShader.SetSrvs(0, src, avgLum, bloom);

            RC.ComputeShader.SetSampler(0, MySamplerStateManager.Default);
            RC.ComputeShader.SetSampler(1, MySamplerStateManager.Point);
            RC.ComputeShader.SetSampler(2, MySamplerStateManager.Default);

            if (enableTonemapping)
            {
                RC.ComputeShader.Set(m_cs);
            }
            else
            {
                RC.ComputeShader.Set(m_csSkip);
            }

            var size = dst.Size;

            RC.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.Set(null);

            return(dst);
        }
Exemple #9
0
        public static IBorrowedUavTexture CreateHistogram(ISrvBindable texture, int samples)
        {
            Vector2I            resolution = texture.Size;
            IBorrowedUavTexture histogram  = MyManagers.RwTexturesPool.BorrowUav("MyHdrDebugTools.Histogram", 513, 1, SharpDX.DXGI.Format.R32_UInt);

            RC.ClearUav(histogram, Int4.Zero);
            RC.ComputeShader.Set(m_buildHistogram);
            RC.ComputeShader.SetSrv(0, texture);
            RC.ComputeShader.SetUav(0, histogram);

            var buffer  = MyCommon.GetObjectCB(16);
            var mapping = MyMapping.MapDiscard(buffer);

            mapping.WriteAndPosition(ref resolution.X);
            mapping.WriteAndPosition(ref resolution.Y);
            mapping.Unmap();
            RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16));

            RC.Dispatch((resolution.X + m_numthreads - 1) / m_numthreads, (resolution.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.ComputeShader.Set(null);
            return(histogram);
        }
Exemple #10
0
        internal static void BuildMipmaps(IUavArrayTexture texture)
        {
            RC.ComputeShader.Set(m_mipmap);

            var mipLevels = texture.MipmapLevels;
            var side      = texture.Size.X;

            for (int j = 0; j < 6; ++j)
            {
                var mipSide = side;
                for (int i = 1; i < mipLevels; ++i)
                {
                    RC.ComputeShader.SetUav(0, texture.SubresourceUav(j, i), -1);
                    RC.ComputeShader.SetSrv(0, texture.SubresourceSrv(j, i - 1));
                    RC.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);
                    RC.ComputeShader.SetSrv(0, null);

                    mipSide >>= 1;
                }
            }

            RC.ComputeShader.SetUav(0, null, -1);
            RC.ComputeShader.Set(null);
        }
Exemple #11
0
        internal static IBorrowedUavTexture Run(ISrvBindable src)
        {
            IBorrowedUavTexture uav0 = MyManagers.RwTexturesPool.BorrowUav("MyLuminanceAverage.Uav0", Format.R32G32_Float);
            IBorrowedUavTexture uav1 = MyManagers.RwTexturesPool.BorrowUav("MyLuminanceAverage.Uav1", Format.R32G32_Float);

            Vector2I size      = src.Size;
            int      texelsNum = size.X * size.Y;
            uint     sizeX     = (uint)size.X;
            uint     sizeY     = (uint)size.Y;
            var      buffer    = MyCommon.GetObjectCB(16);
            var      mapping   = MyMapping.MapDiscard(buffer);

            mapping.WriteAndPosition(ref sizeX);
            mapping.WriteAndPosition(ref sizeY);
            mapping.WriteAndPosition(ref texelsNum);
            mapping.Unmap();

            RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16));

            RC.ComputeShader.Set(m_initialShader);

            IBorrowedUavTexture output   = uav0;
            ISrvBindable        inputSrc = src;

            RC.ComputeShader.SetUav(0, output);
            RC.ComputeShader.SetSrv(0, inputSrc);

            int threadGroupCountX = ComputeGroupCount(size.X);
            int threadGroupCountY = ComputeGroupCount(size.Y);

            RC.Dispatch(threadGroupCountX, threadGroupCountY, 1);
            RC.ComputeShader.Set(m_sumShader);

            IBorrowedUavTexture input;
            int i = 0;

            while (true)
            {
                size.X = threadGroupCountX;
                size.Y = threadGroupCountY;

                if (size.X <= NUM_THREADS && size.Y <= NUM_THREADS)
                {
                    break;
                }

                output = (i % 2 == 0) ? uav1 : uav0;
                input  = (i % 2 == 0) ? uav0 : uav1;

                RC.ComputeShader.SetSrv(0, null);
                RC.ComputeShader.SetUav(0, output);
                RC.ComputeShader.SetSrv(0, input);

                threadGroupCountX = ComputeGroupCount(size.X);
                threadGroupCountY = ComputeGroupCount(size.Y);
                RC.Dispatch(threadGroupCountX, threadGroupCountY, 1);

                i++;
            }

            RC.ComputeShader.Set(m_finalShader);

            output = (i % 2 == 0) ? uav1 : uav0;
            input  = (i % 2 == 0) ? uav0 : uav1;

            RC.ComputeShader.SetSrv(0, null);
            RC.ComputeShader.SetUav(0, output);
            RC.ComputeShader.SetSrvs(0, input, m_prevLum);

            threadGroupCountX = ComputeGroupCount(size.X);
            threadGroupCountY = ComputeGroupCount(size.Y);
            RC.Dispatch(threadGroupCountX, threadGroupCountY, 1);

            RC.ComputeShader.Set(null);
            RC.ComputeShader.SetUav(0, null);

            // Backup the result for later process
            RC.CopySubresourceRegion(output.Resource, 0, new ResourceRegion(0, 0, 0, 1, 1, 1), m_prevLum.Resource, 0);

            input.Release();
            return(output);
        }
Exemple #12
0
        private static void PreparePointLights()
        {
            bool visiblePointlights = VisiblePointlights.Count != 0;

            if (!visiblePointlights && !m_lastFrameVisiblePointlights)
            {
                return;
            }

            m_lastFrameVisiblePointlights = visiblePointlights;

            if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
            {
                VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared));

                while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
                {
                    VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1);
                }
            }

            var activePointlights = 0;

            foreach (var light in VisiblePointlights)
            {
                MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]);

                activePointlights++;
                Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS);
            }
            for (int lightIndex = activePointlights; lightIndex < MyRender11Constants.MAX_POINT_LIGHTS; ++lightIndex)
            {
                MyLights.WritePointlightConstants(LightId.NULL, ref m_pointlightsCullBuffer[lightIndex]);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.WriteAndPosition(ref activePointlights);
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer);
            mapping.WriteAndPosition(m_pointlightsCullBuffer, MyRender11Constants.MAX_POINT_LIGHTS);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            }
            RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16));

            RC.ComputeShader.SetUav(0, m_tileIndices);
            RC.ComputeShader.SetSrvs(0, MyGBuffer.Main);
            RC.ComputeShader.SetSrv(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer);
            RC.ComputeShader.Set(m_preparePointLights);
            Vector2I tiles = new Vector2I(m_tilesX, m_tilesY);

            if (MyStereoRender.Enable && MyStereoRender.RenderRegion != MyStereoRegion.FULLSCREEN)
            {
                tiles.X /= 2;
            }

            RC.Dispatch(tiles.X, tiles.Y, 1);
            RC.ComputeShader.Set(null);
            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.ResetSrvs(0, MyGBufferSrvFilter.ALL);
        }
        internal static void PreparePointLights()
        {
            var activePointlights = 0;

            MyLights.Update();
            BoundingFrustumD viewFrustumClippedD = MyRender11.Environment.Matrices.ViewFrustumClippedD;

            if (MyStereoRender.Enable)
            {
                if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesLeftEye.ViewFrustumClippedD;
                }
                else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesRightEye.ViewFrustumClippedD;
                }
            }
            MyLights.PointlightsBvh.OverlapAllFrustum(ref viewFrustumClippedD, VisiblePointlights);

            bool visiblePointlights = VisiblePointlights.Count != 0;

            if (!visiblePointlights && !m_lastFrameVisiblePointlights)
            {
                return;
            }

            m_lastFrameVisiblePointlights = visiblePointlights;

            if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
            {
                VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared));

                while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
                {
                    VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1);
                }
            }

            foreach (var light in VisiblePointlights)
            {
                MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]);

                activePointlights++;
                Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS);
            }
            for (int lightIndex = activePointlights; lightIndex < MyRender11Constants.MAX_POINT_LIGHTS; ++lightIndex)
            {
                MyLights.WritePointlightConstants(LightId.NULL, ref m_pointlightsCullBuffer[lightIndex]);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.WriteAndPosition(ref activePointlights);
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer.Buffer);
            mapping.WriteAndPosition(m_pointlightsCullBuffer, 0, MyRender11Constants.MAX_POINT_LIGHTS);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            }
            RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16));

            //RC.BindUAV(0, MyScreenDependants.m_test);
            RC.ComputeShader.SetRawUav(0, MyScreenDependants.m_tileIndices.m_uav);
            RC.ComputeShader.SetSrvs(0, MyGBuffer.Main);
            RC.ComputeShader.SetRawSrv(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv);
            RC.ComputeShader.Set(m_preparePointLights);
            Vector2I tiles = new Vector2I(MyScreenDependants.TilesX, MyScreenDependants.TilesY);

            if (MyStereoRender.Enable && MyStereoRender.RenderRegion != MyStereoRegion.FULLSCREEN)
            {
                tiles.X /= 2;
            }

            RC.Dispatch(tiles.X, tiles.Y, 1);
            RC.ComputeShader.Set(null);
            RC.ComputeShader.SetRawUav(0, null);
            RC.ComputeShader.ResetSrvs(0, MyGBufferSrvFilter.ALL);
        }
Exemple #14
0
        internal static void Draw(IRtvBindable renderTarget, IRtvTexture ambientOcclusion)
        {
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.SetRtv(renderTarget);
            RC.PixelShader.SetSrvs(0, MyGBuffer.Main);

            RC.SetBlendState(null);

            if (MyRender11.Settings.DisplayGbufferColor)
            {
                RC.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAlbedo)
            {
                RC.PixelShader.Set(m_albedoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormal)
            {
                RC.PixelShader.Set(m_normalShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormalView)
            {
                RC.PixelShader.Set(m_normalViewShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferGlossiness)
            {
                RC.PixelShader.Set(m_glossinessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMetalness)
            {
                RC.PixelShader.Set(m_metalnessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAO)
            {
                RC.PixelShader.Set(m_aoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEmissive)
            {
                RC.PixelShader.Set(m_emissiveShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientDiffuse)
            {
                RC.PixelShader.Set(m_ambientDiffuseShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientSpecular)
            {
                RC.PixelShader.Set(m_ambientSpecularShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEdgeMask)
            {
                RC.PixelShader.Set(m_edgeDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayShadowsWithDebug)
            {
                RC.PixelShader.Set(m_shadowsDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayNDotL)
            {
                RC.PixelShader.Set(m_NDotLShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferLOD)
            {
                RC.PixelShader.Set(m_LODShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayMipmap)
            {
                RC.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayDepth)
            {
                RC.PixelShader.Set(m_depthShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayReprojectedDepth)
            {
                var dst = MyManagers.RwTexturesPool.BorrowUav("DebugRender.DepthReprojection", Format.R32_Float);
                MyRender11.RC.ClearUav(dst, SharpDX.Int4.Zero);

                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
                RC.ComputeShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
                RC.ComputeShader.SetUav(0, dst);
                RC.ComputeShader.Set(m_depthReprojectionShader);
                int numThreadGroupsX = align(MyRender11.ResolutionI.X, 32) / 32;
                int numThreadGroupsY = align(MyRender11.ResolutionI.Y, 32) / 32;
                RC.Dispatch(numThreadGroupsX, numThreadGroupsY, 1);
                RC.ComputeShader.SetSrv(0, null);
                RC.ComputeShader.SetUav(0, null);

                RC.PixelShader.SetSrv(0, dst);
                RC.PixelShader.Set(m_depthShader);
                MyScreenPass.DrawFullscreenQuad();

                RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            }
            else if (MyRender11.Settings.DisplayStencil)
            {
                RC.PixelShader.Set(m_stencilShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAO)
            {
                RC.PixelShader.SetSrv(0, ambientOcclusion);
                RC.PixelShader.SetSampler(0, MySamplerStateManager.Linear);
                RC.PixelShader.Set(m_rtShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEnvProbe)
            {
                DrawEnvProbe();
            }

            //DrawEnvProbe();
            //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);
            //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);

            if (MyRender11.Settings.DrawCascadeTextures)
            {
                //DrawDepthArrayTexture(MyManagers.Shadow.GetCsmForGbuffer(), 100, 100, 200);
                DrawDepthArrayTexture(MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray, 100, 100, 200);
                if (MyScene.SeparateGeometry)
                {
                    DrawDepthArrayTexture(MyRender11.StaticShadows.ShadowCascades.CascadeShadowmapArray, 100, 300, 200);
                    DrawDepthArrayTexture(MyShadowCascades.CombineShadowmapArray, 100, 500, 200);
                }
            }

            if (MyRender11.Settings.DisplayIDs || MyRender11.Settings.DisplayAabbs)
            {
                DrawHierarchyDebug();
            }

            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                foreach (var light in MyLightsRendering.VisiblePointlights)
                {
                    batch.AddSphereRing(new BoundingSphere(light.PointPosition, 0.5f), Color.White, Matrix.Identity);
                }
                batch.Commit();
            }

            // draw terrain lods
            if (MyRender11.Settings.DebugRenderClipmapCells)
            {
                //var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => (MyMeshes.IsVoxelMesh(x.Mesh))))
                //{
                //    if (renderable.IsVisible)
                //    {
                //        if (renderable.m_lod >= LOD_COLORS.Length)
                //            return;

                //        BoundingBox bb = new BoundingBox(renderable.m_owner.Aabb.Min - MyRender11.Environment.CameraPosition,renderable.m_owner.Aabb.Max - MyRender11.Environment.CameraPosition);

                //        batch.AddBoundingBox(bb, new Color(LOD_COLORS[renderable.m_voxelLod]));


                //        if (renderable.m_lods != null && renderable.m_voxelLod != renderable.m_lods[0].RenderableProxies[0].ObjectData.CustomAlpha)
                //        {

                //        }
                //    }
                //}

                //batch.Commit();

                MyClipmap.DebugDrawClipmaps();
            }

            //if(true)
            //{
            //    var batch = MyLinesRenderer.CreateBatch();

            //    foreach(var id in MyLights.DirtySpotlights)
            //    {
            //        var info = MyLights.Spotlights[id.Index];

            //        if(info.ApertureCos > 0)
            //        {
            //            var D = info.Direction * info.Range;
            //            //batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            //var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range).Transform(Matrix.CreateLookAt(MyLights.Lights.Data[id.Index].Position, info.Direction, info.Up));


            //            //batch.AddBoundingBox(bb, Color.Green);

            //            batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range, MyLights.Lights.Data[id.Index].Position, info.Up);
            //            batch.AddBoundingBox(bb, Color.Green);
            //        }
            //    }



            //    batch.Commit();
            //}

            // draw lods
            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => ((x.GetMesh() as MyVoxelMesh) == null)))
                //{

                //    if (renderable.CurrentLodNum >= LOD_COLORS.Length || renderable.m_lods.Length == 1)
                //        continue;

                //    batch.AddBoundingBox(renderable.m_owner.Aabb, new Color(LOD_COLORS[renderable.CurrentLodNum]));
                //}

                batch.Commit();
            }
        }
Exemple #15
0
        // IMPORTANT: The returned object needs to be returned to MyManagers.RwTexturePool after the usage
        internal static IBorrowedUavTexture Run(ISrvBindable src, ISrvBindable srcGBuffer2, ISrvBindable srcDepth)
        {
            RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.ComputeShader.SetSampler(0, MySamplerStateManager.Default);

            int    screenX       = MyRender11.ResolutionI.X;
            int    screenY       = MyRender11.ResolutionI.Y;
            Format formatLBuffer = MyGBuffer.LBufferFormat;
            MyBorrowedRwTextureManager rwTexturePool       = MyManagers.RwTexturesPool;
            IBorrowedUavTexture        uavHalfScreen       = rwTexturePool.BorrowUav("MyBloom.UavHalfScreen", screenX / 2, screenY / 2, formatLBuffer);
            IBorrowedUavTexture        uavBlurScreen       = rwTexturePool.BorrowUav("MyBloom.UavBlurScreen", screenX / BLOOM_TARGET_SIZE_DIVIDER, screenY / BLOOM_TARGET_SIZE_DIVIDER, formatLBuffer);
            IBorrowedUavTexture        uavBlurScreenHelper = rwTexturePool.BorrowUav("MyBloom.UavBlurScreenHelper", screenX / BLOOM_TARGET_SIZE_DIVIDER, screenY / BLOOM_TARGET_SIZE_DIVIDER, formatLBuffer);

            RC.ComputeShader.SetUav(0, uavHalfScreen);
            RC.ComputeShader.SetSrv(0, src);
            RC.ComputeShader.SetSrv(1, srcGBuffer2);
            RC.ComputeShader.SetSrv(2, srcDepth);

            RC.ComputeShader.Set(m_bloomShader);

            var size = uavHalfScreen.Size;

            VRageMath.Vector2I threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.Dispatch(threadGroups.X, threadGroups.Y, 1);

            bool skipDownScale = false;

            switch (BLOOM_TARGET_SIZE_DIVIDER)
            {
            case 2:
                skipDownScale = true;
                break;

            case 4:
                RC.ComputeShader.Set(m_downscale2Shader);
                break;

            case 8:
                RC.ComputeShader.Set(m_downscale4Shader);
                break;

            default:
                MyRenderProxy.Assert(false, "Invalid bloom target size divider");
                break;
            }
            size         = uavBlurScreen.Size;
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            if (!skipDownScale)
            {
                RC.ComputeShader.SetConstantBuffer(1, GetCBSize(uavHalfScreen.Size.X, uavHalfScreen.Size.Y));

                RC.ComputeShader.SetUav(0, uavBlurScreen);
                RC.ComputeShader.SetSrv(0, uavHalfScreen);
                RC.Dispatch(threadGroups.X, threadGroups.Y, 1);
            }

            RC.ComputeShader.SetConstantBuffer(1, GetCB_blur(MyStereoRegion.FULLSCREEN, size));
            RC.ComputeShader.Set(m_blurV[MyRender11.Postprocess.BloomSize]);
            RC.ComputeShader.SetUav(0, uavBlurScreenHelper);
            RC.ComputeShader.SetSrv(0, uavBlurScreen);
            RC.Dispatch(threadGroups.X, threadGroups.Y, 1);
            RC.ComputeShader.SetSrv(0, null);
            RC.ComputeShader.SetUav(0, null);

            RC.ComputeShader.Set(m_blurH[MyRender11.Postprocess.BloomSize]);
            RC.ComputeShader.SetUav(0, uavBlurScreen);
            RC.ComputeShader.SetSrv(0, uavBlurScreenHelper);

            int nPasses = 1;

            if (MyStereoRender.Enable)
            {
                threadGroups.X /= 2;
                nPasses         = 2;
            }
            for (int nPass = 0; nPass < nPasses; nPass++)
            {
                MyStereoRegion region = MyStereoRegion.FULLSCREEN;
                if (MyStereoRender.Enable)
                {
                    region = nPass == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT;
                }

                RC.ComputeShader.SetConstantBuffer(1, GetCB_blur(region, size));
                RC.Dispatch(threadGroups.X, threadGroups.Y, 1);
            }

            if (MyRender11.Settings.DisplayBloomFilter)
            {
                MyDebugTextureDisplay.Select(uavHalfScreen);
            }
            else if (MyRender11.Settings.DisplayBloomMin)
            {
                MyDebugTextureDisplay.Select(uavBlurScreen);
            }

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.SetSrv(0, null);
            uavHalfScreen.Release();
            uavBlurScreenHelper.Release();

            return(uavBlurScreen);
        }
        internal void GatherArray(IUavTexture postprocessTarget, ISrvBindable cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality();

            if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED)
            {
                RC.ClearUav(postprocessTarget, new RawInt4());
                return;
            }

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            if (shadowsQuality == MyShadowsQuality.LOW)
            {
                RC.ComputeShader.Set(m_gatherCS_LD);
            }
            else if (shadowsQuality == MyShadowsQuality.MEDIUM)
            {
                RC.ComputeShader.Set(m_gatherCS_MD);
            }
            else if (shadowsQuality == MyShadowsQuality.HIGH)
            {
                RC.ComputeShader.Set(m_gatherCS_HD);
            }

            RC.ComputeShader.SetUav(0, postprocessTarget);

            RC.ComputeShader.SetSrv(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.ComputeShader.SetSrv(1, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap);
            if (!MyStereoRender.Enable)
            {
                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            }
            //RC.ComputeShader.SetConstantBuffer(4, MyManagers.Shadows.GetCsmConstantBufferOldOne());
            RC.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, cascadeArray);
            //RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyManagers.Shadow.GetCsmForGbuffer());

            Vector2I threadGroups = GetThreadGroupCount();

            RC.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.SetSrv(0, null);
            RC.ComputeShader.SetSrv(1, null);

            if (shadowsQuality == MyShadowsQuality.HIGH && MyShadowCascades.Settings.Data.EnableShadowBlur)
            {
                IBorrowedUavTexture helper = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascadesPostProcess.Helper", Format.R8_UNorm);
                MyBlur.Run(postprocessTarget, helper, postprocessTarget,
                           depthStencilState: MyDepthStencilStateManager.IgnoreDepthStencil,
                           depthDiscardThreshold: 0.2f, clearColor: Color4.White);
                helper.Release();
            }

            MyGpuProfiler.IC_EndBlock();
        }