Ejemplo n.º 1
0
        public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite)
        {
            VRTextureUsage vrUsage      = VRTextureUsage.None;
            int            antiAliasing = 1;

            return(GetTemporary(width, height, depthBuffer, format, readWrite, antiAliasing, vrUsage));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, RenderTextureMemoryless memorylessMode)
        {
            bool           useDynamicScale = false;
            VRTextureUsage vrUsage         = VRTextureUsage.None;

            return(RenderTexture.GetTemporary(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, vrUsage, useDynamicScale));
        }
Ejemplo n.º 4
0
        private void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            rtFormat  = src.format;
            srcWidth  = src.width / samples;
            srcHeight = src.height / samples;

#if UNITY_2017_2_OR_NEWER
            srcVRUsage = src.vrUsage;

            RenderTexture glowTexInner = GetTemporaryRT(srcWidth, srcHeight, src.vrUsage);
            RenderTexture tmpGlowTex   = GetTemporaryRT(srcWidth, srcHeight, src.vrUsage);
#else
            RenderTexture glowTexInner = GetTemporaryRT(srcWidth, srcHeight);
            RenderTexture tmpGlowTex   = GetTemporaryRT(srcWidth, srcHeight);
#endif

            switch (glowType)
            {
            case GlowType.Selective:
                SelectiveGlow(src, dest, glowTexInner, tmpGlowTex);
                break;

            case GlowType.Fullscreen:
                FullScreenGlow(src, dest, glowTexInner, tmpGlowTex);
                break;
            }

            RenderTexture.ReleaseTemporary(glowTexInner);
            RenderTexture.ReleaseTemporary(tmpGlowTex);
        }
Ejemplo n.º 5
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);
        }
Ejemplo 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);
        }
Ejemplo n.º 8
0
        private void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            rtFormat  = src.format;
            srcWidth  = src.width / samples;
            srcHeight = src.height / samples;

#if UNITY_2017_2_OR_NEWER
            srcVRUsage = src.vrUsage;

            RenderTexture glowTexInner = GetTemporaryRT(srcWidth, srcHeight, src.vrUsage);
            RenderTexture tmpGlowTex   = GetTemporaryRT(srcWidth, srcHeight, src.vrUsage);
#else
            RenderTexture glowTexInner = GetTemporaryRT(srcWidth, srcHeight);
            RenderTexture tmpGlowTex   = GetTemporaryRT(srcWidth, srcHeight);
#endif

            switch (glowType)
            {
            case GlowType.Selective:
#if UNITY_2017_2_OR_NEWER
                glowTexRaw = RenderTexture.GetTemporary((int)((Cam.pixelWidth) / samples), (int)((Cam.pixelHeight) / samples), 16, rtFormat, RenderTextureReadWrite.Default, 1, RenderTextureMemoryless.None, srcVRUsage);
#else
                glowTexRaw = RenderTexture.GetTemporary((int)((Cam.pixelWidth) / samples), (int)((Cam.pixelHeight) / samples), 16, rtFormat, RenderTextureReadWrite.Default, 1);
#endif
                SetupGlowCamera();
                SelectiveGlowCamera.RenderWithShader(selectiveRenderShader, "RenderType");
                break;

            case GlowType.Fullscreen:
                break;
            }
            blurMaterial.SetFloat("_VRMult", Cam.stereoEnabled ? 0.5f : 1.0f);
            compositeMaterial.SetFloat("_GlowIntensityInner", glowIntensityInner * ((glowType != GlowType.Fullscreen) ? GLOW_INTENSITY_MULT * blurSpreadInner : 10.0f));
            compositeMaterial.SetColor("_GlowTint", glowTint);

            switch (glowType)
            {
            case GlowType.Selective:
                SelectiveGlow(src, dest, glowTexInner, tmpGlowTex);
                break;

            case GlowType.Fullscreen:
                FullScreenGlow(src, dest, glowTexInner, tmpGlowTex);
                break;
            }

            RenderTexture.ReleaseTemporary(glowTexInner);
            RenderTexture.ReleaseTemporary(tmpGlowTex);
            RenderTexture.ReleaseTemporary(glowTexRaw);
        }
