Exemplo n.º 1
0
        // This method wraps around regular RenderTexture creation.
        // There is no specific logic applied to RenderTextures created this way.
        public static RTHandle Alloc(
            int width,
            int height,
            int slices = 1,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None
            )
        {
            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;
            }

            var rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat, sRGB ? RenderTextureReadWrite.sRGB : 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   = useDynamicScale,
                vrUsage           = vrUsage,
                memorylessMode    = memoryless
            };

            rt.Create();

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

            newRT.SetRenderTexture(rt, category);
            newRT.useScaling          = false;
            newRT.m_EnableRandomWrite = enableRandomWrite;
            newRT.m_EnableMSAA        = enableMSAA;
            return(newRT);
        }
Exemplo n.º 2
0
        public HDShadowManager(RenderPipelineResources renderPipelineResources, DepthBits directionalShadowDepthBits,
                               HDShadowInitParameters.HDShadowAtlasInitParams punctualLightAtlasInfo, HDShadowInitParameters.HDShadowAtlasInitParams areaLightAtlasInfo, int maxShadowRequests, Shader clearShader)
        {
            Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader);

            // Prevent the list from resizing their internal container when we add shadow requests
            m_ShadowDatas.Capacity = maxShadowRequests;
            m_ShadowResolutionRequests.Capacity = maxShadowRequests;
            m_ShadowRequests = new HDShadowRequest[maxShadowRequests];

            // The cascade atlas will be allocated only if there is a directional light
            m_Atlas = new HDShadowAtlas(renderPipelineResources, punctualLightAtlasInfo.shadowAtlasResolution, punctualLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._ShadowAtlasSize, clearMaterial, false, depthBufferBits: punctualLightAtlasInfo.shadowAtlasDepthBits, name: "Shadow Map Atlas");
            // Cascade atlas render texture will only be allocated if there is a shadow casting directional light
            bool useMomentShadows = GetDirectionalShadowAlgorithm() == DirectionalShadowAlgorithm.IMS;

            m_CascadeAtlas = new HDShadowAtlas(renderPipelineResources, 1, 1, HDShaderIDs._CascadeShadowAtlasSize, clearMaterial, useMomentShadows, depthBufferBits: directionalShadowDepthBits, name: "Cascade Shadow Map Atlas");

            m_AreaLightShadowAtlas = new HDShadowAtlas(renderPipelineResources, areaLightAtlasInfo.shadowAtlasResolution, areaLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._AreaShadowAtlasSize, clearMaterial, false, BlurredEVSM: true, depthBufferBits: areaLightAtlasInfo.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas");
#if USE_PACKED_SHADOWDATA
            m_PackedShadowBuffer   = new ComputeBuffer(maxShadowRequests + 1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PackedShadowData)));
            m_packedShadowDataList = new List <PackedShadowData>(maxShadowRequests + 1);
#else
            m_ShadowDataBuffer            = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
            m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));
#endif

            m_MaxShadowRequests = maxShadowRequests;
        }
