Ejemplo n.º 1
0
        internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth)
        {
            RC.DeviceContext.ClearRenderTargetView((dst as IRenderTargetBindable).RTV, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.WriteAndPosition(ref Params);
            FillRandomVectors(mapping);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.SetCB(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(RC);
            }
            RC.SetCB(1, paramsCB);

            RC.SetPS(m_ps);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst);

            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, resolvedDepth);

            DrawFullscreenQuad();
        }
Ejemplo n.º 2
0
        internal static void Run(IRtvBindable dst, MyGBuffer gbuffer, ISrvBindable resolvedDepth)
        {
            RC.ClearRtv(dst, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.WriteAndPosition(ref Params.Data);
            FillRandomVectors(mapping);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(RC);
            }
            RC.AllShaderStages.SetConstantBuffer(1, paramsCB);

            RC.PixelShader.Set(m_ps);
            RC.SetRtv(dst);

            RC.PixelShader.SetSrvs(0, gbuffer);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetSrv(5, resolvedDepth);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);

            DrawFullscreenQuad();
            RC.ResetTargets();
        }
Ejemplo n.º 3
0
        unsafe static void DrawInternal(bool transparent, uint sinceStartTs)
        {
            var RC      = MyImmediateRC.RC;
            int nPasses = MyStereoRender.Enable ? 2 : 1;

            for (int i = 0; i < nPasses; i++)
            {
                if (!MyStereoRender.Enable)
                {
                    RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
                    RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
                }
                else
                {
                    MyStereoRender.RenderRegion = i == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT;
                    MyStereoRender.BindRawCB_FrameConstants(RC);
                    MyStereoRender.SetViewport(RC);
                }

                RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
                RC.SetIndexBuffer(m_IB.Buffer, m_IB.Format);
                RC.SetInputLayout(null);

                RC.VertexShader.Set(m_vs);
                RC.SetDepthStencilState(MyDepthStencilStateManager.DepthTestReadOnly);
                RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

                var decalCb = MyCommon.GetObjectCB(sizeof(MyDecalConstants) * DECAL_BATCH_SIZE);
                RC.AllShaderStages.SetConstantBuffer(2, decalCb);

                foreach (var pair in m_materialsToDraw)
                {
                    PrepareMaterialBatches(RC, pair.Value, sinceStartTs);
                    DrawBatches(RC, pair.Key.Material, pair.Key.Index, transparent);
                    m_jobs.Clear();
                }
            }

            // Clear materials to draw outside eye rendering passes
            foreach (var pair in m_materialsToDraw)
            {
                pair.Value.Clear();
            }

            RC.SetBlendState(null);
            RC.PixelShader.SetSrv(0, null);

            if (MyStereoRender.Enable)
            {
                RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
                RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
                MyStereoRender.RenderRegion = MyStereoRegion.FULLSCREEN;
            }
        }