Ejemplo 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);
        }
Ejemplo n.º 10
0
 void InitDefaultValues(bool dynamicResolution, bool xrReady)
 {
     useDynamicScale = dynamicResolution;
     vrUsage         = VRTextureUsage.None;
     // XR Ready
     if (xrReady)
     {
         slices    = TextureXR.slices;
         dimension = TextureXR.dimension;
     }
     else
     {
         slices    = 1;
         dimension = TextureDimension.Tex2D;
     }
 }
Ejemplo n.º 11
0
 public static RTHandleSystem.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                   = 0,
     MSAASamples msaaSamples            = MSAASamples.None,
     bool bindTextureMS                 = false,
     bool useDynamicScale               = false,
     VRTextureUsage vrUsage             = VRTextureUsage.None,
     RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
     string name = ""
     )
 {
     return(s_DefaultInstance.Alloc(
                width,
                height,
                slices,
                depthBufferBits,
                colorFormat,
                filterMode,
                wrapMode,
                dimension,
                sRGB,
                enableRandomWrite,
                useMipMap,
                autoGenerateMips,
                anisoLevel,
                mipMapBias,
                msaaSamples,
                bindTextureMS,
                useDynamicScale,
                vrUsage,
                memoryless,
                name
                ));
 }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
0
        public static bool GetTemporaryImpl(ref RenderTexture __result, int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
        {
            int tID = Thread.CurrentThread.ManagedThreadId;

            if (RimThreaded.mainRequestWaits.TryGetValue(tID, out EventWaitHandle eventWaitStart))
            {
                object[] functionAndParameters = new object[] { safeFunction, new object[] { width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, useDynamicScale } };
                lock (RimThreaded.safeFunctionRequests)
                {
                    RimThreaded.safeFunctionRequests[tID] = functionAndParameters;
                }
                RimThreaded.mainThreadWaitHandle.Set();
                eventWaitStart.WaitOne();
                RimThreaded.safeFunctionResults.TryGetValue(tID, out object safeFunctionResult);
                __result = (RenderTexture)safeFunctionResult;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 14
0
 private static extern void Internal_SetVRUsage(RenderTexture mono, VRTextureUsage vrUsage);
Ejemplo n.º 15
0
 public static RenderTexture GetTemporary(int width, int height, [DefaultValue("0")] int depthBuffer, [DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [DefaultValue("1")] int antiAliasing, [DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode, [DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage, [DefaultValue("false")] bool useDynamicScale)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height)
     {
         depthBufferBits = depthBuffer,
         vrUsage = vrUsage,
         colorFormat = format,
         sRGB = (readWrite != RenderTextureReadWrite.Linear),
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         useDynamicScale = useDynamicScale
     }));
 }
Ejemplo n.º 16
0
 public static extern RenderTexture GetTemporary(int width, int height, [DefaultValue("0")] int depthBuffer, [DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [DefaultValue("1")] int antiAliasing, [DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage);
Ejemplo n.º 17
0
 public static bool GetTemporaryImpl(ref RenderTexture __result, int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     if (!CurrentThread.IsBackground || !allWorkerThreads.TryGetValue(CurrentThread, out ThreadInfo threadInfo))
     {
         return(true);
     }
     threadInfo.safeFunctionRequest = new object[] { safeFunction, new object[] { width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, useDynamicScale } };
     mainThreadWaitHandle.Set();
     threadInfo.eventWaitStart.WaitOne();
     __result = (RenderTexture)threadInfo.safeFunctionResult;
     return(false);
 }
Ejemplo n.º 18
0
 RenderTexture GetTemporaryRT(int width, int height, VRTextureUsage vrUsage)
 {
     return(RenderTexture.GetTemporary(width, height, 0, rtFormat, RenderTextureReadWrite.Default, 1, RenderTextureMemoryless.None, vrUsage));
 }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
 private static RenderTexture GetTemporaryImpl(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height, format, depthBuffer)
     {
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         vrUsage = vrUsage,
         useDynamicScale = useDynamicScale
     }));
 }
Ejemplo n.º 21
0
        // 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,
            bool xrInstancing                  = 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;
            }

            // XR override for instancing support
            VRTextureUsage vrUsage = VRTextureUsage.None;

            // 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,
                    vrUsage           = vrUsage,
                    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,
                    vrUsage           = vrUsage,
                    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);
        }