Exemplo n.º 3
0
        // Next two methods are used to allocate RenderTexture that depend on the frame settings (resolution and msaa for now)
        // RenderTextures allocated this way are meant to be defined by a scale of camera resolution (full/half/quarter resolution for example).
        // The idea is that internally the system will scale up the size of all render texture so that it amortizes with time and not reallocate when a smaller size is required (which is what happens with TemporaryRTs).
        // Since MSAA cannot be changed on the fly for a given RenderTexture, a separate instance will be created if the user requires it. This instance will be the one used after the next call of SetReferenceSize if MSAA is required.
        public RTHandle Alloc(
            Vector2 scaleFactor,
            int slices = 1,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            bool enableMSAA                    = false,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            // If an MSAA target is requested, make sure the support was on
            if (enableMSAA)
            {
                Debug.Assert(m_ScaledRTSupportsMSAA);
            }

            int width  = Mathf.Max(Mathf.RoundToInt(scaleFactor.x * GetMaxWidth()), 1);
            int height = Mathf.Max(Mathf.RoundToInt(scaleFactor.y * GetMaxHeight()), 1);

            var rth = AllocAutoSizedRenderTexture(width,
                                                  height,
                                                  slices,
                                                  depthBufferBits,
                                                  colorFormat,
                                                  filterMode,
                                                  wrapMode,
                                                  dimension,
                                                  sRGB,
                                                  enableRandomWrite,
                                                  useMipMap,
                                                  autoGenerateMips,
                                                  anisoLevel,
                                                  mipMapBias,
                                                  enableMSAA,
                                                  bindTextureMS,
                                                  useDynamicScale,
                                                  vrUsage,
                                                  memoryless,
                                                  name
                                                  );

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

            rth.scaleFactor = scaleFactor;
            return(rth);
        }
        //
        // You can provide your own scaling function for advanced scaling schemes (e.g. scaling to
        // the next POT). The function takes a Vec2 as parameter that holds max width & height
        // values for the current manager context and returns a Vec2 of the final size in pixels.
        //
        // var rth = Alloc(
        //     size => new Vector2Int(size.x / 2, size.y),
        //     [...]
        // );
        //
        public RTHandle Alloc(
            ScaleFunc scaleFunc,
            int slices = 1,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            bool enableMSAA                    = false,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            bool       allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false;
            RTCategory category     = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

            var scaleFactor = scaleFunc(new Vector2Int(GetMaxWidth(category), GetMaxHeight(category)));
            int width       = Mathf.Max(scaleFactor.x, 1);
            int height      = Mathf.Max(scaleFactor.y, 1);

            var rth = AllocAutoSizedRenderTexture(width,
                                                  height,
                                                  slices,
                                                  depthBufferBits,
                                                  colorFormat,
                                                  filterMode,
                                                  wrapMode,
                                                  dimension,
                                                  sRGB,
                                                  enableRandomWrite,
                                                  useMipMap,
                                                  autoGenerateMips,
                                                  anisoLevel,
                                                  mipMapBias,
                                                  enableMSAA,
                                                  bindTextureMS,
                                                  useDynamicScale,
                                                  vrUsage,
                                                  memoryless,
                                                  name
                                                  );

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

            rth.scaleFunc = scaleFunc;
            return(rth);
        }
Exemplo n.º 5
0
        //
        // You can provide your own scaling function for advanced scaling schemes (e.g. scaling to
        // the next POT). The function takes a Vec2 as parameter that holds max width & height
        // values for the current manager context and returns a Vec2 of the final size in pixels.
        //
        // var rth = Alloc(
        //     size => new Vector2Int(size.x / 2, size.y),
        //     [...]
        // );
        //
        public RTHandle Alloc(
            ScaleFunc scaleFunc,
            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,
            bool enableMSAA                    = false,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            bool xrInstancing                  = false,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            var scaleFactor = scaleFunc(new Vector2Int(GetMaxWidth(), GetMaxHeight()));
            int width       = Mathf.Max(scaleFactor.x, 1);
            int height      = Mathf.Max(scaleFactor.y, 1);

            var rth = AllocAutoSizedRenderTexture(width,
                                                  height,
                                                  slices,
                                                  depthBufferBits,
                                                  colorFormat,
                                                  filterMode,
                                                  wrapMode,
                                                  dimension,
                                                  enableRandomWrite,
                                                  useMipMap,
                                                  autoGenerateMips,
                                                  isShadowMap,
                                                  anisoLevel,
                                                  mipMapBias,
                                                  enableMSAA,
                                                  bindTextureMS,
                                                  useDynamicScale,
                                                  xrInstancing,
                                                  memoryless,
                                                  name
                                                  );

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

            rth.scaleFunc = scaleFunc;
            return(rth);
        }
