Esempio n. 1
0
        internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth)
        {
            RC.Context.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.stream.Write(Params.MinRadius);
            mapping.stream.Write(Params.MaxRadius);
            mapping.stream.Write(Params.RadiusGrow);
            mapping.stream.Write(Params.Falloff);
            mapping.stream.Write(Params.RadiusBias);
            mapping.stream.Write(Params.Contrast);
            mapping.stream.Write(Params.Normalization);
            mapping.stream.Write(0);
            FillRandomVectors(mapping.stream);
            mapping.Unmap();

            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, paramsCB);

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

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

            DrawFullscreenQuad();
        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        internal static void SSGrass(MyBindableResource destination,
                                     MyBindableResource depth, MyBindableResource source, MyBindableResource gbuffer2)
        {
            var context = MyRender.Context;

            var cbuffer = MyCommon.GetObjectBuffer(16);
            var mapping = MyMapping.MapDiscard(cbuffer.Buffer);

            mapping.stream.Write(MyRender.Settings.GrassPostprocessCloseDistance);
            mapping.Unmap();

            context.PixelShader.SetConstantBuffer(1, cbuffer.Buffer);

            context.OutputMerger.BlendState = null;
            context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.VertexShader.Set(FullscreenShader.VertexShader);
            context.PixelShader.Set(SSGrassShader.PixelShader);

            //var array = new ShaderResourceView[] { depth, resource, MyRender.MainGbuffer.Gbuffers[2].ShaderView };
            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResources(0, array);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, depth, source, gbuffer2);

            context.Draw(3, 0);
        }
Esempio n. 4
0
 internal static void Run(MyBindableResource dst, MyBindableResource src)
 {
     RC.SetPS(m_ps);
     RC.BindDepthRT(dst, DepthStencilAccess.ReadWrite, null);
     RC.BindSRV(0, src);
     DrawFullscreenQuad();
 }
        /// <summary>
        /// Render depth and normals of windows to the specified target
        /// REMARK: Only on the windows with decals
        /// </summary>
        /// <returns>True if windows to be rendered found</returns>
        internal static bool RenderWindowsDepthOnly(MyDepthStencil depthStencil, MyBindableResource gbuffer1)
        {
            if (m_windowCount == 0)
            {
                return(false);
            }

            TransferDataBillboards(WindowCountSafe, ref m_arrayDataWindows);

            RC.BindDepthRT(depthStencil, DepthStencilAccess.ReadWrite, gbuffer1);
            BindResourcesCommon();

            RC.SetBS(null);
            RC.SetVS(m_vsDepthOnly);
            RC.SetPS(m_psDepthOnly);


            if (!MyStereoRender.Enable)
            {
                RC.DeviceContext.DrawIndexed(m_windowCount * 6, 0, 0);
            }
            else
            {
                MyStereoRender.DrawIndexedBillboards(RC, m_windowCount * 6, 0, 0);
            }

            RC.SetRS(null);
            return(true);
        }
Esempio n. 6
0
 internal static void RunFullscreenSampleFreq(MyBindableResource RT)
 {
     Debug.Assert(MyRender11.MultisamplingEnabled);
     RC.SetDS(MyDepthStencilState.TestEdgeStencil, 0x80);
     RC.BindDepthRT(MyGBuffer.Main.Get(MyGbufferSlot.DepthStencil), DepthStencilAccess.ReadOnly, RT);
     DrawFullscreenQuad();
     RC.SetDS(MyDepthStencilState.DefaultDepthState);
 }
Esempio n. 7
0
 internal static void ResolveOIT(MyUnorderedAccessTexture accumTarget, MyUnorderedAccessTexture coverageTarget)
 {
     RC.SetBS(MyRender11.BlendInvTransparent);
     RC.SetPS(m_psResolve);
     RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
     RC.BindSRV(0, accumTarget);
     RC.BindSRV(1, coverageTarget);
     MyScreenPass.DrawFullscreenQuad(null);
 }
Esempio n. 8
0
 internal static void Run()
 {
     RC.SetDS(MyDepthStencilState.MarkAAEdge, 0xFF);
     RC.SetPS(m_ps);
     RC.BindDepthRT(MyGBuffer.Main.Get(MyGbufferSlot.DepthStencil), DepthStencilAccess.DepthReadOnly, null);
     RC.BindGBufferForReadSkipStencil(0, MyGBuffer.Main);
     DrawFullscreenQuad();
     RC.SetDS(null);
 }
        internal sealed override void Begin()
        {
            base.Begin();

            Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            RC.SetGS(m_geometryShader);
            RC.SetPS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, null);
        }
