コード例 #1
0
ファイル: MyShadowManager.cs プロジェクト: viktorius/Viktor
        public IBorrowedUavTexture Evaluate()
        {
            MyRenderProxy.Assert(m_mainCsm.SlicesCount == m_settings.NewData.CascadesCount, "Cascades count incostistency");
            if (m_settings.NewData.DrawVolumes)
            {
                ShadowCore.DrawVolumes();
            }
            ShadowCore.MarkAllCascades(MyGBuffer.Main.DepthStencil, MyRender11.Environment.Matrices.ViewProjectionAt0, m_mainCsm);
            if (m_settings.NewData.DisplayCascadeCoverage)
            {
                IBorrowedRtvTexture target = MyManagers.RwTexturesPool.BorrowRtv("MyShadows.Evaluate.CascadeCoverage", Format.R8G8B8A8_SNorm);
                ShadowCore.DrawCoverage(target, MyGBuffer.Main.DepthStencil);
                MyDebugTextureDisplay.Select(target);
                target.Release();
            }

            if (m_settings.NewData.DisplayHardShadows)
            {
                IBorrowedUavTexture hardShadowed =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.HardShadowed", Format.R8_UNorm);
                ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.HARD, hardShadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings);
                MyDebugTextureDisplay.Select(hardShadowed);
                hardShadowed.Release();
            }

            if (m_settings.NewData.DisplaySimpleShadows)
            {
                IBorrowedUavTexture simpleShadowed =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.SimpleShadowed", Format.R8_UNorm);
                ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.SIMPLE, simpleShadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings);
                MyDebugTextureDisplay.Select(simpleShadowed);
                simpleShadowed.Release();
            }

            IBorrowedUavTexture shadowed =
                MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.Shadowed", Format.R8_UNorm);

            ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.SIMPLE, shadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings);

            if (m_settings.NewData.EnableFXAAOnShadows)
            {
                IBorrowedUavTexture inputForFXAA =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.InputForFXAA", Format.R8G8B8A8_UNorm);
                ShadowCore.CopyRedToAll(inputForFXAA, shadowed);
                IBorrowedUavTexture shadowedWithFXAA =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.ShadowedWithFXAA", Format.R8G8B8A8_UNorm);
                MyFXAA.Run(shadowedWithFXAA, inputForFXAA);
                shadowed.Release();
                inputForFXAA.Release();
                shadowed = shadowedWithFXAA;
            }
            return(shadowed);
        }
コード例 #2
0
ファイル: MyHdrDebugTools.cs プロジェクト: viktorius/Viktor
        public static void DisplayHdrIntensity(ISrvBindable srv)
        {
            RC.PixelShader.Set(m_psDisplayHdrIntensity);
            RC.PixelShader.SetSrv(5, srv);
            RC.SetBlendState(null);
            IBorrowedRtvTexture outTex = MyManagers.RwTexturesPool.BorrowRtv("MyHdrDebugTools.DisplayHdrIntensity.OutTex", srv.Size.X, srv.Size.Y, Format.B8G8R8X8_UNorm);

            MyScreenPass.RunFullscreenPixelFreq(outTex);
            MyDebugTextureDisplay.Select(outTex);

            RC.PixelShader.SetSrv(5, null);
            RC.SetRtvs(MyGBuffer.Main, MyDepthStencilAccess.ReadOnly);
            outTex.Release();
        }
コード例 #3
0
        static void DisplayOverlappingHeatMap(IUavTexture accumTarget, IUavTexture coverageTarget, bool useGrayscale)
        {
            IBorrowedRtvTexture heatMap = MyManagers.RwTexturesPool.BorrowRtv("MyTransparentRendering.HeatMap",
                                                                              Format.R8G8B8A8_UNorm);

            RC.ClearRtv(heatMap, default(RawColor4));

            RC.SetRtv(heatMap);
            RC.PixelShader.SetSrv(0, accumTarget);
            RC.PixelShader.Set(useGrayscale ? m_psOverlappingHeatMapInGrayscale : m_psOverlappingHeatMap);
            RC.SetBlendState(MyBlendStateManager.BlendAdditive);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            MyScreenPass.DrawFullscreenQuad();

            RC.PixelShader.Set(null);
            RC.PixelShader.SetSrv(0, null);
            RC.SetRtv(null);
            SetupOIT(accumTarget, coverageTarget, false);

            MyDebugTextureDisplay.Select(heatMap);
            heatMap.Release();
        }
コード例 #4
0
ファイル: MyBloom.cs プロジェクト: viktorius/Viktor
        // 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);
        }