Exemplo n.º 6
0
        public HDShadowAtlas(int width, int height, int atlasSizeShaderID, Material clearMaterial, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
        {
            this.width          = width;
            this.height         = height;
            m_FilterMode        = filterMode;
            m_DepthBufferBits   = depthBufferBits;
            m_Format            = format;
            m_Name              = name;
            m_AtlasSizeShaderID = atlasSizeShaderID;
            m_ClearMaterial     = clearMaterial;

            AllocateRenderTexture();
        }
Exemplo n.º 7
0
        // Next two methods are used to allocate RenderTexture that depend on the frame settings (resolution and msaa for now)
        // RenderTextures allocated this way are meant to be defined by a scale of camera resolution (full/half/quarter resolution for example).
        // The idea is that internally the system will scale up the size of all render texture so that it amortizes with time and not reallocate when a smaller size is required (which is what happens with TemporaryRTs).
        // Since MSAA cannot be changed on the fly for a given RenderTexture, a separate instance will be created if the user requires it. This instance will be the one used after the next call of SetReferenceSize if MSAA is required.
        public static RTHandle Alloc(
            Vector2 scaleFactor,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            bool enableMSAA                    = false,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None
            )
        {
            bool       allocForMSAA = s_ScaledRTSupportsMSAA ? enableMSAA : false;
            RTCategory category     = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

            int width  = Mathf.Max(Mathf.RoundToInt(scaleFactor.x * GetMaxWidth(category)), 1);
            int height = Mathf.Max(Mathf.RoundToInt(scaleFactor.y * GetMaxHeight(category)), 1);

            var rth = AllocAutoSizedRenderTexture(width,
                                                  height,
                                                  1,
                                                  depthBufferBits,
                                                  colorFormat,
                                                  filterMode,
                                                  wrapMode,
                                                  dimension,
                                                  sRGB,
                                                  enableRandomWrite,
                                                  useMipMap,
                                                  autoGenerateMips,
                                                  anisoLevel,
                                                  mipMapBias,
                                                  enableMSAA,
                                                  bindTextureMS,
                                                  useDynamicScale,
                                                  vrUsage,
                                                  memoryless
                                                  );

            rth.scaleFactor = scaleFactor;
            return(rth);
        }
Exemplo n.º 8
0
        public HDShadowManager(int width, int height, int maxShadowRequests, DepthBits shadowMapDepthBits, Shader clearShader)
        {
            Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader);

            m_CascadeAtlas = new HDShadowAtlas(width, height, clearMaterial, depthBufferBits: shadowMapDepthBits, name: "Cascade Shadow Map Atlas");
            m_Atlas        = new HDShadowAtlas(width, height, clearMaterial, depthBufferBits: shadowMapDepthBits, name: "Shadow Map Atlas");

            m_ShadowDataBuffer            = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
            m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

            m_Width             = width;
            m_maxShadowRequests = maxShadowRequests;
            m_Height            = height;
        }
Exemplo n.º 9
0
        //
        // You can provide your own scaling function for advanced scaling schemes (e.g. scaling to
        // the next POT). The function takes a Vec2 as parameter that holds max width & height
        // values for the current manager context and returns a Vec2 of the final size in pixels.
        //
        // var rth = Alloc(
        //     size => new Vector2Int(size.x / 2, size.y),
        //     [...]
        // );
        //
        public static RTHandle Alloc(
            ScaleFunc scaleFunc,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None
            )
        {
            var scaleFactor = scaleFunc(new Vector2Int(s_MaxWidth, s_MaxHeight));
            int width       = Mathf.Max(scaleFactor.x, 1);
            int height      = Mathf.Max(scaleFactor.y, 1);

            var rth = Alloc(width,
                            height,
                            1,
                            depthBufferBits,
                            colorFormat,
                            filterMode,
                            wrapMode,
                            dimension,
                            sRGB,
                            enableRandomWrite,
                            useMipMap,
                            autoGenerateMips,
                            anisoLevel,
                            mipMapBias,
                            msaaSamples,
                            bindTextureMS,
                            useDynamicScale,
                            vrUsage,
                            memoryless
                            );

            rth.scaleFunc = scaleFunc;
            s_AutoSizedRTs.Add(rth);
            return(rth);
        }
Exemplo n.º 10
0
        public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasSizeShaderID, Material clearMaterial, bool supportMomentShadows, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
        {
            this.width                = width;
            this.height               = height;
            m_FilterMode              = filterMode;
            m_DepthBufferBits         = depthBufferBits;
            m_Format                  = format;
            m_Name                    = name;
            m_AtlasSizeShaderID       = atlasSizeShaderID;
            m_ClearMaterial           = clearMaterial;
            m_SupportMomentShadows    = supportMomentShadows;
            m_RenderPipelineResources = renderPipelineResources;

            AllocateRenderTexture();
        }
Exemplo n.º 11
0
        public virtual void InitAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
        {
            this.width                = width;
            this.height               = height;
            m_FilterMode              = filterMode;
            m_DepthBufferBits         = depthBufferBits;
            m_Format                  = format;
            m_Name                    = name;
            m_AtlasShaderID           = atlasShaderID;
            m_ClearMaterial           = clearMaterial;
            m_BlurAlgorithm           = blurAlgorithm;
            m_RenderPipelineResources = renderPipelineResources;

            AllocateRenderTexture();
        }