Ejemplo n.º 22
0
    static int GetTemporary(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            RenderTextureDescriptor arg0 = (RenderTextureDescriptor)LuaScriptMgr.GetNetObject(L, 1, typeof(RenderTextureDescriptor));
            RenderTexture           o    = RenderTexture.GetTemporary(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 2)
        {
            int           arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int           arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            RenderTexture o    = RenderTexture.GetTemporary(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 3)
        {
            int           arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int           arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int           arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTexture o    = RenderTexture.GetTemporary(arg0, arg1, arg2);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 4)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTexture       o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 5)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            RenderTexture          o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 6)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            int           arg5          = (int)LuaScriptMgr.GetNumber(L, 6);
            RenderTexture o             = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4, arg5);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 7)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            int arg5 = (int)LuaScriptMgr.GetNumber(L, 6);
            RenderTextureMemoryless arg6 = (RenderTextureMemoryless)LuaScriptMgr.GetNetObject(L, 7, typeof(RenderTextureMemoryless));
            RenderTexture           o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 8)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            int arg5 = (int)LuaScriptMgr.GetNumber(L, 6);
            RenderTextureMemoryless arg6 = (RenderTextureMemoryless)LuaScriptMgr.GetNetObject(L, 7, typeof(RenderTextureMemoryless));
            VRTextureUsage          arg7 = (VRTextureUsage)LuaScriptMgr.GetNetObject(L, 8, typeof(VRTextureUsage));
            RenderTexture           o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 9)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            int arg5 = (int)LuaScriptMgr.GetNumber(L, 6);
            RenderTextureMemoryless arg6 = (RenderTextureMemoryless)LuaScriptMgr.GetNetObject(L, 7, typeof(RenderTextureMemoryless));
            VRTextureUsage          arg7 = (VRTextureUsage)LuaScriptMgr.GetNetObject(L, 8, typeof(VRTextureUsage));
            bool          arg8           = LuaScriptMgr.GetBoolean(L, 9);
            RenderTexture o = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: RenderTexture.GetTemporary");
        }

        return(0);
    }
Ejemplo 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,
            bool xrInstancing,
            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;

            // XR override for instancing support
            VRTextureUsage vrUsage = VRTextureUsage.None;//TextureXR.OverrideRenderTexture(xrInstancing, ref dimension, ref slices);

            // 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,
                    vrUsage           = vrUsage,
                    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,
                    vrUsage           = vrUsage,
                    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);
        }
Ejemplo n.º 24
0
 private static RenderTexture GetTemporaryImpl(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height, format, depthBuffer)
     {
         sRGB = (readWrite != RenderTextureReadWrite.Linear),
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         vrUsage = vrUsage,
         useDynamicScale = useDynamicScale
     }));
 }
Ejemplo n.º 25
0
 public static RenderTexture GetTemporary(int width, int height, [UnityEngine.Internal.DefaultValue("0")] int depthBuffer, [UnityEngine.Internal.DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [UnityEngine.Internal.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [UnityEngine.Internal.DefaultValue("1")] int antiAliasing, [UnityEngine.Internal.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode, [UnityEngine.Internal.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage, [UnityEngine.Internal.DefaultValue("false")] bool useDynamicScale)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, vrUsage, useDynamicScale));
 }
Ejemplo n.º 26
0
 public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, RenderTextureMemoryless memorylessMode, VRTextureUsage vrUsage)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, vrUsage, false));
 }