Beispiel #1
0
        internal Texture Lerp(Texture from, Texture to, float t)
        {
            Assert.IsNotNull(from);
            Assert.IsNotNull(to);
            Assert.AreEqual(from.width, to.width);
            Assert.AreEqual(from.height, to.height);

            // Saves a potentially expensive fullscreen blit when using dirt textures & the likes
            if (from == to)
            {
                return(from);
            }

            bool is3D = from is Texture3D ||
                        (from is RenderTexture && ((RenderTexture)from).volumeDepth > 1);

            RenderTexture rt;

            // 3D texture blending is a special case and only works on compute enabled platforms
            if (is3D)
            {
                int dpth = @from is Texture3D ? ((Texture3D)@from).depth : ((RenderTexture)@from).volumeDepth;
                int size = Mathf.Max(from.width, from.height);
                size = Mathf.Max(size, dpth);

                rt = Get(RenderTextureFormat.ARGBHalf, from.width, from.height, dpth, true, true);

                var compute = m_Resources.computeShaders.texture3dLerp;
                int kernel  = compute.FindKernel("KTexture3DLerp");
                m_Command.SetComputeVectorParam(compute, "_DimensionsAndLerp", new Vector4(from.width, from.height, dpth, t));
                m_Command.SetComputeTextureParam(compute, kernel, "_Output", rt);
                m_Command.SetComputeTextureParam(compute, kernel, "_From", from);
                m_Command.SetComputeTextureParam(compute, kernel, "_To", to);

                int groupSizeXY = Mathf.CeilToInt(size / 8f);
                int groupSizeZ  = Mathf.CeilToInt(size / 8f);
                m_Command.DispatchCompute(compute, kernel, groupSizeXY, groupSizeXY, groupSizeZ);
                return(rt);
            }

            // 2D texture blending
            // We could handle textures with different sizes by picking the biggest one to avoid
            // popping effects. This would work in most cases but will still pop if one texture is
            // wider but shorter than the other. Generally speaking you're expected to use same-size
            // textures anyway so we decided not to handle this case at the moment, especially since
            // it would waste a lot of texture memory as soon as you start using bigger textures
            // (snow ball effect).
            var format = TextureFormatUtilities.GetUncompressedRenderTextureFormat(to);

            rt = Get(format, to.width, to.height);

            var sheet = m_PropertySheets.Get(m_Resources.shaders.texture2dLerp);

            sheet.properties.SetTexture(ShaderIDs.To, to);
            sheet.properties.SetFloat(ShaderIDs.Interp, t);

            m_Command.BlitFullscreenTriangle(from, rt, sheet, 0);

            return(rt);
        }
Beispiel #2
0
        internal Texture Lerp(Texture from, Texture to, float t)
        {
            if (from == to)
            {
                return(from);
            }
            RenderTexture renderTexture;

            if (from is Texture3D || (from is RenderTexture && ((RenderTexture)from).volumeDepth > 1))
            {
                int num = (!(from is Texture3D)) ? ((RenderTexture)from).volumeDepth : ((Texture3D)from).depth;
                int a   = Mathf.Max(from.width, from.height);
                a             = Mathf.Max(a, num);
                renderTexture = Get(RenderTextureFormat.ARGBHalf, from.width, from.height, num, enableRandomWrite: true, force3D: true);
                ComputeShader texture3dLerp = m_Resources.computeShaders.texture3dLerp;
                int           kernelIndex   = texture3dLerp.FindKernel("KTexture3DLerp");
                m_Command.SetComputeVectorParam(texture3dLerp, "_DimensionsAndLerp", new Vector4(from.width, from.height, num, t));
                m_Command.SetComputeTextureParam(texture3dLerp, kernelIndex, "_Output", renderTexture);
                m_Command.SetComputeTextureParam(texture3dLerp, kernelIndex, "_From", from);
                m_Command.SetComputeTextureParam(texture3dLerp, kernelIndex, "_To", to);
                int num2          = Mathf.CeilToInt((float)a / 8f);
                int threadGroupsZ = Mathf.CeilToInt((float)a / 8f);
                m_Command.DispatchCompute(texture3dLerp, kernelIndex, num2, num2, threadGroupsZ);
                return(renderTexture);
            }
            RenderTextureFormat uncompressedRenderTextureFormat = TextureFormatUtilities.GetUncompressedRenderTextureFormat(to);

            renderTexture = Get(uncompressedRenderTextureFormat, to.width, to.height);
            PropertySheet propertySheet = m_PropertySheets.Get(m_Resources.shaders.texture2dLerp);

            propertySheet.properties.SetTexture(ShaderIDs.To, to);
            propertySheet.properties.SetFloat(ShaderIDs.Interp, t);
            m_Command.BlitFullscreenTriangle(from, renderTexture, propertySheet, 0);
            return(renderTexture);
        }