Exemplo n.º 12
0
        public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, int atlasSizeShaderID, Material clearMaterial, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "", int momentAtlasShaderID = 0)
        {
            this.width                = width;
            this.height               = height;
            m_FilterMode              = filterMode;
            m_DepthBufferBits         = depthBufferBits;
            m_Format                  = format;
            m_Name                    = name;
            m_AtlasShaderID           = atlasShaderID;
            m_MomentAtlasShaderID     = momentAtlasShaderID;
            m_AtlasSizeShaderID       = atlasSizeShaderID;
            m_ClearMaterial           = clearMaterial;
            m_BlurAlgorithm           = blurAlgorithm;
            m_RenderPipelineResources = renderPipelineResources;

            AllocateRenderTexture();
        }
Exemplo n.º 13
0
 public static RTHandleSystem.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                   = 0,
     MSAASamples msaaSamples            = MSAASamples.None,
     bool bindTextureMS                 = false,
     bool useDynamicScale               = false,
     bool xrInstancing                  = false,
     RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
     string name = ""
     )
 {
     return(s_DefaultInstance.Alloc(
                width,
                height,
                slices,
                depthBufferBits,
                colorFormat,
                filterMode,
                wrapMode,
                dimension,
                enableRandomWrite,
                useMipMap,
                autoGenerateMips,
                isShadowMap,
                anisoLevel,
                mipMapBias,
                msaaSamples,
                bindTextureMS,
                useDynamicScale,
                xrInstancing,
                memoryless,
                name
                ));
 }
Exemplo n.º 14
0
        public static RTHandle Alloc(
            int width,
            int height,
            int slices = 1,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None
            )
        {
            var rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat, sRGB ? RenderTextureReadWrite.sRGB : 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   = useDynamicScale,
                vrUsage           = vrUsage,
                memorylessMode    = memoryless
            };

            rt.Create();

            return(new RTHandle(rt));
        }
Exemplo n.º 15
0
            internal HDShadowAtlasInitParameters(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID,
                                                 Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams, ConstantBuffer <ShaderVariablesGlobal> cb)
            {
                this.renderPipelineResources = renderPipelineResources;
                this.width             = width;
                this.height            = height;
                this.atlasShaderID     = atlasShaderID;
                this.clearMaterial     = clearMaterial;
                this.maxShadowRequests = maxShadowRequests;
                this.initParams        = initParams;
                this.blurAlgorithm     = BlurAlgorithm.None;
                this.filterMode        = FilterMode.Bilinear;
                this.depthBufferBits   = DepthBits.Depth16;
                this.format            = RenderTextureFormat.Shadowmap;
                this.name = "";

                this.cb = cb;
            }
Exemplo n.º 16
0
 public static RTHandleSystem.RTHandle Alloc(
     Vector2 scaleFactor,
     int slices = 1,
     DepthBits depthBufferBits       = DepthBits.None,
     RenderTextureFormat colorFormat = RenderTextureFormat.Default,
     FilterMode filterMode           = FilterMode.Point,
     TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
     TextureDimension dimension      = TextureDimension.Tex2D,
     bool sRGB = true,
     bool enableRandomWrite             = false,
     bool useMipMap                     = false,
     bool autoGenerateMips              = true,
     int anisoLevel                     = 1,
     float mipMapBias                   = 0,
     bool enableMSAA                    = false,
     bool bindTextureMS                 = false,
     bool useDynamicScale               = false,
     VRTextureUsage vrUsage             = VRTextureUsage.None,
     RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
     string name = ""
     )
 {
     return(s_DefaultInstance.Alloc(
                scaleFactor,
                slices,
                depthBufferBits,
                colorFormat,
                filterMode,
                wrapMode,
                dimension,
                sRGB,
                enableRandomWrite,
                useMipMap,
                autoGenerateMips,
                anisoLevel,
                mipMapBias,
                enableMSAA,
                bindTextureMS,
                useDynamicScale,
                vrUsage,
                memoryless,
                name
                ));
 }