Esempio n. 10
0
        internal static unsafe void MarkCascadesInStencil()
        {
            //RC.SetRS(MyRasterizerState.CullCW);

            RC.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            RC.SetVB(0, m_cascadesBoundingsVertices.Buffer, m_cascadesBoundingsVertices.Stride);
            RC.SetIB(m_cubeIB.Buffer, m_cubeIB.Format);
            RC.SetIL(m_inputLayout);
            RC.Context.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.DepthReadOnly);
            RC.SetVS(m_markVS);
            RC.SetPS(m_markPS);

            var verticesCS = new Vector3D[8] {
                new Vector3D(-1, -1, 0),
                new Vector3D(-1, 1, 0),
                new Vector3D(1, 1, 0),
                new Vector3D(1, -1, 0),

                new Vector3D(-1, -1, 1),
                new Vector3D(-1, 1, 1),
                new Vector3D(1, 1, 1),
                new Vector3D(1, -1, 1)
            };
            var verticesLS = new Vector3D[8];

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

            for (int c = 0; c < m_initializedShadowCascadesCount; c++)
            {
                var inverseViewProj = MatrixD.Invert(m_cascadeInfo[c].CurrentLocalToProjection);
                Vector3D.Transform(verticesCS, ref inverseViewProj, verticesLS);
                Vector3[] verticesF = new Vector3[8];
                for (int i = 0; i < 8; i++)
                {
                    verticesF[i] = verticesLS[i];
                }

                fixed(Vector3 *V = verticesF)
                {
                    mapping.stream.Write(new IntPtr(V), 0, 8 * sizeof(Vector3));
                }
            }
            mapping.Unmap();

            for (int i = 0; i < m_initializedShadowCascadesCount; i++)
            {
                RC.SetDS(MyDepthStencilState.MarkIfInsideCascade[i], 1 << i);
                // mark ith bit on depth near
                RC.Context.DrawIndexed(36, 0, 8 * i);
            }
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly);

            RC.SetDS(null);
            RC.SetRS(null);
        }
Esempio n. 11
0
        internal static void Run(MyBindableResource dst, MyBindableResource src, BlendState bs = null)
        {
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, dst);
            RC.BindSRV(0, src);
            RC.SetPS(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Esempio n. 12
0
        internal static void RunWithStencil(MyBindableResource destinationResource, MyBindableResource sourceResource, BlendState blendState, DepthStencilState depthStencilState, int stencilMask)
        {
            RC.SetDS(depthStencilState, stencilMask);
            RC.SetBS(blendState);
            RC.SetRS(null);
            RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.ReadOnly, destinationResource);
            RC.BindSRV(0, sourceResource);
            RC.SetPS(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Esempio n. 13
0
        internal static void RunWithStencil(MyBindableResource dst, MyBindableResource src, BlendState bs = null)
        {
            RC.SetDS(MyDepthStencilState.TestOutlineMeshStencil, 0x40);
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.ReadOnly, dst);
            RC.BindSRV(0, src);
            RC.SetPS(m_ps);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
        internal static void Run(MyBindableResource dst, MyBindableResource src)
        {
            //RC.SetBS(MyRender.BlendStateAdditive);
            RC.SetBS(MyRender11.BlendAlphaPremult);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, dst);
            RC.BindSRV(0, src);
            RC.SetPS(m_ps);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Esempio n. 15
0
        internal static void RunWithPixelStencilTest(MyBindableResource dst, MyBindableResource src, BlendState bs = null)
        {
            RC.SetDS(null);
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
            RC.BindSRV(0, src);
            RC.BindSRV(1, MyGBuffer.Main.DepthStencil.Stencil);
            RC.SetPS(m_psPixelStencil);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Esempio n. 16
0
 internal static void RunFullscreenPixelFreq(params MyBindableResource [] RTs)
 {
     if (MyRender11.MultisamplingEnabled)
     {
         RC.SetDS(MyDepthStencilState.TestAAEdge, 0);
     }
     RC.BindDepthRT(MyGBuffer.Main.Get(MyGbufferSlot.DepthStencil), DepthStencilAccess.ReadOnly, RTs);
     DrawFullscreenQuad();
     if (MyRender11.MultisamplingEnabled)
     {
         RC.SetDS(MyDepthStencilState.DefaultDepthState);
     }
 }
        internal static void SetupStandard()
        {
            RC.SetupScreenViewport();
            RC.SetBS(MyRender11.BlendAlphaPremult);

            if (MyRender11.MultisamplingEnabled)
            {
                RC.BindDepthRT(MyScreenDependants.m_resolvedDepth, DepthStencilAccess.ReadOnly, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            }
            else
            {
                RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.ReadOnly, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            }
        }
Esempio n. 18
0
        internal static void Run(MyBindableResource destination, MyBindableResource source)
        {
            var context = MyRender11.DeviceContext;

            context.OutputMerger.BlendState = null;

            RC.SetIL(null);
            context.PixelShader.Set(m_ps);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, source);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.GetSize().X, destination.GetSize().Y));
        }
Esempio n. 19
0
        internal static void ClearAlpha(MyBindableResource destination)
        {
            var context = MyRender11.DeviceContext;

            context.OutputMerger.BlendState = MyRender11.BlendAdditive;

            context.InputAssembler.InputLayout = null;
            context.PixelShader.Set(m_clearAlphaPs);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.GetSize().X, destination.GetSize().Y));

            context.OutputMerger.BlendState = null;
        }
