예제 #1
0
 internal void Remove(RTHandle rth)
 {
     m_AutoSizedRTs.Remove(rth);
 }
예제 #2
0
        // Internal function
        RTHandle AllocAutoSizedRenderTexture(
            int width,
            int height,
            int slices,
            DepthBits depthBufferBits,
            GraphicsFormat colorFormat,
            FilterMode filterMode,
            TextureWrapMode wrapMode,
            TextureDimension dimension,
            bool enableRandomWrite,
            bool useMipMap,
            bool autoGenerateMips,
            bool isShadowMap,
            int anisoLevel,
            float mipMapBias,
            bool enableMSAA,
            bool bindTextureMS,
            bool useDynamicScale,
            RenderTextureMemoryless memoryless,
            string name
            )
        {
            // Here user made a mistake in setting up msaa/bindMS, hence the warning
            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            bool allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false;

            // Here we purposefully disable MSAA so we just force the bindMS param to false.
            if (!allocForMSAA)
            {
                bindTextureMS = false;
            }

            // MSAA Does not support random read/write.
            bool UAV = enableRandomWrite;

            if (allocForMSAA && (UAV == true))
            {
                Debug.LogWarning("RTHandle that is MSAA-enabled cannot allocate MSAA RT with 'enableRandomWrite = true'.");
                UAV = false;
            }

            int msaaSamples = allocForMSAA ? (int)m_ScaledRTCurrentMSAASamples : 1;

            // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
            RenderTexture rt;

            if (isShadowMap || depthBufferBits != DepthBits.None)
            {
                RenderTextureFormat format        = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
                GraphicsFormat      stencilFormat = isShadowMap ? GraphicsFormat.None : GraphicsFormat.R8_UInt;
                rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = UAV,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    stencilFormat     = stencilFormat,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, colorFormat, name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
                };
            }
            else
            {
                rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = UAV,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, colorFormat, name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
                };
            }

            rt.Create();

            var rth = new RTHandle(this);

            rth.SetRenderTexture(rt);
            rth.m_EnableMSAA           = enableMSAA;
            rth.m_EnableRandomWrite    = enableRandomWrite;
            rth.useScaling             = true;
            rth.m_EnableHWDynamicScale = useDynamicScale;
            rth.m_Name = name;
            m_AutoSizedRTs.Add(rth);
            return(rth);
        }
예제 #3
0
 private static RTHandle Alloc(RTHandle tex)
 {
     Debug.LogError("Allocation a RTHandle from another one is forbidden.");
     return(null);
 }
예제 #4
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorBuffers, RTHandle depthBuffer, ClearFlag clearFlag, Color clearColor)
 {
     cmd.SetRenderTarget(colorBuffers, depthBuffer, 0, CubemapFace.Unknown, -1);
     SetViewportAndClear(cmd, depthBuffer, clearFlag, clearColor);
 }
예제 #5
0
        /// <summary>
        /// Allocate a new fixed sized RTHandle.
        /// </summary>
        /// <param name="width">With of the RTHandle.</param>
        /// <param name="height">Heigh of the RTHandle.</param>
        /// <param name="slices">Number of slices of the RTHandle.</param>
        /// <param name="depthBufferBits">Bit depths of a depth buffer.</param>
        /// <param name="colorFormat">GraphicsFormat of a color buffer.</param>
        /// <param name="filterMode">Filtering mode of the RTHandle.</param>
        /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
        /// <param name="dimension">Texture dimension of the RTHandle.</param>
        /// <param name="enableRandomWrite">Set to true to enable UAV random read writes on the texture.</param>
        /// <param name="useMipMap">Set to true if the texture should have mipmaps.</param>
        /// <param name="autoGenerateMips">Set to true to automatically generate mipmaps.</param>
        /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
        /// <param name="anisoLevel">Anisotropic filtering level.</param>
        /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
        /// <param name="msaaSamples">Number of MSAA samples for the RTHandle.</param>
        /// <param name="bindTextureMS">Set to true if the texture needs to be bound as a multisampled texture in the shader.</param>
        /// <param name="useDynamicScale">Set to true to use hardware dynamic scaling.</param>
        /// <param name="memoryless">Use this property to set the render texture memoryless modes.</param>
        /// <param name="name">Name of the RTHandle.</param>
        /// <returns></returns>
        public RTHandle Alloc(
            int width,
            int height,
            int slices = 1,
            DepthBits depthBufferBits          = DepthBits.None,
            GraphicsFormat colorFormat         = GraphicsFormat.R8G8B8A8_SRGB,
            FilterMode filterMode              = FilterMode.Point,
            TextureWrapMode wrapMode           = TextureWrapMode.Repeat,
            TextureDimension dimension         = TextureDimension.Tex2D,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            bool isShadowMap                   = false,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            bool enableMSAA = msaaSamples != MSAASamples.None;

            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
            RenderTexture rt;

            if (isShadowMap || depthBufferBits != DepthBits.None)
            {
                RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
                rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = enableRandomWrite,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = (int)msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, format, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
                };
            }
            else
            {
                rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = enableRandomWrite,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = (int)msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, colorFormat, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
                };
            }

            rt.Create();

            var newRT = new RTHandle(this);

            newRT.SetRenderTexture(rt);
            newRT.useScaling             = false;
            newRT.m_EnableRandomWrite    = enableRandomWrite;
            newRT.m_EnableMSAA           = enableMSAA;
            newRT.m_EnableHWDynamicScale = useDynamicScale;
            newRT.m_Name = name;

            newRT.referenceSize = new Vector2Int(width, height);

            return(newRT);
        }
예제 #6
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorBuffers, RTHandle depthBuffer, ClearFlag clearFlag = ClearFlag.None)
 {
     CoreUtils.SetRenderTarget(cmd, colorBuffers, depthBuffer.rt); // Don't clear here, viewport needs to be set before we do.
     SetViewportAndClear(cmd, depthBuffer, clearFlag, Color.clear);
 }
예제 #7
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorBuffers, RTHandle depthBuffer)
 {
     CoreUtils.SetRenderTarget(cmd, colorBuffers, depthBuffer.rt, ClearFlag.None, Color.clear);
     SetViewport(cmd, depthBuffer);
 }
예제 #8
0
 public static void SetRenderTarget(CommandBuffer cmd, RTHandle buffer, ClearFlag clearFlag = ClearFlag.None, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = -1)
 => SetRenderTarget(cmd, buffer, clearFlag, Color.clear, miplevel, cubemapFace, depthSlice);
예제 #9
0
 // This set of RenderTarget management methods is supposed to be used when rendering into a camera dependent render texture.
 // This will automatically set the viewport based on the camera size and the RTHandle scaling info.
 public static void SetRenderTarget(CommandBuffer cmd, RTHandle buffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = -1)
 {
     depthSlice = FixupDepthSlice(depthSlice, buffer);
     cmd.SetRenderTarget(buffer, miplevel, cubemapFace, depthSlice);
     SetViewportAndClear(cmd, buffer, clearFlag, clearColor);
 }
예제 #10
0
 /// <summary>
 /// Release memory of a RTHandle from the default RTHandle System
 /// </summary>
 /// <param name="rth">RTHandle that should be released.</param>
 public static void Release(RTHandle rth)
 {
     s_DefaultInstance.Release(rth);
 }