public void Create(long viewID, int w, int h, int d)
            {
                Debug.Assert(viewID >= 0);
                Debug.Assert(w > 0 && h > 0 && d > 0);

                // Clean up first.
                Destroy();

                // The required number of buffers depends on the view type.
                bool isGameView = viewID > 0;
                int  n          = isGameView ? 3 : 1;

                this.viewID       = viewID;
                this.lightingRTEX = new RenderTexture[n];
                this.lightingRTID = new RenderTargetIdentifier[n];

                for (int i = 0; i < n; i++)
                {
                    this.lightingRTEX[i]                   = new RenderTexture(w, h, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                    this.lightingRTEX[i].hideFlags         = HideFlags.HideAndDontSave;
                    this.lightingRTEX[i].filterMode        = FilterMode.Trilinear;   // Custom
                    this.lightingRTEX[i].dimension         = TextureDimension.Tex3D; // TODO: request the thick 3D tiling layout
                    this.lightingRTEX[i].volumeDepth       = d;
                    this.lightingRTEX[i].enableRandomWrite = true;
                    this.lightingRTEX[i].name              = CoreUtils.GetRenderTargetAutoName(w, h, RenderTextureFormat.ARGBHalf, String.Format("Volumetric{0}", i));
                    this.lightingRTEX[i].Create();
                    this.lightingRTID[i] = new RenderTargetIdentifier(this.lightingRTEX[i]);
                }
            }
        void Initialize()
        {
            if (m_TempRenderTexture == null)
            {
                // Temporary RT used for convolution and compression
                m_TempRenderTexture                  = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
                m_TempRenderTexture.hideFlags        = HideFlags.HideAndDontSave;
                m_TempRenderTexture.dimension        = TextureDimension.Tex2D;
                m_TempRenderTexture.useMipMap        = true;
                m_TempRenderTexture.autoGenerateMips = false;
                m_TempRenderTexture.name             = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionTemp", mips: true);
                m_TempRenderTexture.Create();

                m_ConvolutionTargetTexture                   = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
                m_ConvolutionTargetTexture.hideFlags         = HideFlags.HideAndDontSave;
                m_ConvolutionTargetTexture.dimension         = TextureDimension.Tex2D;
                m_ConvolutionTargetTexture.useMipMap         = true;
                m_ConvolutionTargetTexture.autoGenerateMips  = false;
                m_ConvolutionTargetTexture.name              = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true);
                m_ConvolutionTargetTexture.enableRandomWrite = true;
                m_ConvolutionTargetTexture.Create();

                InitializeProbeBakingStates();
            }
        }
Пример #3
0
        public override void Build(HDRenderPipelineAsset hdAsset, HDRenderPipelineRuntimeResources defaultResources)
        {
            PreIntegratedFGD.instance.Build(PreIntegratedFGD.FGDIndex.FGD_GGXAndDisneyDiffuse);
            LTCAreaLight.instance.Build();

            // Initialize the dual scattering LUT.
            m_PreIntegratedFiberScatteringLUT = new RenderTexture(m_Dim, m_Dim, 0, GraphicsFormat.R16G16_SFloat)
            {
                dimension         = TextureDimension.Tex3D,
                volumeDepth       = m_Dim,
                enableRandomWrite = true,
                hideFlags         = HideFlags.HideAndDontSave,
                filterMode        = FilterMode.Point,
                wrapMode          = TextureWrapMode.Clamp,
                name = CoreUtils.GetRenderTargetAutoName(m_Dim, m_Dim, 0, GraphicsFormat.R16G16_SFloat, "PreIntegratedFiberScattering")
            };
            m_PreIntegratedFiberScatteringLUT.Create();

            m_PreIntegratedFiberAverageScatteringLUT = new RenderTexture(m_Dim, m_Dim, 0, GraphicsFormat.R16G16B16A16_SFloat)
            {
                dimension         = TextureDimension.Tex3D,
                volumeDepth       = m_Dim,
                enableRandomWrite = true,
                hideFlags         = HideFlags.HideAndDontSave,
                filterMode        = FilterMode.Point,
                wrapMode          = TextureWrapMode.Clamp,
                name = CoreUtils.GetRenderTargetAutoName(m_Dim, m_Dim, 0, GraphicsFormat.R16G16B16A16_SFloat, "PreIntegratedAverageFiberScattering")
            };
            m_PreIntegratedFiberAverageScatteringLUT.Create();

            m_PreIntegratedFiberScatteringCS = defaultResources.shaders.preIntegratedFiberScatteringCS;
        }
Пример #4
0
        void Initialize()
        {
            if (m_TempRenderTexture == null)
            {
                // Temporary RT used for convolution and compression
                m_TempRenderTexture                  = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
                m_TempRenderTexture.hideFlags        = HideFlags.HideAndDontSave;
                m_TempRenderTexture.dimension        = TextureDimension.Cube;
                m_TempRenderTexture.useMipMap        = true;
                m_TempRenderTexture.autoGenerateMips = false;
                m_TempRenderTexture.name             = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "ReflectionProbeTemp", mips: true);
                m_TempRenderTexture.Create();

                m_ConvolutionTargetTextureArray = new RenderTexture[m_IBLFilterBSDF.Length];
                for (int bsdfIdx = 0; bsdfIdx < m_IBLFilterBSDF.Length; ++bsdfIdx)
                {
                    m_ConvolutionTargetTextureArray[bsdfIdx]                  = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
                    m_ConvolutionTargetTextureArray[bsdfIdx].hideFlags        = HideFlags.HideAndDontSave;
                    m_ConvolutionTargetTextureArray[bsdfIdx].dimension        = TextureDimension.Cube;
                    m_ConvolutionTargetTextureArray[bsdfIdx].useMipMap        = true;
                    m_ConvolutionTargetTextureArray[bsdfIdx].autoGenerateMips = false;
                    m_ConvolutionTargetTextureArray[bsdfIdx].name             = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "ReflectionProbeConvolution_" + bsdfIdx.ToString(), mips: true);
                    m_ConvolutionTargetTextureArray[bsdfIdx].Create();
                }
            }

            InitializeProbeBakingStates();
        }