Esempio n. 20
0
        internal static void SetupOIT(MyUnorderedAccessTexture accumTarget, MyUnorderedAccessTexture coverageTarget)
        {
            RC.SetupScreenViewport();
            RC.SetBS(MyRender11.BlendWeightedTransparency);
            MyRender11.DeviceContext.ClearRenderTargetView(accumTarget.m_RTV, SharpDX.Color4.Black);
            MyRender11.DeviceContext.ClearRenderTargetView(coverageTarget.m_RTV, SharpDX.Color4.White);

            if (MyRender11.MultisamplingEnabled)
            {
                RC.BindDepthRT(MyScreenDependants.m_resolvedDepth, DepthStencilAccess.ReadOnly, accumTarget, coverageTarget);
            }
            else
            {
                RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.ReadOnly, accumTarget, coverageTarget);
            }
        }
Esempio n. 21
0
        internal static void Draw(MyBindableResource depth)
        {
            RC.SetupScreenViewport();
            RC.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            RC.SetIL(m_inputLayout);

            RC.SetRS(MyRender11.m_nocullRasterizerState);
            RC.SetDS(MyDepthStencilState.DefaultDepthState);

            RC.SetVS(m_vs);
            RC.SetPS(m_ps);

            RC.BindDepthRT(depth, DepthStencilAccess.ReadOnly, MyRender11.Backbuffer);

            RC.SetCB(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            RC.SetBS(MyRender11.BlendTransparent);

            SortTransparent();
            var mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);

            mapping.stream.Write(Matrix.Transpose(MyEnvironment.ViewProjectionAt0));
            mapping.Unmap();

            CheckBufferSize(m_vertexList.Count);

            RC.SetVB(0, m_VB.Buffer, m_VB.Stride);

            DataStream stream;

            RC.Context.MapSubresource(m_VB.Buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
            for (int i = 0; i < m_vertexList.Count; i++)
            {
                stream.Write(m_vertexList[i]);
            }
            RC.Context.UnmapSubresource(m_VB.Buffer, 0);
            stream.Dispose();

            RC.Context.Draw(m_vertexList.Count, 0);

            RC.SetBS(null);

            m_vertexList.Clear();
            m_postSortVertexList.Clear();
            m_triangleSortDistance.Clear();
            m_sortedIndices.Clear();
        }
Esempio n. 22
0
        internal static void Run(MyBindableResource destination, MyBindableResource source)
        {
            var context = MyRender11.Context;

            context.OutputMerger.BlendState = null;
            //context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.InputAssembler.InputLayout = null;
            context.PixelShader.Set(m_copyPs);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResource(0, resource);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, source);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.GetSize().X, destination.GetSize().Y));
        }
Esempio n. 23
0
        internal static void Copy(MyBindableResource destination, MyBindableResource source)
        {
            var context = MyRender.Context;

            context.OutputMerger.BlendState = null;
            context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.InputAssembler.InputLayout = null;
            context.VertexShader.Set(FullscreenShader.VertexShader);
            context.PixelShader.Set(CopyShader.PixelShader);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResource(0, resource);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, source);

            context.Draw(3, 0);
        }