Exemplo n.º 17
0
 public virtual void InitAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
 {
     this.width        = width;
     this.height       = height;
     m_FilterMode      = filterMode;
     m_DepthBufferBits = depthBufferBits;
     m_Format          = format;
     m_Name            = name;
     // With render graph, textures are "allocated" every frame so we need to prepare strings beforehand.
     m_MomentName                 = m_Name + "Moment";
     m_MomentCopyName             = m_Name + "MomentCopy";
     m_IntermediateSummedAreaName = m_Name + "IntermediateSummedArea";
     m_SummedAreaName             = m_Name + "SummedAreaFinal";
     m_AtlasShaderID              = atlasShaderID;
     m_ClearMaterial              = clearMaterial;
     m_BlurAlgorithm              = blurAlgorithm;
     m_RenderPipelineResources    = renderPipelineResources;
     m_IsACacheForShadows         = false;
 }
        public HDShadowManager(int width, int height, int maxShadowRequests, DepthBits atlasDepthBits, Shader clearShader)
        {
            Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader);

            // Prevent the list from resizing their internal container when we add shadow requests
            m_ShadowDatas.Capacity = maxShadowRequests;
            m_ShadowResolutionRequests.Capacity = maxShadowRequests;
            m_ShadowRequests = new HDShadowRequest[maxShadowRequests];

            // The cascade atlas will be allocated only if there is a directional light
            m_Atlas = new HDShadowAtlas(width, height, HDShaderIDs._ShadowAtlasSize, clearMaterial, depthBufferBits: atlasDepthBits, name: "Shadow Map Atlas");
            // Cascade atlas render texture will only be allocated if there is a shadow casting directional light
            m_CascadeAtlas = new HDShadowAtlas(1, 1, HDShaderIDs._CascadeShadowAtlasSize, clearMaterial, depthBufferBits: atlasDepthBits, name: "Cascade Shadow Map Atlas");

            m_ShadowDataBuffer            = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
            m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

            m_MaxShadowRequests = maxShadowRequests;
        }
Exemplo n.º 19
0
        public virtual void InitAtlas(HDShadowAtlasInitParameters initParams)
        {
            this.width             = initParams.width;
            this.height            = initParams.height;
            m_FilterMode           = initParams.filterMode;
            m_DepthBufferBits      = initParams.depthBufferBits;
            m_Format               = initParams.format;
            m_Name                 = initParams.name;
            m_GlobalConstantBuffer = initParams.cb;

            // With render graph, textures are "allocated" every frame so we need to prepare strings beforehand.
            m_MomentName                 = m_Name + "Moment";
            m_MomentCopyName             = m_Name + "MomentCopy";
            m_IntermediateSummedAreaName = m_Name + "IntermediateSummedArea";
            m_SummedAreaName             = m_Name + "SummedAreaFinal";
            m_AtlasShaderID              = initParams.atlasShaderID;
            m_ClearMaterial              = initParams.clearMaterial;
            m_BlurAlgorithm              = initParams.blurAlgorithm;
            m_RenderPipelineResources    = initParams.renderPipelineResources;
            m_IsACacheForShadows         = false;
        }
Exemplo n.º 20
0
        public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
        {
            this.width                = width;
            this.height               = height;
            m_FilterMode              = filterMode;
            m_DepthBufferBits         = depthBufferBits;
            m_Format                  = format;
            m_Name                    = name;
            m_AtlasShaderID           = atlasShaderID;
            m_ClearMaterial           = clearMaterial;
            m_BlurAlgorithm           = blurAlgorithm;
            m_RenderPipelineResources = renderPipelineResources;

            m_SortedRequestsCache      = new HDShadowResolutionRequest[Mathf.CeilToInt(maxShadowRequests * 1.5f)];
            m_CachedResolutionRequests = new HDShadowResolutionRequest[maxShadowRequests];
            for (int i = 0; i < maxShadowRequests; ++i)
            {
                m_CachedResolutionRequests[i] = new HDShadowResolutionRequest();
            }

            AllocateRenderTexture();
        }