Пример #5
0
        void Initialize()
        {
            if (m_ConvolutionTargetTexture == null)
            {
                m_ConvolutionTargetTexture                   = new RenderTexture(m_ProbeSize, m_ProbeSize, 0, m_ProbeFormat);
                m_ConvolutionTargetTexture.hideFlags         = HideFlags.HideAndDontSave;
                m_ConvolutionTargetTexture.dimension         = TextureDimension.Tex2D;
                m_ConvolutionTargetTexture.useMipMap         = true;
                m_ConvolutionTargetTexture.autoGenerateMips  = false;
                m_ConvolutionTargetTexture.filterMode        = FilterMode.Point;
                m_ConvolutionTargetTexture.name              = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 0, m_ProbeFormat, "PlanarReflectionConvolution", mips: true);
                m_ConvolutionTargetTexture.enableRandomWrite = true;
                m_ConvolutionTargetTexture.Create();

                // Clear to avoid garbage in the convolution texture.
                int mipCount = Mathf.FloorToInt(Mathf.Log(m_ProbeSize, 2)) + 1;
                for (int mipIdx = 0; mipIdx < mipCount; ++mipIdx)
                {
                    Graphics.SetRenderTarget(m_ConvolutionTargetTexture, mipIdx, CubemapFace.Unknown);
                    GL.Clear(false, true, Color.clear);
                }
            }

            m_FrameProbeIndex = 0;
        }
            public void Create(long viewID, int w, int h, int d, ControllerParameters controlParams)
            {
                Debug.Assert(viewID > 0);
                Debug.Assert(w > 0 && h > 0 && d > 0);

                // Clean up first.
                Destroy();

                m_ViewID      = viewID;
                m_Textures    = new RenderTexture[k_NumBuffers];
                m_Identifiers = new RenderTargetIdentifier[k_NumBuffers];
                m_Params      = new Parameters[k_NumFrames];

                for (int i = 0; i < k_NumBuffers; i++)
                {
                    m_Textures[i]                   = new RenderTexture(w, h, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                    m_Textures[i].hideFlags         = HideFlags.HideAndDontSave;
                    m_Textures[i].filterMode        = FilterMode.Trilinear;   // Custom
                    m_Textures[i].dimension         = TextureDimension.Tex3D; // TODO: request the thick 3D tiling layout
                    m_Textures[i].volumeDepth       = d;
                    m_Textures[i].enableRandomWrite = true;
                    m_Textures[i].name              = CoreUtils.GetRenderTargetAutoName(w, h, RenderTextureFormat.ARGBHalf, String.Format("VBuffer{0}", i));
                    m_Textures[i].Create();

                    // TODO: clear the texture. Clearing 3D textures does not appear to work right now.

                    m_Identifiers[i] = new RenderTargetIdentifier(m_Textures[i]);
                }

                // Start with the same parameters for both frames. Then incrementally update them.
                Parameters parameters = new Parameters(w, h, d, controlParams);

                m_Params[0] = parameters;
                m_Params[1] = parameters;
            }
Пример #7
0
            public void Create(long viewID, int w, int h, int d)
            {
                Debug.Assert(viewID >= 0);
                Debug.Assert(w > 0 && h > 0 && d > 0);

                // Clean up first.
                Destroy();

                // Only Game Views need history and feedback buffers.
                bool isGameView = viewID > 0;
                int  n          = isGameView ? 4 : 2;

                m_ViewID      = viewID;
                m_Textures    = new RenderTexture[n];
                m_Identifiers = new RenderTargetIdentifier[n];

                for (int i = 0; i < n; i++)
                {
                    m_Textures[i]                   = new RenderTexture(w, h, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                    m_Textures[i].hideFlags         = HideFlags.HideAndDontSave;
                    m_Textures[i].filterMode        = FilterMode.Trilinear;   // Custom
                    m_Textures[i].dimension         = TextureDimension.Tex3D; // TODO: request the thick 3D tiling layout
                    m_Textures[i].volumeDepth       = d;
                    m_Textures[i].enableRandomWrite = true;
                    m_Textures[i].name              = CoreUtils.GetRenderTargetAutoName(w, h, RenderTextureFormat.ARGBHalf, String.Format("VBuffer{0}", i));
                    m_Textures[i].Create();

                    // TODO: clear the texture. Clearing 3D textures does not appear to work right now.

                    m_Identifiers[i] = new RenderTargetIdentifier(m_Textures[i]);
                }
            }
Пример #8
0
        void Initialize()
        {
            if (m_ConvolutionTargetTexture == null)
            {
                // Temporary RT used for convolution and compression

                // Note: Temporarily disabled because planar probe baking is currently disabled so we avoid allocating unused targets
                // m_TempRenderTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
                // m_TempRenderTexture.hideFlags = HideFlags.HideAndDontSave;
                // m_TempRenderTexture.dimension = TextureDimension.Tex2D;
                // m_TempRenderTexture.useMipMap = true;
                // m_TempRenderTexture.autoGenerateMips = false;
                // m_TempRenderTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionTemp", mips: true);
                // m_TempRenderTexture.Create();

                m_ConvolutionTargetTexture                   = new RenderTexture(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf);
                m_ConvolutionTargetTexture.hideFlags         = HideFlags.HideAndDontSave;
                m_ConvolutionTargetTexture.dimension         = TextureDimension.Tex2D;
                m_ConvolutionTargetTexture.useMipMap         = true;
                m_ConvolutionTargetTexture.autoGenerateMips  = false;
                m_ConvolutionTargetTexture.filterMode        = FilterMode.Point;
                m_ConvolutionTargetTexture.name              = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true);
                m_ConvolutionTargetTexture.enableRandomWrite = true;
                m_ConvolutionTargetTexture.Create();
            }

            m_FrameProbeIndex = 0;
        }
Пример #9
0
        public override void Build(HDRenderPipelineAsset hdAsset)
        {
            m_InitPreFGD = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");

            m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
            m_PreIntegratedFGD.hideFlags  = HideFlags.HideAndDontSave;
            m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
            m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
            m_PreIntegratedFGD.hideFlags  = HideFlags.DontSave;
            m_PreIntegratedFGD.name       = CoreUtils.GetRenderTargetAutoName(128, 128, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD");
            m_PreIntegratedFGD.Create();

            m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, 3, TextureFormat.RGBAHalf, false /*mipmap*/, true /* linear */)
            {
                hideFlags  = HideFlags.HideAndDontSave,
                wrapMode   = TextureWrapMode.Clamp,
                filterMode = FilterMode.Bilinear,
                name       = CoreUtils.GetTextureAutoName(k_LtcLUTResolution, k_LtcLUTResolution, TextureFormat.RGBAHalf, depth: 3, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
            };

            LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, s_LtcGGXMatrixData);
            LoadLUT(m_LtcData, 1, TextureFormat.RGBAHalf, s_LtcDisneyDiffuseMatrixData);
            // TODO: switch to RGBA64 when it becomes available.
            LoadLUT(m_LtcData, 2, TextureFormat.RGBAHalf, s_LtcGGXMagnitudeData, s_LtcGGXFresnelData, s_LtcDisneyDiffuseMagnitudeData);

            m_LtcData.Apply();

            m_isInit = false;
        }
        public void Build(BRDF_TYPE _BRDFType)
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;

                switch (_BRDFType)
                {
                case BRDF_TYPE.GGX_SMITH_SCHLICK:
                    m_PreIntegratedFGDMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.preIntegratedFGD);
                    break;

                case BRDF_TYPE.WARD_MORODER_SCHLICK:
                    m_PreIntegratedFGDMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.preIntegratedFGD_AxFWard);
                    break;
                }

                m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
                m_PreIntegratedFGD.hideFlags  = HideFlags.HideAndDontSave;
                m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
                m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
                m_PreIntegratedFGD.hideFlags  = HideFlags.DontSave;
                m_PreIntegratedFGD.name       = CoreUtils.GetRenderTargetAutoName(128, 128, 1, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD");
                m_PreIntegratedFGD.Create();

                m_isInit = false;
            }

            m_refCounting++;
        }