Esempio n. 24
0
        internal static void RunWithPixelStencilTest(MyBindableResource dst, MyBindableResource src, BlendState bs = null, bool inverseTest = false)
        {
            RC.SetDS(null);
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
            RC.BindSRV(0, src);
            RC.BindSRV(1, MyGBuffer.Main.DepthStencil.Stencil);
            if (!inverseTest)
            {
                RC.SetPS(m_stencilTestPixelShader);
            }
            else
            {
                RC.SetPS(m_stencilInverseTestPixelShader);
            }

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Esempio n. 25
0
        internal static void Run(MyBindableResource dst1, MyBindableResource dst2, MyBindableResource lightBuffer, MyGBuffer gbuffer)
        {
            if (!Settings.BlurEnabled || Settings.BlurAmount < 0.01f)
            {
                return;
            }

            RC.DeviceContext.ClearRenderTargetView((dst1 as IRenderTargetBindable).RTV, new SharpDX.Color4(0, 0, 0, 0));
            RC.DeviceContext.ClearRenderTargetView((dst2 as IRenderTargetBindable).RTV, new SharpDX.Color4(0, 0, 0, 0));

            float zero    = 0f;
            var   mapping = MyMapping.MapDiscard(m_cb);

            mapping.WriteAndPosition(ref Settings.BlurAmount);
            mapping.WriteAndPosition(ref Settings.BlurDistance);
            mapping.WriteAndPosition(ref Settings.BlurTransitionRatio);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, m_cb);


            RC.SetPS(m_psH);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst1);
            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, lightBuffer);
            DrawFullscreenQuad();


            RC.SetPS(m_psV);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst2);
            RC.BindSRV(5, dst1);

            DrawFullscreenQuad();

//          MyBlendTargets.Run(lightBuffer, MyScreenDependants.m_planetBlur2, MyRender11.BlendPlanetBlur);
//          MyBlendTargets.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyScreenDependants.m_planetBlur2, MyRender11.BlendPlanetBlur);
        }
Esempio n. 26
0
        internal static void DrawSkybox(MyBindableResource destination)
        {
            var context = MyRender.Context;

            context.OutputMerger.BlendState = null;
            context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.PixelShader.SetSamplers(0, MyRender.StandardSamplers);

            context.VertexShader.Set(FullscreenShader.VertexShader);
            context.PixelShader.Set(SkyboxShader.PixelShader);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindGBufferForRead(0, MyGBuffer.Main);

            //context.PixelShader.SetShaderResources(0, MyRender.MainGbuffer.DepthGbufferViews);
            context.PixelShader.SetShaderResource(MyCommon.SKYBOX_SLOT,
                                                  MyTextureManager.GetTexture(MyEnvironment.SkyboxTexture).ShaderView);

            context.Draw(3, 0);

            context.PixelShader.SetShaderResource(0, null);
        }