Exemplo n.º 21
0
        public HDShadowManager(RenderPipelineResources renderPipelineResources, DepthBits directionalShadowDepthBits,
                               HDShadowInitParameters.HDShadowAtlasInitParams punctualLightAtlasInfo, HDShadowInitParameters.HDShadowAtlasInitParams areaLightAtlasInfo, int maxShadowRequests, Shader clearShader)
        {
            Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader);

            // Prevent the list from resizing their internal container when we add shadow requests
            m_ShadowDatas.Capacity = maxShadowRequests;
            m_ShadowResolutionRequests.Capacity = maxShadowRequests;
            m_ShadowRequests = new HDShadowRequest[maxShadowRequests];

            // The cascade atlas will be allocated only if there is a directional light
            m_Atlas = new HDShadowAtlas(renderPipelineResources, punctualLightAtlasInfo.shadowAtlasResolution, punctualLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._ShadowmapAtlas, HDShaderIDs._ShadowAtlasSize, clearMaterial, depthBufferBits: punctualLightAtlasInfo.shadowAtlasDepthBits, name: "Shadow Map Atlas");
            // Cascade atlas render texture will only be allocated if there is a shadow casting directional light
            HDShadowAtlas.BlurAlgorithm cascadeBlur = GetDirectionalShadowAlgorithm() == DirectionalShadowAlgorithm.IMS ? HDShadowAtlas.BlurAlgorithm.IM : HDShadowAtlas.BlurAlgorithm.None;
            m_CascadeAtlas = new HDShadowAtlas(renderPipelineResources, 1, 1, HDShaderIDs._ShadowmapCascadeAtlas, HDShaderIDs._CascadeShadowAtlasSize, clearMaterial, cascadeBlur, depthBufferBits: directionalShadowDepthBits, name: "Cascade Shadow Map Atlas");

            m_AreaLightShadowAtlas = new HDShadowAtlas(renderPipelineResources, areaLightAtlasInfo.shadowAtlasResolution, areaLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._AreaLightShadowmapAtlas, HDShaderIDs._AreaShadowAtlasSize, clearMaterial, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: areaLightAtlasInfo.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas", momentAtlasShaderID: HDShaderIDs._AreaShadowmapMomentAtlas);

            m_ShadowDataBuffer            = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
            m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

            m_MaxShadowRequests = maxShadowRequests;
        }
Exemplo n.º 22
0
 internal void InitAreaLightShadowAtlas(RenderPipelineResources renderPipelineResources, RenderGraph renderGraph, bool useSharedTexture, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams,
                                        HDShadowAtlas.BlurAlgorithm blurAlgorithm = HDShadowAtlas.BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
 {
     m_InitParams = initParams;
     areaShadowAtlas.InitAtlas(renderPipelineResources, renderGraph, useSharedTexture, width, height, atlasShaderID, clearMaterial, maxShadowRequests, initParams, blurAlgorithm, filterMode, depthBufferBits, format, name);
 }
Exemplo n.º 23
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, 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);
            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);
        }
Exemplo n.º 24
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, GraphicsFormatUtility.GetRenderTextureFormat(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);
        }
Exemplo n.º 25
0
        public override void InitAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
        {
            base.InitAtlas(renderPipelineResources, width, height, atlasShaderID, clearMaterial, maxShadowRequests, initParams, blurAlgorithm, filterMode, depthBufferBits, format, name);

            m_AtlasResolutionInSlots = HDUtils.DivRoundUp(width, m_MinSlotSize);
            m_AtlasSlots             = new List <bool>(m_AtlasResolutionInSlots * m_AtlasResolutionInSlots);
            for (int i = 0; i < m_AtlasResolutionInSlots * m_AtlasResolutionInSlots; ++i)
            {
                m_AtlasSlots.Add(false);
            }

            // Note: If changing the characteristics of the atlas via HDRP asset, the lights OnEnable will not be called again so we are missing them, however we can explicitly
            // put them back up for placement. If this is the first Init of the atlas, the lines below do nothing.
            DefragmentAtlasAndReRender(initParams);
            m_CanTryPlacement    = true;
            m_NeedOptimalPacking = true;
        }