Beispiel #3
0
        internal Texture Lerp(Texture from, Texture to, float t)
        {
            Assert.IsNotNull(from);
            Assert.IsNotNull(to);

            // Saves a potentially expensive fullscreen blit when using dirt textures & the likes
            if (from == to)
            {
                return(from);
            }

            bool is3d = to is Texture3D ||
                        (to is RenderTexture && ((RenderTexture)to).volumeDepth > 1);

            RenderTexture rt = null;

            if (is3d)
            {
                int size = to.width;
                rt = Get(RenderTextureFormat.ARGBHalf, size, size, size, true);

                var compute = m_Resources.computeShaders.texture3dLerp;
                int kernel  = compute.FindKernel("KTexture3DLerp");
                m_Command.SetComputeVectorParam(compute, "_Params", new Vector4(t, size, 0f, 0f));
                m_Command.SetComputeTextureParam(compute, kernel, "_Output", rt);
                m_Command.SetComputeTextureParam(compute, kernel, "_From", from);
                m_Command.SetComputeTextureParam(compute, kernel, "_To", to);

                int groupSizeXY = Mathf.CeilToInt(size / 8f);
                int groupSizeZ  = Mathf.CeilToInt(size / (RuntimeUtilities.isAndroidOpenGL ? 2f : 8f));
                m_Command.DispatchCompute(compute, kernel, groupSizeXY, groupSizeXY, groupSizeZ);
            }
            else
            {
                var format = TextureFormatUtilities.GetUncompressedRenderTextureFormat(to);
                rt = Get(format, to.width, to.height);

                var sheet = m_PropertySheets.Get(m_Resources.shaders.texture2dLerp);
                sheet.properties.SetTexture(ShaderIDs.To, to);
                sheet.properties.SetFloat(ShaderIDs.Interp, t);

                m_Command.BlitFullscreenTriangle(from, rt, sheet, 0);
            }

            return(rt);
        }
        internal Texture Lerp(Texture from, Texture to, float t)
        {
            Assert.IsNotNull(from);
            Assert.IsNotNull(to);

            bool is3d = to is Texture3D ||
                        (to is RenderTexture && ((RenderTexture)to).volumeDepth > 1);

            RenderTexture rt = null;

            bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;

            if (is3d)
            {
                int size = to.width;
                rt = Get(RenderTextureFormat.ARGBHalf, size, size, size, true);

                var compute = m_Resources.computeShaders.texture3dLerp;
                int kernel  = compute.FindKernel("KTexture3DLerp");
                m_Command.SetComputeVectorParam(compute, "_Params", new Vector4(t, size, 0f, 0f));
                m_Command.SetComputeTextureParam(compute, kernel, "_Output", rt);
                m_Command.SetComputeTextureParam(compute, kernel, "_From", from);
                m_Command.SetComputeTextureParam(compute, kernel, "_To", to);

                int groupSizeXY = Mathf.CeilToInt(size / 8f);
                int groupSizeZ  = Mathf.CeilToInt(size / (isAndroidOpenGL ? 2f : 8f));
                m_Command.DispatchCompute(compute, kernel, groupSizeXY, groupSizeXY, groupSizeZ);
            }
            else
            {
                var format = TextureFormatUtilities.GetUncompressedRenderTextureFormat(to);
                rt = Get(format, to.width, to.height);

                var sheet = m_PropertySheets.Get(m_Resources.shaders.texture2dLerp);
                sheet.properties.SetTexture(ShaderIDs.To, to);
                sheet.properties.SetFloat(ShaderIDs.Interp, t);

                m_Command.BlitFullscreenTriangle(from, rt, sheet, 0);
            }

            return(rt);
        }