Esempio n. 27
0
        internal unsafe static void RenderSpotlights()
        {
            RC.BindDepthRT(MyGBuffer.Main.Get(MyGbufferSlot.DepthStencil), DepthStencilAccess.ReadOnly, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            RC.DeviceContext.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.DeviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            var coneMesh = MyMeshes.GetMeshId(X.TEXT("Models/Debug/Cone.mwm"));
            var buffers  = MyMeshes.GetLodMesh(coneMesh, 0).Buffers;

            RC.SetVB(0, buffers.VB0.Buffer, buffers.VB0.Stride);
            RC.SetIB(buffers.IB.Buffer, buffers.IB.Format);

            RC.SetVS(SpotlightProxyVs);
            RC.SetIL(SpotlightProxyIL);

            RC.SetRS(MyRender11.m_invTriRasterizerState);

            var cb = MyCommon.GetObjectCB(sizeof(SpotlightConstants));

            RC.SetCB(1, cb);
            RC.DeviceContext.PixelShader.SetSampler(13, MyRender11.m_alphamaskSamplerState);
            RC.DeviceContext.PixelShader.SetSampler(14, MyRender11.m_shadowmapSamplerState);
            RC.DeviceContext.PixelShader.SetSampler(15, MyRender11.m_shadowmapSamplerState);

            int index       = 0;
            int casterIndex = 0;

            foreach (var id in VisibleSpotlights)
            {
                MyLights.WriteSpotlightConstants(id, ref Spotlights[index]);

                var mapping = MyMapping.MapDiscard(cb);
                mapping.WriteAndPosition(ref Spotlights[index]);
                mapping.Unmap();

                RC.DeviceContext.PixelShader.SetShaderResource(13, MyTextures.GetView(MyLights.Spotlights[id.Index].ReflectorTexture));

                if (id.CastsShadowsThisFrame)
                {
                    RC.DeviceContext.PixelShader.SetShaderResource(14, MyRender11.DynamicShadows.ShadowmapsPool[casterIndex].ShaderView);
                    casterIndex++;
                }

                RC.SetPS(SpotlightPs_Pixel);
                if (MyRender11.MultisamplingEnabled)
                {
                    RC.SetDS(MyDepthStencilState.TestEdgeStencil, 0);
                }
                RC.DeviceContext.DrawIndexed(MyMeshes.GetLodMesh(coneMesh, 0).Info.IndicesNum, 0, 0);

                if (MyRender11.MultisamplingEnabled)
                {
                    RC.SetPS(SpotlightPs_Sample);
                    RC.SetDS(MyDepthStencilState.TestEdgeStencil, 0x80);
                    RC.DeviceContext.DrawIndexed(MyMeshes.GetLodMesh(coneMesh, 0).Info.IndicesNum, 0, 0);
                }

                index++;
                if (index >= SPOTLIGHTS_MAX)
                {
                    break;
                }
            }

            if (MyRender11.MultisamplingEnabled)
            {
                RC.SetDS(MyDepthStencilState.DefaultDepthState);
            }

            RC.SetRS(null);
        }
Esempio n. 28
0
        // viewport, render target
        internal unsafe static void Draw(RenderTargetView rtv, MyViewport viewport)
        {
            if (StackTop().m_internalBatch.Texture != null && StackTop().m_internalBatch.Count > 0)
            {
                StackTop().m_internalBatch.Commit();
            }
            StackTop().m_internalBatch = new MySpritesBatch();

            RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;

            RC.SetIL(m_inputLayout);
            //RC.SetupScreenViewport();
            RC.DeviceContext.Rasterizer.SetViewport(viewport.OffsetX, viewport.OffsetY, viewport.Width, viewport.Height);

            RC.SetVS(m_vs);
            RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.SetCB(MyCommon.PROJECTION_SLOT, MyCommon.GetObjectCB(64));
            RC.SetPS(m_ps);
            RC.DeviceContext.PixelShader.SetSamplers(0, MyRender11.StandardSamplers);

            //RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, MyRender11.Backbuffer);
            // to reset state
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, null);
            RC.DeviceContext.OutputMerger.SetRenderTargets(rtv);

            RC.SetBS(MyRender11.BlendGui);

            CheckBufferSize(StackTop().m_instances.Count);
            RC.SetVB(0, m_VB.Buffer, m_VB.Stride);

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

            for (int i = 0; i < StackTop().m_instances.Count; i++)
            {
                var helper = StackTop().m_instances[i];
                mapping.WriteAndPosition(ref helper);
            }
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(64));
            var viewportSize = new Vector2(viewport.Width, viewport.Height);

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

            foreach (var batch in StackTop().m_batches)
            {
                if (batch.ScissorRectangle.HasValue)
                {
                    RC.SetRS(MyRender11.m_scissorTestRasterizerState);

                    var scissor = batch.ScissorRectangle.Value;
                    RC.DeviceContext.Rasterizer.SetScissorRectangle((int)scissor.X, (int)scissor.Y, (int)(scissor.X + scissor.Width), (int)(scissor.Y + scissor.Height));
                }
                else
                {
                    RC.SetRS(MyRender11.m_nocullRasterizerState);
                }

                RC.BindRawSRV(0, batch.Texture);
                RC.DeviceContext.DrawInstanced(4, batch.Count, 0, batch.Start);
            }

            RC.SetBS(null);
            RC.SetRS(null);

            StackTop().m_instances.Clear();
            StackTop().m_batches.Clear();
        }