Пример #11
0
        public bool AllocTextureArray(int numCubeMaps, int width, TextureFormat format, bool isMipMapped, Material cubeBlitMaterial)
        {
            var res = AllocTextureArray(numCubeMaps);

            m_NumMipLevels = GetNumMips(width, width);      // will calculate same way whether we have cube array or not

            if (!TextureCache.supportsCubemapArrayTextures)
            {
                m_CubeBlitMaterial = cubeBlitMaterial;

                int panoWidthTop  = 4 * width;
                int panoHeightTop = 2 * width;

                // create panorama 2D array. Hardcoding the render target for now. No convenient way atm to
                // map from TextureFormat to RenderTextureFormat and don't want to deal with sRGB issues for now.
                m_CacheNoCubeArray = new Texture2DArray(panoWidthTop, panoHeightTop, numCubeMaps, TextureFormat.RGBAHalf, isMipMapped)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Repeat,
                    wrapModeV  = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Trilinear,
                    anisoLevel = 0,
                    name       = CoreUtils.GetTextureAutoName(panoWidthTop, panoHeightTop, format, TextureDimension.Tex2DArray, depth: numCubeMaps, name: m_CacheName)
                };

                m_NumPanoMipLevels = isMipMapped ? GetNumMips(panoWidthTop, panoHeightTop) : 1;
                m_StagingRTs       = new RenderTexture[m_NumPanoMipLevels];
                for (int m = 0; m < m_NumPanoMipLevels; m++)
                {
                    m_StagingRTs[m] = new RenderTexture(Mathf.Max(1, panoWidthTop >> m), Mathf.Max(1, panoHeightTop >> m), 0, RenderTextureFormat.ARGBHalf)
                    {
                        hideFlags = HideFlags.HideAndDontSave
                    };
                    m_StagingRTs[m].name = CoreUtils.GetRenderTargetAutoName(Mathf.Max(1, panoWidthTop >> m), Mathf.Max(1, panoHeightTop >> m), 1, RenderTextureFormat.ARGBHalf, String.Format("PanaCache{0}", m));
                }

                if (m_CubeBlitMaterial)
                {
                    m_CubeMipLevelPropName = Shader.PropertyToID("_cubeMipLvl");
                    m_cubeSrcTexPropName   = Shader.PropertyToID("_srcCubeTexture");
                }
            }
            else
            {
                m_Cache = new CubemapArray(width, numCubeMaps, format, isMipMapped)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Trilinear,
                    anisoLevel = 0, // It is important to set 0 here, else unity force anisotropy filtering
                    name       = CoreUtils.GetTextureAutoName(width, width, format, TextureDimension.CubeArray, depth: numCubeMaps, name: m_CacheName)
                };
            }

            return(res);
        }
 public RenderTexture NewRenderTarget(PlanarReflectionProbe probe)
 {
     var rt = new RenderTexture(m_Parameters.planarReflectionProbeSize, m_Parameters.planarReflectionProbeSize, 0, RenderTextureFormat.ARGBHalf);
     // No hide and don't save for this one
     rt.useMipMap = true;
     rt.autoGenerateMips = false;
     rt.name = CoreUtils.GetRenderTargetAutoName(m_Parameters.planarReflectionProbeSize, m_Parameters.planarReflectionProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarProbeRT");
     rt.Create();
     return rt;
 }
Пример #13
0
        public override void Build(HDRenderPipelineAsset hdAsset, HDRenderPipelineRuntimeResources defaultResources)
        {
            // Create Materials
            m_preIntegratedFGDMaterial_Ward = CoreUtils.CreateEngineMaterial(defaultResources.shaders.preIntegratedFGD_WardPS);
            if (m_preIntegratedFGDMaterial_Ward == null)
            {
                throw new Exception("Failed to create material for Ward BRDF pre-integration!");
            }

            m_preIntegratedFGDMaterial_CookTorrance = CoreUtils.CreateEngineMaterial(defaultResources.shaders.preIntegratedFGD_CookTorrancePS);
            if (m_preIntegratedFGDMaterial_CookTorrance == null)
            {
                throw new Exception("Failed to create material for Cook-Torrance BRDF pre-integration!");
            }

            // Create render textures where we will render the FGD tables
            m_preIntegratedFGD_Ward            = new RenderTexture(128, 128, 0, GraphicsFormat.A2B10G10R10_UNormPack32);
            m_preIntegratedFGD_Ward.hideFlags  = HideFlags.HideAndDontSave;
            m_preIntegratedFGD_Ward.filterMode = FilterMode.Bilinear;
            m_preIntegratedFGD_Ward.wrapMode   = TextureWrapMode.Clamp;
            m_preIntegratedFGD_Ward.hideFlags  = HideFlags.DontSave;
            m_preIntegratedFGD_Ward.name       = CoreUtils.GetRenderTargetAutoName(128, 128, 1, GraphicsFormat.A2B10G10R10_UNormPack32, "PreIntegratedFGD_Ward");
            m_preIntegratedFGD_Ward.Create();

            m_preIntegratedFGD_CookTorrance            = new RenderTexture(128, 128, 0, GraphicsFormat.A2B10G10R10_UNormPack32);
            m_preIntegratedFGD_CookTorrance.hideFlags  = HideFlags.HideAndDontSave;
            m_preIntegratedFGD_CookTorrance.filterMode = FilterMode.Bilinear;
            m_preIntegratedFGD_CookTorrance.wrapMode   = TextureWrapMode.Clamp;
            m_preIntegratedFGD_CookTorrance.hideFlags  = HideFlags.DontSave;
            m_preIntegratedFGD_CookTorrance.name       = CoreUtils.GetRenderTargetAutoName(128, 128, 1, GraphicsFormat.A2B10G10R10_UNormPack32, "PreIntegratedFGD_CookTorrance");
            m_preIntegratedFGD_CookTorrance.Create();

            // LTC data

            m_LtcData = new Texture2DArray(LTCAreaLight.k_LtcLUTResolution, LTCAreaLight.k_LtcLUTResolution, 3, GraphicsFormat.R16G16B16A16_SFloat, TextureCreationFlags.None)
            {
                hideFlags  = HideFlags.HideAndDontSave,
                wrapMode   = TextureWrapMode.Clamp,
                filterMode = FilterMode.Bilinear,
                name       = CoreUtils.GetTextureAutoName(LTCAreaLight.k_LtcLUTResolution, LTCAreaLight.k_LtcLUTResolution, GraphicsFormat.R16G16B16A16_SFloat, depth: 2, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
            };

            // Caution: This need to match order define in AxFLTCAreaLight
            LTCAreaLight.LoadLUT(m_LtcData, 0, GraphicsFormat.R16G16B16A16_SFloat, LTCAreaLight.s_LtcMatrixData_GGX);
            // Warning: check /Material/AxF/AxFLTCAreaLight/LtcData.GGX2.cs: 5 columns are needed, the entries are NOT normalized!
            // For now, we patch for this in LoadLUT, which should affect the loading of s_LtcGGXMatrixData for the rest of the materials
            // (Lit, etc.)

            m_LtcData.Apply();

            // TODO BugFix:
            // We still bind the original data for now, see AxFLTCAreaLight.hlsl: when using a local table, results differ,
            // even if we patch the non-normalization error in the 8th column when calling the LTCInvMatrix loading routine (LoadLUT).
            LTCAreaLight.instance.Build();
        }
Пример #14
0
        public RenderTexture NewRenderTarget(HDAdditionalReflectionData probe)
        {
            var rt = new RenderTexture(m_Parameters.reflectionProbeSize, m_Parameters.reflectionProbeSize, 0, RenderTextureFormat.ARGBHalf);

            // No hide and don't save for this one
            rt.useMipMap        = true;
            rt.autoGenerateMips = false;
            rt.name             = CoreUtils.GetRenderTargetAutoName(m_Parameters.reflectionProbeSize, m_Parameters.reflectionProbeSize, 1, RenderTextureFormat.ARGBHalf, "ProbeRT");
            rt.dimension        = TextureDimension.Cube;
            rt.Create();
            return(rt);
        }
    void Resize(int width, int height, MSAASamples msaaSamples, bool sizeChanged, bool msaaSampleChanged)
    {
        m_MaxWidths  = Math.Max(width, m_MaxWidths);
        m_MaxHeights = Math.Max(height, m_MaxHeights);
        m_ScaledRTCurrentMSAASamples = msaaSamples;

        var maxSize = new Vector2Int(m_MaxWidths, m_MaxHeights);

        Array.Resize(ref m_AutoSizedRTsArray, m_AutoSizedRTs.Count);
        m_AutoSizedRTs.CopyTo(m_AutoSizedRTsArray);

        for (int i = 0, c = m_AutoSizedRTsArray.Length; i < c; ++i)
        {
            // Grab the RT Handle
            var rth = m_AutoSizedRTsArray[i];

            // If we are only processing MSAA sample count change, make sure this RT is an MSAA one
            if (!sizeChanged && msaaSampleChanged && !rth.m_EnableMSAA)
            {
                continue;
            }

            // Force its new reference size
            rth.referenceSize = maxSize;

            // Grab the render texture
            var renderTexture = rth.m_RT;

            // Free the previous version
            renderTexture.Release();

            // Get the scaled size
            var scaledSize = rth.GetScaledSize(maxSize);

            renderTexture.width  = Mathf.Max(scaledSize.x, 1);
            renderTexture.height = Mathf.Max(scaledSize.y, 1);

            // If this is a msaa texture, make sure to update its msaa count
            if (rth.m_EnableMSAA)
            {
                renderTexture.antiAliasing = (int)m_ScaledRTCurrentMSAASamples;
            }

            // Regenerate the name
            renderTexture.name = CoreUtils.GetRenderTargetAutoName(renderTexture.width, renderTexture.height, renderTexture.volumeDepth, renderTexture.format, rth.m_Name, mips: renderTexture.useMipMap, enableMSAA: rth.m_EnableMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples);

            // Create the render texture
            renderTexture.Create();
        }
    }
Пример #16
0
        public void Build(FGDIndex index)
        {
            Debug.Assert(index != FGDIndex.Count);
            Debug.Assert(m_refCounting[(int)index] >= 0);

            if (m_refCounting[(int)index] == 0)
            {
                int res = (int)FGDTexture.Resolution;

                switch (index)
                {
                case FGDIndex.FGD_GGXAndDisneyDiffuse:
                    m_PreIntegratedFGDMaterial[(int)index]    = CoreUtils.CreateEngineMaterial(HDRenderPipelineGlobalSettings.instance.renderPipelineResources.shaders.preIntegratedFGD_GGXDisneyDiffusePS);
                    m_PreIntegratedFGD[(int)index]            = new RenderTexture(res, res, 0, GraphicsFormat.A2B10G10R10_UNormPack32);
                    m_PreIntegratedFGD[(int)index].hideFlags  = HideFlags.HideAndDontSave;
                    m_PreIntegratedFGD[(int)index].filterMode = FilterMode.Bilinear;
                    m_PreIntegratedFGD[(int)index].wrapMode   = TextureWrapMode.Clamp;
                    m_PreIntegratedFGD[(int)index].name       = CoreUtils.GetRenderTargetAutoName(res, res, 1, GraphicsFormat.A2B10G10R10_UNormPack32, "preIntegratedFGD_GGXDisneyDiffuse");
                    m_PreIntegratedFGD[(int)index].Create();
                    break;

                case FGDIndex.FGD_CharlieAndFabricLambert:
                    m_PreIntegratedFGDMaterial[(int)index]    = CoreUtils.CreateEngineMaterial(HDRenderPipelineGlobalSettings.instance.renderPipelineResources.shaders.preIntegratedFGD_CharlieFabricLambertPS);
                    m_PreIntegratedFGD[(int)index]            = new RenderTexture(res, res, 0, GraphicsFormat.A2B10G10R10_UNormPack32);
                    m_PreIntegratedFGD[(int)index].hideFlags  = HideFlags.HideAndDontSave;
                    m_PreIntegratedFGD[(int)index].filterMode = FilterMode.Bilinear;
                    m_PreIntegratedFGD[(int)index].wrapMode   = TextureWrapMode.Clamp;
                    m_PreIntegratedFGD[(int)index].name       = CoreUtils.GetRenderTargetAutoName(res, res, 1, GraphicsFormat.A2B10G10R10_UNormPack32, "preIntegratedFGD_CharlieFabricLambert");
                    m_PreIntegratedFGD[(int)index].Create();
                    break;

                case FGDIndex.FGD_Marschner:
                    m_PreIntegratedFGDMaterial[(int)index]    = CoreUtils.CreateEngineMaterial(HDRenderPipelineGlobalSettings.instance.renderPipelineResources.shaders.preIntegratedFGD_MarschnerPS);
                    m_PreIntegratedFGD[(int)index]            = new RenderTexture(res, res, 0, GraphicsFormat.A2B10G10R10_UNormPack32);
                    m_PreIntegratedFGD[(int)index].hideFlags  = HideFlags.HideAndDontSave;
                    m_PreIntegratedFGD[(int)index].filterMode = FilterMode.Bilinear;
                    m_PreIntegratedFGD[(int)index].wrapMode   = TextureWrapMode.Clamp;
                    m_PreIntegratedFGD[(int)index].name       = CoreUtils.GetRenderTargetAutoName(res, res, 1, GraphicsFormat.A2B10G10R10_UNormPack32, "preIntegratedFGD_Marschner");
                    m_PreIntegratedFGD[(int)index].Create();
                    break;

                default:
                    break;
                }

                m_isInit[(int)index] = false;
            }

            m_refCounting[(int)index]++;
        }
Пример #17
0
        public override void Build(HDRenderPipelineAsset hdAsset)
        {
            var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;

            // Create Materials
            m_preIntegratedFGDMaterial_Ward = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.shaders.preIntegratedFGD_WardPS);
            if (m_preIntegratedFGDMaterial_Ward == null)
            {
                throw new Exception("Failed to create material for Ward BRDF pre-integration!");
            }

            m_preIntegratedFGDMaterial_CookTorrance = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.shaders.preIntegratedFGD_CookTorrancePS);
            if (m_preIntegratedFGDMaterial_CookTorrance == null)
            {
                throw new Exception("Failed to create material for Cook-Torrance BRDF pre-integration!");
            }

            // Create render textures where we will render the FGD tables
            m_preIntegratedFGD_Ward            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
            m_preIntegratedFGD_Ward.hideFlags  = HideFlags.HideAndDontSave;
            m_preIntegratedFGD_Ward.filterMode = FilterMode.Bilinear;
            m_preIntegratedFGD_Ward.wrapMode   = TextureWrapMode.Clamp;
            m_preIntegratedFGD_Ward.hideFlags  = HideFlags.DontSave;
            m_preIntegratedFGD_Ward.name       = CoreUtils.GetRenderTargetAutoName(128, 128, 1, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD_Ward");
            m_preIntegratedFGD_Ward.Create();

            m_preIntegratedFGD_CookTorrance            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
            m_preIntegratedFGD_CookTorrance.hideFlags  = HideFlags.HideAndDontSave;
            m_preIntegratedFGD_CookTorrance.filterMode = FilterMode.Bilinear;
            m_preIntegratedFGD_CookTorrance.wrapMode   = TextureWrapMode.Clamp;
            m_preIntegratedFGD_CookTorrance.hideFlags  = HideFlags.DontSave;
            m_preIntegratedFGD_CookTorrance.name       = CoreUtils.GetRenderTargetAutoName(128, 128, 1, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD_CookTorrance");
            m_preIntegratedFGD_CookTorrance.Create();

            // LTC data

            m_LtcData = new Texture2DArray(LTCAreaLight.k_LtcLUTResolution, LTCAreaLight.k_LtcLUTResolution, 3, TextureFormat.RGBAHalf, false /*mipmap*/, true /* linear */)
            {
                hideFlags  = HideFlags.HideAndDontSave,
                wrapMode   = TextureWrapMode.Clamp,
                filterMode = FilterMode.Bilinear,
                name       = CoreUtils.GetTextureAutoName(LTCAreaLight.k_LtcLUTResolution, LTCAreaLight.k_LtcLUTResolution, TextureFormat.RGBAHalf, depth: 2, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
            };

            // Caution: This need to match order define in AxFLTCAreaLight
            LTCAreaLight.LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, LTCAreaLight.s_LtcMatrixData_GGX);

            m_LtcData.Apply();
        }
    public void DemandResize(RTHandle rth)
    {
        Assert.IsTrue(m_ResizeOnDemandRTs.Contains(rth), "The RTHandle is not an resize on demand handle in this RTHandleSystem. Please call SwitchToResizeOnDemand(rth, true) before resizing on demand.");

        // Grab the render texture
        var rt = rth.m_RT;

        rth.referenceSize = new Vector2Int(m_MaxWidths, m_MaxHeights);
        var scaledSize = rth.GetScaledSize(rth.referenceSize);

        scaledSize = Vector2Int.Max(Vector2Int.one, scaledSize);

        // Did the size change?
        var sizeChanged = rt.width != scaledSize.x || rt.height != scaledSize.y;
        // If this is an MSAA texture, did the sample count change?
        var msaaSampleChanged = rth.m_EnableMSAA && rt.antiAliasing != (int)m_ScaledRTCurrentMSAASamples;

        if (sizeChanged || msaaSampleChanged)
        {
            // Free this render texture
            rt.Release();

            // Update the antialiasing count
            if (rth.m_EnableMSAA)
            {
                rt.antiAliasing = (int)m_ScaledRTCurrentMSAASamples;
            }

            // Update the size
            rt.width  = scaledSize.x;
            rt.height = scaledSize.y;

            // Generate a new name
            rt.name = CoreUtils.GetRenderTargetAutoName(
                rt.width,
                rt.height,
                rt.volumeDepth,
                rt.format,
                rth.m_Name,
                mips: rt.useMipMap,
                enableMSAA: rth.m_EnableMSAA,
                msaaSamples: m_ScaledRTCurrentMSAASamples
                );

            // Create the new texture
            rt.Create();
        }
    }
Пример #19
0
        public override void Initialize(CommandBuffer cmd)
        {
            if (!m_ComputeGgxIblSampleDataCS)
            {
                m_ComputeGgxIblSampleDataCS     = m_RenderPipelineResources.shaders.computeGgxIblSampleDataCS;
                m_ComputeGgxIblSampleDataKernel = m_ComputeGgxIblSampleDataCS.FindKernel("ComputeGgxIblSampleData");
            }

            if (!m_BuildProbabilityTablesCS)
            {
                m_BuildProbabilityTablesCS   = m_RenderPipelineResources.shaders.buildProbabilityTablesCS;
                m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities");
                m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities");
            }

            if (!m_convolveMaterial)
            {
                m_convolveMaterial = CoreUtils.CreateEngineMaterial(m_RenderPipelineResources.shaders.GGXConvolvePS);
            }

            if (!m_GgxIblSampleData)
            {
                m_GgxIblSampleData                   = new RenderTexture(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                m_GgxIblSampleData.useMipMap         = false;
                m_GgxIblSampleData.autoGenerateMips  = false;
                m_GgxIblSampleData.enableRandomWrite = true;
                m_GgxIblSampleData.filterMode        = FilterMode.Point;
                m_GgxIblSampleData.name              = CoreUtils.GetRenderTargetAutoName(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 1, RenderTextureFormat.ARGBHalf, "GGXIblSampleData");
                m_GgxIblSampleData.hideFlags         = HideFlags.HideAndDontSave;
                m_GgxIblSampleData.Create();

                InitializeGgxIblSampleData(cmd);
            }

            if (!m_PlanarReflectionFilteringCS)
            {
                m_PlanarReflectionFilteringCS           = m_RenderPipelineResources.shaders.planarReflectionFilteringCS;
                m_PlanarReflectionDepthConversionKernel = m_PlanarReflectionFilteringCS.FindKernel("DepthConversion");
                m_PlanarReflectionDownScaleKernel       = m_PlanarReflectionFilteringCS.FindKernel("DownScale");
                m_PlanarReflectionFilteringKernel       = m_PlanarReflectionFilteringCS.FindKernel("FilterPlanarReflection");
            }

            for (int i = 0; i < 6; ++i)
            {
                var lookAt = Matrix4x4.LookAt(Vector3.zero, CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
                m_faceWorldToViewMatrixMatrices[i] = lookAt * Matrix4x4.Scale(new Vector3(1.0f, 1.0f, -1.0f)); // Need to scale -1.0 on Z to match what is being done in the camera.wolrdToCameraMatrix API. ...
            }
        }
        public void Initialize(CommandBuffer cmd)
        {
            if (!m_ComputeGgxIblSampleDataCS)
            {
                m_ComputeGgxIblSampleDataCS     = m_RenderPipelineResources.computeGgxIblSampleData;
                m_ComputeGgxIblSampleDataKernel = m_ComputeGgxIblSampleDataCS.FindKernel("ComputeGgxIblSampleData");
            }

            if (!m_BuildProbabilityTablesCS)
            {
                m_BuildProbabilityTablesCS   = m_RenderPipelineResources.buildProbabilityTables;
                m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities");
                m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities");
            }

            if (!m_GgxConvolveMaterial)
            {
                m_GgxConvolveMaterial = CoreUtils.CreateEngineMaterial(m_RenderPipelineResources.GGXConvolve);
            }

            if (!m_GgxIblSampleData)
            {
                m_GgxIblSampleData                   = new RenderTexture(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
                m_GgxIblSampleData.useMipMap         = false;
                m_GgxIblSampleData.autoGenerateMips  = false;
                m_GgxIblSampleData.enableRandomWrite = true;
                m_GgxIblSampleData.filterMode        = FilterMode.Point;
                m_GgxIblSampleData.name              = CoreUtils.GetRenderTargetAutoName(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, RenderTextureFormat.ARGBHalf, "GGXIblSampleData");
                m_GgxIblSampleData.hideFlags         = HideFlags.HideAndDontSave;
                m_GgxIblSampleData.Create();

                m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeGgxIblSampleDataKernel, "output", m_GgxIblSampleData);

                using (new ProfilingSample(cmd, "Compute GGX IBL Sample Data"))
                {
                    cmd.DispatchCompute(m_ComputeGgxIblSampleDataCS, m_ComputeGgxIblSampleDataKernel, 1, 1, 1);
                }
            }

            for (int i = 0; i < 6; ++i)
            {
                var lookAt = Matrix4x4.LookAt(Vector3.zero, CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
                m_faceWorldToViewMatrixMatrices[i] = lookAt * Matrix4x4.Scale(new Vector3(1.0f, 1.0f, -1.0f)); // Need to scale -1.0 on Z to match what is being done in the camera.wolrdToCameraMatrix API. ...
            }
        }
Пример #21
0
        public void Build(FGDIndex index)
        {
            Debug.Assert(index != FGDIndex.Count);
            Debug.Assert(m_refCounting[(int)index] >= 0);

            if (m_refCounting[(int)index] == 0)
            {
                var hdrp = HDRenderPipeline.defaultAsset;
                int res  = (int)FGDTexture.Resolution;

                switch (index)
                {
                case FGDIndex.FGD_GGXAndDisneyDiffuse:
                    m_PreIntegratedFGDMaterial[(int)index]    = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.shaders.preIntegratedFGD_GGXDisneyDiffusePS);
                    m_PreIntegratedFGD[(int)index]            = new RenderTexture(res, res, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
                    m_PreIntegratedFGD[(int)index].hideFlags  = HideFlags.HideAndDontSave;
                    m_PreIntegratedFGD[(int)index].filterMode = FilterMode.Bilinear;
                    m_PreIntegratedFGD[(int)index].wrapMode   = TextureWrapMode.Clamp;
                    m_PreIntegratedFGD[(int)index].name       = CoreUtils.GetRenderTargetAutoName(res, res, 1, RenderTextureFormat.ARGB2101010, "preIntegratedFGD_GGXDisneyDiffuse");
                    m_PreIntegratedFGD[(int)index].Create();
                    break;

                case FGDIndex.FGD_CharlieAndFabricLambert:
                    m_PreIntegratedFGDMaterial[(int)index]    = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.shaders.preIntegratedFGD_CharlieFabricLambertPS);
                    m_PreIntegratedFGD[(int)index]            = new RenderTexture(res, res, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
                    m_PreIntegratedFGD[(int)index].hideFlags  = HideFlags.HideAndDontSave;
                    m_PreIntegratedFGD[(int)index].filterMode = FilterMode.Bilinear;
                    m_PreIntegratedFGD[(int)index].wrapMode   = TextureWrapMode.Clamp;
                    m_PreIntegratedFGD[(int)index].name       = CoreUtils.GetRenderTargetAutoName(res, res, 1, RenderTextureFormat.ARGB2101010, "preIntegratedFGD_CharlieFabricLambert");
                    m_PreIntegratedFGD[(int)index].Create();
                    break;

                default:
                    break;
                }

                m_isInit[(int)index] = false;
            }

            m_refCounting[(int)index]++;
        }
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                m_InitPreFGD = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");

                m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
                m_PreIntegratedFGD.hideFlags  = HideFlags.HideAndDontSave;
                m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
                m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
                m_PreIntegratedFGD.hideFlags  = HideFlags.DontSave;
                m_PreIntegratedFGD.name       = CoreUtils.GetRenderTargetAutoName(128, 128, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD");
                m_PreIntegratedFGD.Create();

                m_isInit = false;
            }

            m_refCounting++;
        }
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
                m_PreIntegratedFGDMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.preIntegratedFGD);

                m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
                m_PreIntegratedFGD.hideFlags  = HideFlags.HideAndDontSave;
                m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
                m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
                m_PreIntegratedFGD.hideFlags  = HideFlags.DontSave;
                m_PreIntegratedFGD.name       = CoreUtils.GetRenderTargetAutoName(128, 128, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD");
                m_PreIntegratedFGD.Create();

                m_isInit = false;
            }

            m_refCounting++;
        }
        void Initialize()
        {
            if (m_ConvolutionTargetTexture == null)
            {
                // Temporary RT used for convolution and compression

                // Note: Temporarily disabled because planar probe baking is currently disabled so we avoid allocating unused targets
                // m_TempRenderTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
                // m_TempRenderTexture.hideFlags = HideFlags.HideAndDontSave;
                // m_TempRenderTexture.dimension = TextureDimension.Tex2D;
                // m_TempRenderTexture.useMipMap = true;
                // m_TempRenderTexture.autoGenerateMips = false;
                // m_TempRenderTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionTemp", mips: true);
                // m_TempRenderTexture.Create();

                m_ConvolutionTargetTexture                   = new RenderTexture(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf);
                m_ConvolutionTargetTexture.hideFlags         = HideFlags.HideAndDontSave;
                m_ConvolutionTargetTexture.dimension         = TextureDimension.Tex2D;
                m_ConvolutionTargetTexture.useMipMap         = true;
                m_ConvolutionTargetTexture.autoGenerateMips  = false;
                m_ConvolutionTargetTexture.filterMode        = FilterMode.Point;
                m_ConvolutionTargetTexture.name              = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true);
                m_ConvolutionTargetTexture.enableRandomWrite = true;
                m_ConvolutionTargetTexture.Create();

                // Clear to avoid garbage in the convolution texture.
                int mipCount = Mathf.FloorToInt(Mathf.Log(m_ProbeSize, 2)) + 1;
                for (int mipIdx = 0; mipIdx < mipCount; ++mipIdx)
                {
                    Graphics.SetRenderTarget(m_ConvolutionTargetTexture, mipIdx, CubemapFace.Unknown);
                    GL.Clear(false, true, Color.clear);
                }
            }

            m_FrameProbeIndex = 0;
        }
Пример #25
0
        public bool AllocTextureArray(int numCubeMaps, int width, GraphicsFormat format, bool isMipMapped, Material cubeBlitMaterial)
        {
            var res = AllocTextureArray(numCubeMaps);

            m_NumMipLevels = GetNumMips(width, width);      // will calculate same way whether we have cube array or not

            if (!TextureCache.supportsCubemapArrayTextures)
            {
                m_CubeBlitMaterial = cubeBlitMaterial;

                int panoWidthTop  = 4 * width;
                int panoHeightTop = 2 * width;

                // create panorama 2D array. Hardcoding the render target for now. No convenient way atm to
                // map from TextureFormat to RenderTextureFormat and don't want to deal with sRGB issues for now.
                m_CacheNoCubeArray = new Texture2DArray(panoWidthTop, panoHeightTop, numCubeMaps, format, isMipMapped ? TextureCreationFlags.MipChain : TextureCreationFlags.None)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Repeat,
                    wrapModeV  = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Trilinear,
                    anisoLevel = 0,
                    name       = CoreUtils.GetTextureAutoName(panoWidthTop, panoHeightTop, format, TextureDimension.Tex2DArray, depth: numCubeMaps, name: m_CacheName)
                };

                m_NumPanoMipLevels = isMipMapped ? GetNumMips(panoWidthTop, panoHeightTop) : 1;
                m_StagingRTs       = new RenderTexture[m_NumPanoMipLevels];
                for (int m = 0; m < m_NumPanoMipLevels; m++)
                {
                    m_StagingRTs[m] = new RenderTexture(Mathf.Max(1, panoWidthTop >> m), Mathf.Max(1, panoHeightTop >> m), 0, format)
                    {
                        hideFlags = HideFlags.HideAndDontSave
                    };
                    m_StagingRTs[m].name = CoreUtils.GetRenderTargetAutoName(Mathf.Max(1, panoWidthTop >> m), Mathf.Max(1, panoHeightTop >> m), 1, format, String.Format("PanaCache{0}", m));
                }

                if (m_CubeBlitMaterial)
                {
                    m_CubeMipLevelPropName = Shader.PropertyToID("_cubeMipLvl");
                    m_cubeSrcTexPropName   = Shader.PropertyToID("_srcCubeTexture");
                }
            }
            else
            {
                var desc = new RenderTextureDescriptor(width, width, format, 0)
                {
                    dimension        = TextureDimension.CubeArray,
                    volumeDepth      = numCubeMaps * 6, // We need to multiply by the face count of a cubemap here
                    autoGenerateMips = false,
                    useMipMap        = isMipMapped,
                    msaaSamples      = 1,
                };

                m_Cache = new RenderTexture(desc)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Trilinear,
                    anisoLevel = 0, // It is important to set 0 here, else unity force anisotropy filtering
                    name       = CoreUtils.GetTextureAutoName(width, width, format, desc.dimension, depth: numCubeMaps, name: m_CacheName, mips: isMipMapped)
                };

                // We need to clear the content in case it is read on first frame, since on console we have no guarantee that
                // the content won't be NaN
                ClearCache();
                m_Cache.Create();
            }

            return(res);
        }
    // This method wraps around regular RenderTexture creation.
    // There is no specific logic applied to RenderTextures created this way.
    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, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
            };
        }

        rt.Create();

        RTCategory category = enableMSAA ? RTCategory.MSAA : RTCategory.Regular;
        var        newRT    = new RTHandle(this);

        newRT.SetRenderTexture(rt, category);
        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);
    }
    // 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;
        RTCategory category    = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

        // 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 = 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, GraphicsFormatUtility.GetRenderTextureFormat(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, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
            };
        }

        rt.Create();

        var rth = new RTHandle(this);

        rth.SetRenderTexture(rt, category);
        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);
    }