Ejemplo n.º 4
0
        private unsafe void MarkCascadesInStencil(MyProjectionInfo[] cascadeInfo)
        {
            MyGpuProfiler.IC_BeginBlock("MarkCascadesInStencil");

            //RC.SetRS(MyRasterizerState.CullCW);

            MyRenderContext renderContext = MyRenderContext.Immediate;

            renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            renderContext.SetVB(0, m_cascadesBoundingsVertices.Buffer, m_cascadesBoundingsVertices.Stride);
            renderContext.SetIB(m_cubeIB.Buffer, m_cubeIB.Format);
            renderContext.SetIL(m_inputLayout);
            renderContext.DeviceContext.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            if (!MyStereoRender.Enable)
            {
                renderContext.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(renderContext);
            }
            renderContext.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.DepthReadOnly, null);
            renderContext.SetVS(m_markVS);
            renderContext.SetPS(m_markPS);

            const int vertexCount = 8;

            Vector3D *frustumVerticesSS = stackalloc Vector3D[vertexCount];

            frustumVerticesSS[0] = new Vector3D(-1, -1, 0);
            frustumVerticesSS[1] = new Vector3D(-1, 1, 0);
            frustumVerticesSS[2] = new Vector3D(1, 1, 0);
            frustumVerticesSS[3] = new Vector3D(1, -1, 0);
            frustumVerticesSS[4] = new Vector3D(-1, -1, 1);
            frustumVerticesSS[5] = new Vector3D(-1, 1, 1);
            frustumVerticesSS[6] = new Vector3D(1, 1, 1);
            frustumVerticesSS[7] = new Vector3D(1, -1, 1);

            Vector3D *lightVertices    = stackalloc Vector3D[vertexCount];
            Vector3 * tmpFloatVertices = stackalloc Vector3[vertexCount];

            var mapping = MyMapping.MapDiscard(m_cascadesBoundingsVertices.Buffer);

            for (int cascadeIndex = 0; cascadeIndex < MyRender11.Settings.ShadowCascadeCount; ++cascadeIndex)
            {
                var inverseViewProj = MatrixD.Invert(cascadeInfo[cascadeIndex].CurrentLocalToProjection);
                for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex)
                {
                    Vector3D.Transform(ref frustumVerticesSS[arrayIndex], ref inverseViewProj, out lightVertices[arrayIndex]);
                    tmpFloatVertices[arrayIndex] = lightVertices[arrayIndex];
                }

                for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex)
                {
                    mapping.WriteAndPosition(ref tmpFloatVertices[arrayIndex]);
                }
            }
            mapping.Unmap();

            if (MyStereoRender.Enable)
            {
                MyStereoRender.SetViewport(renderContext);
            }

            for (int cascadeIndex = 0; cascadeIndex < MyRender11.Settings.ShadowCascadeCount; ++cascadeIndex)
            {
                renderContext.SetDS(MyDepthStencilState.MarkIfInsideCascade[cascadeIndex], 0xf - cascadeIndex);
                // mark ith bit on depth near

                renderContext.DeviceContext.DrawIndexed(36, 0, 8 * cascadeIndex);
            }

            renderContext.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, null);

            renderContext.SetDS(MyDepthStencilState.DefaultDepthState);
            renderContext.SetRS(null);

            MyGpuProfiler.IC_EndBlock();
        }
        private unsafe void MarkCascadesInStencil(MyProjectionInfo[] cascadeInfo)
        {
            MyGpuProfiler.IC_BeginBlock("MarkCascadesInStencil");

            //RC.SetRS(MyRasterizerState.CullCW);

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetVertexBuffer(0, m_cascadesBoundingsVertices);
            RC.SetIndexBuffer(m_cubeIB);
            RC.SetInputLayout(m_inputLayout);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            if (!MyStereoRender.Enable)
            {
                RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(RC);
            }
            RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.DepthReadOnly);
            RC.VertexShader.Set(m_markVS);
            RC.PixelShader.Set(m_markPS);

            const int vertexCount = 8;

            Vector3D *frustumVerticesSS = stackalloc Vector3D[vertexCount];

            frustumVerticesSS[0] = new Vector3D(-1, -1, 0);
            frustumVerticesSS[1] = new Vector3D(-1, 1, 0);
            frustumVerticesSS[2] = new Vector3D(1, 1, 0);
            frustumVerticesSS[3] = new Vector3D(1, -1, 0);
            frustumVerticesSS[4] = new Vector3D(-1, -1, 1);
            frustumVerticesSS[5] = new Vector3D(-1, 1, 1);
            frustumVerticesSS[6] = new Vector3D(1, 1, 1);
            frustumVerticesSS[7] = new Vector3D(1, -1, 1);

            Vector3D *lightVertices    = stackalloc Vector3D[vertexCount];
            Vector3 * tmpFloatVertices = stackalloc Vector3[vertexCount];

            var mapping = MyMapping.MapDiscard(m_cascadesBoundingsVertices);

            for (int cascadeIndex = 0; cascadeIndex < MyShadowCascades.Settings.NewData.CascadesCount; ++cascadeIndex)
            {
                var inverseViewProj = MatrixD.Invert(cascadeInfo[cascadeIndex].CurrentLocalToProjection);
                for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex)
                {
                    Vector3D.Transform(ref frustumVerticesSS[arrayIndex], ref inverseViewProj, out lightVertices[arrayIndex]);
                    tmpFloatVertices[arrayIndex] = lightVertices[arrayIndex];
                }

                for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex)
                {
                    mapping.WriteAndPosition(ref tmpFloatVertices[arrayIndex]);
                }
            }
            mapping.Unmap();

            if (MyStereoRender.Enable)
            {
                MyStereoRender.SetViewport(RC);
            }

            for (int cascadeIndex = 0; cascadeIndex < MyShadowCascades.Settings.NewData.CascadesCount; ++cascadeIndex)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.MarkIfInsideCascade[cascadeIndex], 0xf - cascadeIndex);
                // mark ith bit on depth near

                RC.DrawIndexed(36, 0, 8 * cascadeIndex);
            }

            RC.SetRtv(null);

            RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
            RC.SetRasterizerState(null);

            MyGpuProfiler.IC_EndBlock();
        }