Esempio n. 29
0
        internal static void Draw(MyBindableResource renderTarget)
        {
            var context = RC.DeviceContext;

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            context.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, renderTarget);
            RC.BindGBufferForRead(0, MyGBuffer.Main);

            //context.OutputMerger.SetTargets(null as DepthStencilView, MyRender.Backbuffer.RenderTarget);

            //context.PixelShader.SetShaderResources(0, MyRender.MainGbuffer.DepthGbufferViews);

            context.OutputMerger.BlendState = null;

            RC.SetVS(null);
            RC.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding());
            RC.DeviceContext.InputAssembler.InputLayout = null;

            if (MyRender11.Settings.DisplayGbufferColor)
            {
                context.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            if (MyRender11.Settings.DisplayGbufferColorLinear)
            {
                context.PixelShader.Set(m_baseColorLinearShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormal)
            {
                context.PixelShader.Set(m_normalShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferGlossiness)
            {
                context.PixelShader.Set(m_glossinessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMetalness)
            {
                context.PixelShader.Set(m_metalnessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMaterialID)
            {
                context.PixelShader.Set(m_matIDShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAO)
            {
                context.PixelShader.Set(m_aoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEmissive)
            {
                context.PixelShader.Set(m_emissiveShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientDiffuse)
            {
                context.PixelShader.Set(m_ambientDiffuseShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientSpecular)
            {
                context.PixelShader.Set(m_ambientSpecularShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEdgeMask)
            {
                context.PixelShader.Set(m_edgeDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayShadowsWithDebug)
            {
                context.PixelShader.Set(m_shadowsDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayNDotL)
            {
                context.PixelShader.Set(m_NDotLShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayStencil)
            {
                context.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
                context.PixelShader.Set(m_stencilShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            //DrawEnvProbe();
            //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);
            //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);

            if (MyRender11.Settings.DrawCascadeTextures)
            {
                DrawCascades(MyRender11.DynamicShadows.ShadowCascades, 100, 100, 200);
                if (MyScene.SeparateGeometry)
                {
                    DrawCascades(MyRender11.StaticShadows.ShadowCascades, 100, 300, 200);
                    DrawCombinedCascades(100, 500, 200);
                }
            }

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

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

                foreach (var light in MyLightRendering.VisiblePointlights)
                {
                    batch.AddSphereRing(new BoundingSphere(light.Position, 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 - MyEnvironment.CameraPosition,renderable.m_owner.Aabb.Max - MyEnvironment.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 (MyRender11.Settings.EnableVoxelMerging && MyRender11.Settings.DebugRenderMergedCells)
            {
                MyClipmap.DebugDrawMergedCells();
            }

            //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();
            }
        }
Esempio n. 30
0
        internal static unsafe void Draw(MyBindableResource renderTarget, MyBindableResource depth)
        {
            RC.SetupScreenViewport();
            RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            RC.SetIL(m_inputLayout);

            RC.SetRS(MyRender11.m_linesRasterizerState);

            RC.SetVS(m_vs);
            RC.SetPS(m_ps);

            RC.SetDS(MyDepthStencilState.DefaultDepthState);

            CheckBufferSize(m_vertices.Count);
            RC.SetVB(0, m_VB.Buffer, m_VB.Stride);

            RC.BindDepthRT(depth, DepthStencilAccess.ReadOnly, renderTarget);

            RC.SetCB(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            if (m_batches.Count > 0)
            {
                var mapping = MyMapping.MapDiscard(m_VB.Buffer);
                mapping.WriteAndPosition(m_vertices.GetInternalArray(), 0, m_vertices.Count);
                mapping.Unmap();

                Matrix prevMatrix = Matrix.Zero;
                foreach (var batch in m_batches)
                {
                    Matrix matrix;
                    if (batch.CustomViewProjection.HasValue)
                    {
                        matrix = batch.CustomViewProjection.Value;
                    }
                    else
                    {
                        matrix = MyEnvironment.ViewProjectionAt0;
                    }

                    if (prevMatrix != matrix)
                    {
                        prevMatrix = matrix;
                        var transpose = Matrix.Transpose(matrix);

                        mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);
                        mapping.WriteAndPosition(ref transpose);
                        mapping.Unmap();
                    }

                    if (batch.IgnoreDepth)
                    {
                        RC.SetDS(MyDepthStencilState.IgnoreDepthStencil);
                    }
                    else
                    {
                        RC.SetDS(MyDepthStencilState.DefaultDepthState);
                    }

                    RC.DeviceContext.Draw(batch.VertexCount, batch.StartVertex);
                }
            }

            RC.SetDS(null);
            RC.SetRS(null);

            m_vertices.Clear();

            foreach (var batch in m_batches)
            {
                m_batchesPool.Deallocate(batch);
            }
            m_batches.Clear();
        }