Пример #1
0
        public bool AllocTextureArray(int numTextures, int width, int height, GraphicsFormat format, bool isMipMapped)
        {
            var res = AllocTextureArray(numTextures);

            m_NumMipLevels = GetNumMips(width, height);

            var desc = new RenderTextureDescriptor(width, width, format, 0)
            {
                // autoGenerateMips is true by default
                dimension   = TextureDimension.Tex2DArray,
                volumeDepth = numTextures,
                useMipMap   = isMipMapped,
                msaaSamples = 1,
            };

            m_Cache = new RenderTexture(desc)
            {
                hideFlags = HideFlags.HideAndDontSave,
                wrapMode  = TextureWrapMode.Clamp,
                name      = CoreUtils.GetTextureAutoName(width, height, format, TextureDimension.Tex2DArray, depth: numTextures, name: m_CacheName)
            };

            // 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);
        }
Пример #2
0
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, (int)LTCLightingModel.Count, GraphicsFormat.R16G16B16A16_SFloat, TextureCreationFlags.None)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Bilinear,
                    name       = CoreUtils.GetTextureAutoName(k_LtcLUTResolution, k_LtcLUTResolution, GraphicsFormat.R16G16B16A16_SFloat, depth: (int)LTCLightingModel.Count, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
                };

                LoadLUT(m_LtcData, (int)LTCLightingModel.GGX, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_GGX);
                LoadLUT(m_LtcData, (int)LTCLightingModel.DisneyDiffuse, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_Disney);

                LoadLUT(m_LtcData, (int)LTCLightingModel.Charlie, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_Charlie);
                LoadLUT(m_LtcData, (int)LTCLightingModel.FabricLambert, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_FabricLambert);

                LoadLUT(m_LtcData, (int)LTCLightingModel.KajiyaKaySpecular, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_KajiyaKaySpecular);
                LoadLUT(m_LtcData, (int)LTCLightingModel.KajiyaKayDiffuse, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_KajiyaKayDiffuse);

                LoadLUT(m_LtcData, (int)LTCLightingModel.CookTorrance, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_CookTorrance);
                LoadLUT(m_LtcData, (int)LTCLightingModel.Ward, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_Ward);
                LoadLUT(m_LtcData, (int)LTCLightingModel.OrenNayar, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_OrenNayar);

                m_LtcData.Apply();
            }

            m_refCounting++;
        }
Пример #3
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;
        }
Пример #4
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);
        }
Пример #5
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();
        }
Пример #6
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 bool AllocTextureArray(int numTextures, int width, int height, TextureFormat format, bool isMipMapped)
    {
        var res = AllocTextureArray(numTextures);

        m_NumMipLevels = GetNumMips(width, height);

        m_Cache = new Texture2DArray(width, height, numTextures, format, isMipMapped)
        {
            hideFlags = HideFlags.HideAndDontSave,
            wrapMode  = TextureWrapMode.Clamp,
            name      = CoreUtils.GetTextureAutoName(width, height, format, TextureDimension.Tex2DArray, depth: numTextures, name: m_CacheName)
        };

        return(res);
    }
Пример #8
0
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                m_PivotData = new Texture2D(k_PivotLUTResolution, k_PivotLUTResolution, GraphicsFormat.R16G16_SFloat, TextureCreationFlags.None)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Bilinear,
                    name       = CoreUtils.GetTextureAutoName(k_PivotLUTResolution, k_PivotLUTResolution, GraphicsFormat.R16G16_SFloat, depth: 0, dim: TextureDimension.Tex2D, name: "PIVOT_LUT")
                };

                LoadLUT(m_PivotData, s_PivotLUTData);

                m_PivotData.Apply();
            }

            m_refCounting++;
        }
Пример #9
0
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                m_PivotData = new Texture2D(k_PivotLUTResolution, k_PivotLUTResolution, TextureFormat.RGHalf, false /*mipmap*/, true /* linear */)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Bilinear,
                    name       = CoreUtils.GetTextureAutoName(k_PivotLUTResolution, k_PivotLUTResolution, TextureFormat.RGHalf, depth: 0, dim: TextureDimension.Tex2D, name: "PIVOT_LUT")
                };

                LoadLUT(m_PivotData, s_PivotLUTData);

                m_PivotData.Apply();
            }

            m_refCounting++;
        }
Пример #10
0
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                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: 2, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
                };

                LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, s_LtcGGXMatrixData);
                LoadLUT(m_LtcData, 1, TextureFormat.RGBAHalf, s_LtcDisneyDiffuseMatrixData);

                m_LtcData.Apply();
            }

            m_refCounting++;
        }
Пример #11
0
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

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

                LoadLUT(m_LtcData, 0, GraphicsFormat.R16G16B16A16_SFloat, s_LtcGGXMatrixData);
                LoadLUT(m_LtcData, 1, GraphicsFormat.R16G16B16A16_SFloat, s_LtcDisneyDiffuseMatrixData);

                m_LtcData.Apply();
            }

            m_refCounting++;
        }
Пример #12
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);
        }