コード例 #1
0
        unsafe IConstantBuffer GetShadowConstants(ICascadeShadowMap csm, ref MyShadowsSettings settings)
        {
            const int MAX_SLICES_COUNT = 8;

            MyRenderProxy.Assert(csm.SlicesCount <= MAX_SLICES_COUNT, "It is not supported more than 8 slices per cascade shadow map");
            int             size    = sizeof(Matrix) * MAX_SLICES_COUNT + sizeof(Vector4) * MAX_SLICES_COUNT;
            IConstantBuffer cb      = MyCommon.GetObjectCB(size);
            var             mapping = MyMapping.MapDiscard(cb);

            for (int i = 0; i < csm.SlicesCount; i++)
            {
                // Set matrices:
                Matrix matrix = csm.GetSlice(i).MatrixWorldAt0ToShadowSpace;
                matrix = matrix * Matrix.CreateTranslation(1, -1, 0);

                Vector2 scalingFactor = new Vector2(0.5f, -0.5f);
                matrix = matrix * Matrix.CreateScale(scalingFactor.X, scalingFactor.Y, 1);
                matrix = Matrix.Transpose(matrix);
                mapping.WriteAndPosition(ref matrix);

                // Set normal offsets:
                mapping.WriteAndPosition(ref settings.Cascades[i].ShadowNormalOffset);
                float zero = 0;
                for (int j = 1; j < 4; j++)
                {
                    mapping.WriteAndPosition(ref zero);
                }
            }

            mapping.Unmap();
            return(cb);
        }
コード例 #2
0
 public void DisposeCsm(ICascadeShadowMap csm)
 {
     MyCascadeShadowMap myCsm = (MyCascadeShadowMap)csm;
     MyRenderProxy.Assert(!m_objectsPoolCsm.Active.Contains(myCsm), "Shadowmap is not active, maybe it is disposed already.");
     myCsm.Destroy();
     m_objectsPoolCsm.Deallocate(myCsm);
 }
コード例 #3
0
        unsafe ConstantsBufferId GetShadowConstants(ICascadeShadowMap csm, ref MyShadowsSettings settings)
        {
            const int MAX_SLICES_COUNT = 8;
            MyRenderProxy.Assert(csm.SlicesCount <= MAX_SLICES_COUNT, "It is not supported more than 8 slices per cascade shadow map");
            int size = sizeof(Matrix)*MAX_SLICES_COUNT + sizeof(Vector4)*MAX_SLICES_COUNT;
            ConstantsBufferId cb = MyCommon.GetObjectCB(size);
            var mapping = MyMapping.MapDiscard(cb);

            for (int i = 0; i < csm.SlicesCount; i++)
            {
                // Set matrices:
                Matrix matrix = csm.GetSlice(i).MatrixWorldAt0ToShadowSpace;
                matrix = matrix*Matrix.CreateTranslation(1, -1, 0);
                
                Vector2 scalingFactor = new Vector2(0.5f, -0.5f);
                matrix = matrix * Matrix.CreateScale(scalingFactor.X, scalingFactor.Y, 1);
                matrix = Matrix.Transpose(matrix);
                mapping.WriteAndPosition(ref matrix);

                // Set normal offsets:
                mapping.WriteAndPosition(ref settings.Cascades[i].ShadowNormalOffset);
                float zero = 0;
                for (int j = 1; j < 4; j++)
                    mapping.WriteAndPosition(ref zero);
            }
            
            mapping.Unmap();
            return cb;
        }
コード例 #4
0
        public void DisposeCsm(ICascadeShadowMap csm)
        {
            MyCascadeShadowMap myCsm = (MyCascadeShadowMap)csm;

            MyRenderProxy.Assert(!m_objectsPoolCsm.Active.Contains(myCsm), "Shadowmap is not active, maybe it is disposed already.");
            myCsm.Destroy();
            m_objectsPoolCsm.Deallocate(myCsm);
        }
