Example #1
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindUAV(0, MyRender11.HalfScreenUavHDR);
            RC.BindSRVs(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.HalfScreenUavHDR.GetSize();

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

            RC.SetCS(m_downscaleShader);

            size         = MyRender11.QuarterScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.QuarterScreenUavHDR);
            RC.BindSRV(0, MyRender11.HalfScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            size         = MyRender11.EighthScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.QuarterScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDRHelper);

            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.CSSetCB(1, GetCB_blurH(region, size));
                RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);
            }

            return(MyRender11.EighthScreenUavHDR);
        }
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindUAV(0, MyRender11.HalfScreenUavHDR);
            RC.BindSRVs(0, src, avgLum);

            RC.SetCS(m_bloomShader);

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

            RC.SetCS(m_downscaleShader);

            size = MyRender11.QuarterScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.QuarterScreenUavHDR);
            RC.BindSRV(0, MyRender11.HalfScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            size = MyRender11.EighthScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.QuarterScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDR); 
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDRHelper);

            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.CSSetCB(1, GetCB_blurH(region, size));
                RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);
            }

            return MyRender11.EighthScreenUavHDR;
        }
Example #3
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);
        }
Example #4
0
 public void Inflate(int size)
 {
     Max += new Vector2I(size);
     Min -= new Vector2I(size);
 }
Example #5
0
        public float Area()
        {
            Vector2I span = Max - Min;

            return(span.X * span.Y);
        }
Example #6
0
        public float Perimeter()
        {
            Vector2I span = Max - Min;

            return(2 * (span.X = span.Y));
        }
Example #7
0
 /// <summary>
 /// return expanded aabb (abb include point)
 /// </summary>
 /// <param name="box"></param>
 /// <returns></returns>
 public BoundingBox2I Include(ref BoundingBox2I box)
 {
     Min = Vector2I.Min(Min, box.Min);
     Max = Vector2I.Max(Max, box.Max);
     return(this);
 }
Example #8
0
 public static BoundingBox2I CreateFromHalfExtent(Vector2I center, Vector2I halfExtent)
 {
     return(new BoundingBox2I(center - halfExtent, center + halfExtent));
 }
Example #9
0
 public BoundingBox2I Include(Vector2I point)
 {
     return(Include(ref point));
 }
Example #10
0
 /// <summary>
 /// Translate
 /// </summary>
 /// <param name="vctTranlsation"></param>
 /// <returns></returns>
 public BoundingBox2I Translate(Vector2I vctTranlsation)
 {
     Min += vctTranlsation;
     Max += vctTranlsation;
     return(this);
 }
Example #11
0
 internal void SupportMapping(ref Vector2I v, out Vector2I result)
 {
     result.X = (double)v.X >= 0.0 ? Max.X : Min.X;
     result.Y = (double)v.Y >= 0.0 ? Max.Y : Min.Y;
 }
Example #12
0
        /*public ContainmentType Contains(Vector2ID point)
         * {
         *  return (double)this.Min.X > (double)point.X || (double)point.X > (double)this.Max.X || ((double)this.Min.Y > (double)point.Y || (double)point.Y > (double)this.Max.Y) ? ContainmentType.Disjoint : ContainmentType.Contains;
         * }*/

        /// <summary>
        /// Tests whether the BoundingBox2I contains a point.
        /// </summary>
        /// <param name="point">The point to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param>
        public void Contains(ref Vector2I point, out ContainmentType result)
        {
            result = (double)Min.X > (double)point.X || (double)point.X > (double)Max.X || ((double)Min.Y > (double)point.Y || (double)point.Y > (double)Max.Y) ? ContainmentType.Disjoint : ContainmentType.Contains;
        }
Example #13
0
 /// <summary>
 /// Tests whether the BoundingBox2I contains a point.
 /// </summary>
 /// <param name="point">The point to test for overlap.</param>
 public ContainmentType Contains(Vector2I point)
 {
     return((double)Min.X > (double)point.X || (double)point.X > (double)Max.X || ((double)Min.Y > (double)point.Y || (double)point.Y > (double)Max.Y) ? ContainmentType.Disjoint : ContainmentType.Contains);
 }
Example #14
0
 /// <summary>
 /// Creates an instance of BoundingBox2I.
 /// </summary>
 /// <param name="min">The minimum point the BoundingBox2I includes.</param><param name="max">The maximum point the BoundingBox2I includes.</param>
 public BoundingBox2I(Vector2I min, Vector2I max)
 {
     Min = min;
     Max = max;
 }
Example #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;
            MyRwTexturePool 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;
        }
Example #16
0
 public BoundingBox2I Include(Vector2I p0, Vector2I p1, Vector2I p2)
 {
     return(Include(ref p0, ref p1, ref p2));
 }
Example #17
0
 public static BoundingBox2I CreateFromHalfExtent(Vector2I center, int halfExtent)
 {
     return(CreateFromHalfExtent(center, new Vector2I(halfExtent)));
 }