Exemplo n.º 26
0
 public HDShadowAtlas(int width, int height, Material clearMaterial, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
 {
     m_Atlas         = RTHandles.Alloc(width, height, filterMode: filterMode, depthBufferBits: depthBufferBits, sRGB: false, colorFormat: format, name: name);
     m_Width         = width;
     m_Height        = height;
     identifier      = new RenderTargetIdentifier(m_Atlas);
     m_ClearMaterial = clearMaterial;
 }
Exemplo n.º 27
0
 public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
 {
     InitAtlas(renderPipelineResources, width, height, atlasShaderID, clearMaterial, maxShadowRequests, initParams, blurAlgorithm, filterMode, depthBufferBits, format, name);
 }
Exemplo n.º 28
0
 public HDDynamicShadowAtlas(RenderPipelineResources renderPipelineResources, RenderGraph renderGraph, bool useSharedTexture, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, HDShadowInitParameters initParams, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
     : base(renderPipelineResources, renderGraph, useSharedTexture, width, height, atlasShaderID, clearMaterial, maxShadowRequests, initParams, blurAlgorithm, filterMode, depthBufferBits, format, name)
 {
     m_SortedRequestsCache = new HDShadowResolutionRequest[Mathf.CeilToInt(maxShadowRequests)];
 }
Exemplo n.º 29
0
        // Internal function
        static RTHandle AllocAutoSizedRenderTexture(
            int width,
            int height,
            int slices,
            DepthBits depthBufferBits,
            RenderTextureFormat colorFormat,
            FilterMode filterMode,
            TextureWrapMode wrapMode,
            TextureDimension dimension,
            bool sRGB,
            bool enableRandomWrite,
            bool useMipMap,
            bool autoGenerateMips,
            int anisoLevel,
            float mipMapBias,
            bool enableMSAA,
            bool bindTextureMS,
            bool useDynamicScale,
            VRTextureUsage vrUsage,
            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 = s_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)s_ScaledRTCurrentMSAASamples : 1;
            RTCategory category    = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

            var rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat, sRGB ? RenderTextureReadWrite.sRGB : 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   = useDynamicScale,
                vrUsage           = vrUsage,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, colorFormat, name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: s_ScaledRTCurrentMSAASamples)
            };

            rt.Create();

            RTHandle rth = new RTHandle();

            rth.SetRenderTexture(rt, category);
            rth.m_EnableMSAA        = enableMSAA;
            rth.m_EnableRandomWrite = enableRandomWrite;
            rth.useScaling          = true;
            rth.m_Name = name;
            s_AutoSizedRTs.Add(rth);
            return(rth);
        }
Exemplo n.º 30
0
        public void InitShadowManager(RenderPipelineResources renderPipelineResources, DepthBits directionalShadowDepthBits,
                                      HDShadowInitParameters.HDShadowAtlasInitParams punctualLightAtlasInfo, HDShadowInitParameters.HDShadowAtlasInitParams areaLightAtlasInfo, int maxShadowRequests, Shader clearShader)
        {
            m_ClearShadowMaterial = CoreUtils.CreateEngineMaterial(clearShader);

            // Prevent the list from resizing their internal container when we add shadow requests
            m_ShadowDatas.Capacity        = Math.Max(maxShadowRequests, m_ShadowDatas.Capacity);
            m_ShadowResolutionRequests    = new HDShadowResolutionRequest[maxShadowRequests];
            m_ShadowRequests              = new HDShadowRequest[maxShadowRequests];
            m_CachedDirectionalShadowData = new HDDirectionalShadowData[1]; // we only support directional light shadow

            for (int i = 0; i < maxShadowRequests; i++)
            {
                m_ShadowResolutionRequests[i] = new HDShadowResolutionRequest();
            }

            // The cascade atlas will be allocated only if there is a directional light
            m_Atlas = new HDShadowAtlas(renderPipelineResources, punctualLightAtlasInfo.shadowAtlasResolution, punctualLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._ShadowmapAtlas, m_ClearShadowMaterial, maxShadowRequests, depthBufferBits: punctualLightAtlasInfo.shadowAtlasDepthBits, name: "Shadow Map Atlas");
            // Cascade atlas render texture will only be allocated if there is a shadow casting directional light
            HDShadowAtlas.BlurAlgorithm cascadeBlur = GetDirectionalShadowAlgorithm() == DirectionalShadowAlgorithm.IMS ? HDShadowAtlas.BlurAlgorithm.IM : HDShadowAtlas.BlurAlgorithm.None;
            m_CascadeAtlas = new HDShadowAtlas(renderPipelineResources, 1, 1, HDShaderIDs._ShadowmapCascadeAtlas, m_ClearShadowMaterial, maxShadowRequests, cascadeBlur, depthBufferBits: directionalShadowDepthBits, name: "Cascade Shadow Map Atlas");

            if (ShaderConfig.s_AreaLights == 1)
            {
                m_AreaLightShadowAtlas = new HDShadowAtlas(renderPipelineResources, areaLightAtlasInfo.shadowAtlasResolution, areaLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._ShadowmapAreaAtlas, m_ClearShadowMaterial, maxShadowRequests, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: areaLightAtlasInfo.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas");
            }

            m_ShadowDataBuffer            = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
            m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

            m_MaxShadowRequests = maxShadowRequests;
        }