コード例 #5
0
        public void Draw(IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm, ref MyShadowsSettings settings)
        {
            MyRenderContext RC = MyRender11.RC;
            RC.SetBlendState(null);
            RC.SetRtv(outTex);

            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, stencil.SrvDepth);
            RC.PixelShader.SetSrv(1, stencil.SrvStencil);
            RC.PixelShader.SetSrv(2, csm.DepthArrayTexture);
            RC.PixelShader.SetSrv(3, MyGBuffer.Main.GBuffer1);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.PixelShader.SetConstantBuffer(1, GetShadowConstants(csm, ref settings));
            RC.PixelShader.SetSampler(6, MySamplerStateManager.Shadowmap);

            MyScreenPass.DrawFullscreenQuad();
            RC.ResetTargets();
        }
コード例 #6
0
        public void Draw(IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm, ref MyShadowsSettings settings)
        {
            MyRenderContext RC = MyRender11.RC;

            RC.SetBlendState(null);
            RC.SetRtv(outTex);

            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, stencil.SrvDepth);
            RC.PixelShader.SetSrv(1, stencil.SrvStencil);
            RC.PixelShader.SetSrv(2, csm.DepthArrayTexture);
            RC.PixelShader.SetSrv(3, MyGBuffer.Main.GBuffer1);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.PixelShader.SetConstantBuffer(1, GetShadowConstants(csm, ref settings));
            RC.PixelShader.SetSampler(6, MySamplerStateManager.Shadowmap);

            MyScreenPass.DrawFullscreenQuad();
            RC.ResetTargets();
        }
コード例 #7
0
        public void ApplyPostprocess(MyPostprocessShadows.Type type, IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm,
                                     ref MyShadowsSettings settings)
        {
            MyPostprocessShadows postprocess = null;

            switch (type)
            {
            case MyPostprocessShadows.Type.HARD:
                postprocess = m_postprocessHardShadows;
                break;

            case MyPostprocessShadows.Type.SIMPLE:
                postprocess = m_postprocessSimpleShadows;
                break;

            default:
                MyRenderProxy.Assert(false);
                break;
            }
            postprocess.Draw(outTex, stencil, csm, ref settings);
        }
コード例 #8
0
 public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm)
 {
     m_markCascades.MarkAllCascades(depthStencil, worldToProjection, csm);
 }
コード例 #9
0
 public void ApplyPostprocess(MyPostprocessShadows.Type type, IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm,
     ref MyShadowsSettings settings)
 {
     MyPostprocessShadows postprocess = null;
     switch (type)
     {
         case MyPostprocessShadows.Type.HARD:
             postprocess = m_postprocessHardShadows;
             break;
         case MyPostprocessShadows.Type.SIMPLE:
             postprocess = m_postprocessSimpleShadows;
             break;
         default:
             MyRenderProxy.Assert(false);
             break;
     }
     postprocess.Draw(outTex, stencil, csm, ref settings);
 }
コード例 #10
0
 public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm)
 {
     m_markCascades.MarkAllCascades(depthStencil, worldToProjection, csm);
 }
コード例 #11
0
        public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm)
        {
            MyRenderContext RC = MyRender11.RC;

            RC.ClearDsv(depthStencil, DepthStencilClearFlags.Stencil, 0, 0);

            for (int i = 0; i < csm.SlicesCount; i++)
            {
                MarkOneCascade(i, depthStencil, worldToProjection, csm.GetSlice(i));
            }
        }
コード例 #12
0
        public MyShadowManager()
        {
            m_mainCsm = ShadowCore.CreateCsm(2048, 7);
            m_mainCsm.CsmPlacementStrategy = new MyCsmRigidPlacementStrategy();

        }
コード例 #13
0
ファイル: MyShadowManager.cs プロジェクト: viktorius/Viktor
 public MyShadowManager()
 {
     m_mainCsm = ShadowCore.CreateCsm(2048, 7);
     m_mainCsm.CsmPlacementStrategy = new MyCsmRigidPlacementStrategy();
 }
コード例 #14
0
        public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm)
        {
            MyRenderContext RC = MyRender11.RC;

            RC.ClearDsv(depthStencil, DepthStencilClearFlags.Stencil, 0, 0);

            for (int i = 0; i < csm.SlicesCount; i++)
            {
                MarkOneCascade(i, depthStencil, worldToProjection, csm.GetSlice(i));
            }
        }