コード例 #1
0
        public void DrawCoverage(IRtvTexture outTex, IDepthStencil depthStencil)
        {
            MyRenderContext RC = MyRender11.RC;

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

            RC.PixelShader.Set(m_psDrawCoverage);
            RC.PixelShader.SetSrv(1, depthStencil.SrvStencil);

            MyScreenPass.DrawFullscreenQuad();
            RC.ResetTargets();
        }
コード例 #2
0
        public void CopyRedToAll(IRtvBindable output, ISrvTexture source)
        {
            MyRenderContext RC = MyRender11.RC;

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

            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, source);
            MyScreenPass.DrawFullscreenQuad();

            RC.ResetTargets();
        }
コード例 #3
0
        public static void Draw(IRtvBindable renderTarget)
        {
            ISrvBindable srvBind = null;

            if (m_selRtvTexture != null)
            {
                srvBind = m_selRtvTexture;
            }
            if (m_selUavTexture != null)
            {
                srvBind = m_selUavTexture;
            }
            if (m_selBorrowedRtvTexture != null)
            {
                srvBind = m_selBorrowedRtvTexture;
            }
            if (m_selBorrowedUavTexture != null)
            {
                srvBind = m_selBorrowedUavTexture;
            }

            if (srvBind == null) // no texture is selected
            {
                return;
            }

            if (m_ps == PixelShaderId.NULL)
            {
                m_ps = MyShaders.CreatePs("Debug/DebugRt.hlsl");
            }

            MyRenderContext RC = MyImmediateRC.RC;

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.SetRtv(renderTarget);
            RC.SetBlendState(null);
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, srvBind);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            MyScreenPass.DrawFullscreenQuad();

            Deselect();
        }
コード例 #4
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();
        }
コード例 #5
0
        internal static void RenderColoredTextures(List <renderColoredTextureProperties> texturesToRender)
        {
            if (texturesToRender.Count == 0)
            {
                return;
            }

            if (!m_initialized)
            {
                Init();
            }

            const int RENDER_TEXTURE_RESOLUTION = 512;

            RC.SetBlendState(null);
            RC.SetInputLayout(null);

            RC.PixelShader.Set(m_ps);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(1, m_cb);

            MyBorrowedRwTextureManager rwTexManager   = MyManagers.RwTexturesPool;
            MyFileTextureManager       fileTexManager = MyManagers.FileTextures;

            foreach (var texture in texturesToRender)
            {
                ISrvBindable tex = fileTexManager.GetTexture(texture.TextureName, MyFileTextureEnum.COLOR_METAL, true);
                if (tex == null)
                {
                    continue;
                }

                Vector2  texSize = tex.Size;
                Vector2I renderTargetResolution = new Vector2I(RENDER_TEXTURE_RESOLUTION, RENDER_TEXTURE_RESOLUTION);
                if (texSize.Y > 0)
                {
                    if (texSize.Y < RENDER_TEXTURE_RESOLUTION)
                    {
                        renderTargetResolution.X = (int)texSize.X;
                        renderTargetResolution.Y = (int)texSize.Y;
                    }
                    else
                    {
                        renderTargetResolution.X *= (int)(texSize.X / texSize.Y);
                    }
                }

                MyViewport viewport = new MyViewport(renderTargetResolution.X, renderTargetResolution.Y);

                IBorrowedRtvTexture renderTexture = rwTexManager.BorrowRtv("MySaveExportedTextures.RenderColoredTextures",
                                                                           renderTargetResolution.X, renderTargetResolution.Y, SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, 1, 0);

                RC.SetRtv(renderTexture);

                // Set color
                var     mapping = MyMapping.MapDiscard(m_cb);
                Vector4 color   = new Vector4(texture.ColorMaskHSV, 1);
                mapping.WriteAndPosition(ref color);
                mapping.Unmap();

                // Set texture
                RC.PixelShader.SetSrv(0, tex);

                // Draw
                MyScreenPass.DrawFullscreenQuad(viewport);

                // Save to file
                MyTextureData.ToFile(renderTexture, texture.PathToSave, ImageFileFormat.Png);

                renderTexture.Release();
            }

            texturesToRender.Clear();

            RC.SetRtv(null);
            RC.PixelShader.SetSrvs(0, MyGBuffer.Main);
        }
コード例 #6
0
        internal static void RenderColoredTextures(List <renderColoredTextureProperties> texturesToRender)
        {
            if (texturesToRender.Count == 0)
            {
                return;
            }

            if (!m_initialized)
            {
                Init();
            }

            const int RENDER_TEXTURE_RESOLUTION = 512;

            RC.DeviceContext.OutputMerger.BlendState = null;
            RC.SetIL(null);

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

            Dictionary <Vector2I, MyRenderTarget> createdRenderTextureTargets = new Dictionary <Vector2I, MyRenderTarget>();

            foreach (var texture in texturesToRender)
            {
                TexId texId = MyTextures.GetTexture(texture.TextureName, MyTextureEnum.COLOR_METAL, true);
                if (texId == TexId.NULL)
                {
                    continue;
                }

                Vector2  texSize = MyTextures.GetSize(texId);
                Vector2I renderTargetResolution = new Vector2I(RENDER_TEXTURE_RESOLUTION, RENDER_TEXTURE_RESOLUTION);
                if (texSize.Y > 0)
                {
                    if (texSize.Y < RENDER_TEXTURE_RESOLUTION)
                    {
                        renderTargetResolution.X = (int)texSize.X;
                        renderTargetResolution.Y = (int)texSize.Y;
                    }
                    else
                    {
                        renderTargetResolution.X *= (int)(texSize.X / texSize.Y);
                    }
                }

                MyViewport viewport = new MyViewport(renderTargetResolution.X, renderTargetResolution.Y);

                MyRenderTarget renderTexture = null;
                if (!createdRenderTextureTargets.TryGetValue(renderTargetResolution, out renderTexture))
                {
                    renderTexture = new MyRenderTarget(renderTargetResolution.X, renderTargetResolution.Y, SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, 1, 0);
                    createdRenderTextureTargets[renderTargetResolution] = renderTexture;
                }

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

                // Set color
                var     mapping = MyMapping.MapDiscard(m_cb);
                Vector4 color   = new Vector4(texture.ColorMaskHSV, 1);
                mapping.WriteAndPosition(ref color);
                mapping.Unmap();

                // Set texture
                RC.DeviceContext.PixelShader.SetShaderResource(0, MyTextures.GetView(texId));

                // Draw
                MyScreenPass.DrawFullscreenQuad(viewport);

                // Save to file
                MyTextureData.ToFile(renderTexture.GetHWResource(), texture.PathToSave, ImageFileFormat.Png);
            }

            texturesToRender.Clear();

            foreach (var texture in createdRenderTextureTargets)
            {
                texture.Value.Release();
            }
            createdRenderTextureTargets.Clear();

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