void Start()
 {
     Debug.Log("Compiled shader: Start warm up");
     shaders.WarmUp();
     Debug.Log("Compiled shader: End warm up");
     SceneManager.LoadScene("SampleScene");
 }
Example #2
0
    public IEnumerable Init()
    {
        while (_IsLoading)
        {
            yield return(null);
        }

        if (_AssetBundle != null)
        {
            if (EntryPoint.Instance.GameCustomConfigParams.ShaderWarmUp)
            {
                ShaderVariantCollection shaderCollection = _AssetBundle.LoadAsset <ShaderVariantCollection>("svc");
                yield return(null);

                if (null != shaderCollection)
                {
                    shaderCollection.WarmUp();
                    yield return(null);
                }
            }

            var shaderListPath = "Assets/Outputs/Shader/ShaderList.prefab";
            var shaderListObj  = _AssetBundle.LoadAsset(shaderListPath) as GameObject;
            yield return(null);

            BuildShaderList(shaderListObj);
            _MobileCamtransOpaqueShader = FindShader("TERA/Environment/MobileCamtransOpaque");
            _MobileCamtransShader       = FindShader("TERA/Environment/MobileCamtrans");
            yield return(null);
        }
    }
Example #3
0
 void Awake()
 {
     if (!variantCollection.isWarmedUp)
     {
         variantCollection.WarmUp();
     }
 }
Example #4
0
        public void WarmUpShader()
        {
            if (!ConstantData.EnableAssetBundle)
            {
                return;
            }

            if (m_hasWarm)
            {
                return;
            }

            m_hasWarm = true;

            LoadBundle("shader", (data) => {
                AssetBundle ab = data as AssetBundle;
                if (ab == null)
                {
                    return;
                }

                ShaderVariantCollection variant = ab.LoadAsset <ShaderVariantCollection>("warmshader");
                if (variant != null)
                {
                    variant.WarmUp();
                }
            });
        }
Example #5
0
 public void AddShaderVariablesCollections(ShaderVariantCollection shaderVariantCollection, bool warmup = false)
 {
     if (!this.m_shaderVariantCollectionDict.ContainsKey(shaderVariantCollection.name))
     {
         this.m_shaderVariantCollectionDict.Add(shaderVariantCollection.name, shaderVariantCollection);
         if (warmup)
         {
             shaderVariantCollection.WarmUp();
         }
     }
 }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shaderVariantCollectionName"></param>
 /// <remarks>todo:貌似预加载preload后会自动 warmup</remarks>
 public void WarmupShaderVariablesCollection(string shaderVariantCollectionName)
 {
     if (this.m_shaderVariantCollectionDict.ContainsKey(shaderVariantCollectionName))
     {
         ShaderVariantCollection shaderCollection = this.m_shaderVariantCollectionDict[shaderVariantCollectionName];
         if (!shaderCollection.isWarmedUp)
         {
             shaderCollection.WarmUp();
         }
     }
 }
        public override void Setup()
        {
            base.Setup();
            m_SegmentationShader = Shader.Find(k_SegmentationPassShaderName);
            var shaderVariantCollection = new ShaderVariantCollection();

            shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_SegmentationShader, PassType.ScriptableRenderPipeline));
            shaderVariantCollection.WarmUp();

            m_OverrideMaterial = new Material(m_SegmentationShader);
        }
Example #8
0
    void LoadShadervariantCompleted(int iHandle, UnityEngine.Object obj)
    {
        ShaderVariantCollection shader = obj as ShaderVariantCollection;

        if (shader != null)
        {
            Debug.Log(shader.shaderCount);
            Debug.Log(shader.variantCount);
            shader.WarmUp();
        }
    }
 private void LoadSVC(string svcFileName)
 {
     if (m_ab != null)
     {
         ShaderVariantCollection svc = m_ab.LoadAsset <ShaderVariantCollection>(svcFileName);
         if (svc != null)
         {
             svc.WarmUp();
         }
     }
 }
        public override void Setup()
        {
            base.Setup();
            m_ClassLabelingShader = Shader.Find(k_ShaderName);

            var shaderVariantCollection = new ShaderVariantCollection();

            if (shaderVariantCollection != null)
            {
                shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_ClassLabelingShader, PassType.ScriptableRenderPipeline));
            }

            m_OverrideMaterial = new Material(m_ClassLabelingShader);

            shaderVariantCollection.WarmUp();
        }
Example #11
0
        /// <summary>
        /// 预加载所有 Shader
        /// </summary>
        public static void PreloadShaders()
        {
            if (Common.IsDebug)
            {
                return;
            }

            DateTime  dateTime = DateTime.Now;
            AssetInfo info     = GetAssetInfoWithAssetPath(Constants.SvcFilePath);

            AssetLoader.Load(info, Constants.CoreAssetGroup);
            info.ab.LoadAllAssets();
            ShaderVariantCollection svc = info.ab.LoadAsset <ShaderVariantCollection>(Constants.ResDirPath + Constants.SvcFilePath);

            svc.WarmUp();
            Debug.Log("[ResManager] Shaders Preload and WarmUp: " + (DateTime.Now - dateTime).Milliseconds / 1000f);
        }
        public override void Setup()
        {
            base.Setup();
            m_LensDistortionShader = Shader.Find(k_ShaderName);

            var shaderVariantCollection = new ShaderVariantCollection();

            if (shaderVariantCollection != null)
            {
                shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_LensDistortionShader, PassType.ScriptableRenderPipeline));
            }

            m_LensDistortionMaterial = new Material(m_LensDistortionShader);

            if (shaderVariantCollection != null)
            {
                shaderVariantCollection.WarmUp();
            }

            // Set up a new texture
            if (m_DistortedTexture == null || m_DistortedTexture.width != Screen.width || m_DistortedTexture.height != Screen.height)
            {
                if (m_DistortedTexture != null)
                {
                    m_DistortedTexture.Release();
                }

                m_DistortedTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
                m_DistortedTexture.enableRandomWrite = true;
                m_DistortedTexture.filterMode        = FilterMode.Point;
                m_DistortedTexture.Create();
            }

            // Grab the lens distortion
#if HDRP_PRESENT
            // Grab the Lens Distortion from Perception Camera stack
            var hdCamera = HDCamera.GetOrCreate(targetCamera);
            var stack    = hdCamera.volumeStack;
            m_LensDistortion = stack.GetComponent <LensDistortion>();
#elif URP_PRESENT
            var stack = VolumeManager.instance.stack;
            m_LensDistortion = stack.GetComponent <LensDistortion>();
#endif
            m_Initialized = true;
        }
Example #13
0
    void Awake()
    {
        if (Instance != null)
        {
            return;
        }

        DontDestroyOnLoad(gameObject);
        Instance = this;
        if (shaderVariantCollection != null)
        {
            shaderVariantCollection.WarmUp();
        }
        else
        {
            Shader.WarmupAllShaders();
        }
    }
    public void CacheShadersFromPackage(string cahced_package_name)
    {
        //IL_002d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0032: Expected O, but got Unknown
        //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
        //IL_00b8: Unknown result type (might be due to invalid IL or missing references)
        //IL_00be: Unknown result type (might be due to invalid IL or missing references)
        PackageObject cachedPackage = GetCachedPackage(cahced_package_name);

        if (cachedPackage != null)
        {
            AssetBundle val = cachedPackage.obj as AssetBundle;
            if (val != null)
            {
                Shader[] array = val.LoadAllAssets <Shader>();
                ShaderVariantCollection val2 = new ShaderVariantCollection();
                int i = 0;
                for (int num = array.Length; i < num; i++)
                {
                    if (!array[i].get_isSupported())
                    {
                        Log.Error("no support shader : " + array[i].get_name());
                    }
                    string name = array[i].get_name();
                    shaderCaches.Add(name, array[i]);
                    if (name.StartsWith("EeL") || name.Contains("effect"))
                    {
                        ShaderVariant val3 = default(ShaderVariant);
                        val3.shader = array[i];
                        val2.Add(val3);
                    }
                }
                if (!val2.get_isWarmedUp())
                {
                    val2.WarmUp();
                }
            }
        }
    }
Example #15
0
 private void Start()
 {
     Shaders.WarmUp();
 }
    /// <summary>
    /// 加载所有assetbundle
    /// </summary>
    /// <returns></returns>
    static IEnumerator IE_01_LoadAll(bool isAsyncLoad = false)
    {
        var outpath = BApplication.BDEditorCachePath + "/AssetBundle";

        if (!Directory.Exists(outpath))
        {
            Directory.CreateDirectory(outpath);
        }

        loadDataMap.Clear();
        //加载
        foreach (var assetdata in AssetBundleLoader.AssetConfigLoder.AssetbundleItemList)
        {
            if (string.IsNullOrEmpty(assetdata.LoadPath))
            {
                continue;
            }

            var typeName    = AssetBundleLoader.AssetConfigLoder.AssetTypes.AssetTypeList[assetdata.AssetType];
            var runtimePath = assetdata.LoadPath;
            //加载
            //Debug.Log("【LoadTest】:" + runtimePath);
            if (!loadDataMap.ContainsKey(typeName))
            {
                loadDataMap[typeName] = new List <LoadTimeData>();
            }

            var loadList = loadDataMap[typeName];
            //
            var loadData = new LoadTimeData();
            loadData.LoadPath = runtimePath;
            loadList.Add(loadData);
            //计时器
            Stopwatch sw = new Stopwatch();
            if (typeName == typeof(GameObject).FullName)
            {
                //加载
                sw.Start();
                GameObject obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <GameObject>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <GameObject>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <GameObject>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                //实例化
                if (obj != null)
                {
                    sw.Restart();
                    var gobj = GameObject.Instantiate(obj);
                    sw.Stop();
                    loadData.InstanceTime = sw.ElapsedTicks;
                    //UI
                    var rectTransform = gobj.GetComponentInChildren <RectTransform>();
                    if (rectTransform != null)
                    {
                        gobj.transform.SetParent(UI_ROOT, false);
                    }
                    else
                    {
                        gobj.transform.SetParent(SCENE_ROOT);
                    }

                    //抓屏 保存
                    var outpng = string.Format("{0}/{1}_ab.png", outpath, runtimePath.Replace("/", "_"));
                    yield return(null);

                    //渲染
                    // GameView.Repaint();
                    // GameView.Focus();

                    yield return(null);

                    //抓屏
                    //TODO 这里有时候能抓到 有时候抓不到

                    ScreenCapture.CaptureScreenshot(outpng);
                    //删除
                    GameObject.DestroyImmediate(gobj);
                }
                else
                {
                    UnityEngine.Debug.LogError("【Prefab】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(TextAsset).FullName)
            {
                //测试打印AssetText资源
                sw.Start();
                TextAsset obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <TextAsset>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <TextAsset>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <TextAsset>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【TextAsset】加载失败:" + runtimePath);
                }
                else
                {
                    UnityEngine.Debug.Log(obj.text);
                }
            }
            else if (typeName == typeof(Texture).FullName)
            {
                sw.Start();
                Texture obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Texture>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Texture>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Texture>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Texture】加载失败:" + runtimePath);
                }

                break;
            }
            else if (typeName == typeof(Texture2D).FullName)
            {
                sw.Start();
                Texture2D obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Texture2D>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Texture2D>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Texture2D>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Texture2D】加载失败:" + runtimePath);
                }
                else
                {
                    spriteRendererNode.gameObject.SetActive(true);
                    spriteRendererNode.sprite = Sprite.Create(obj, new Rect(Vector2.zero, obj.texelSize), new Vector2(0.5f, 0.5f), 128);
                    yield return(null);

                    spriteRendererNode.gameObject.SetActive(false);
                }
            }
            else if (typeName == typeof(Sprite).FullName)
            {
                sw.Start();
                Sprite obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Sprite>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Sprite>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Sprite>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Sprite】加载失败:" + runtimePath);
                }
                else
                {
                    imageNode.gameObject.SetActive(true);
                    imageNode.overrideSprite = obj;
                    imageNode.SetNativeSize();
                    yield return(null);

                    imageNode.gameObject.SetActive(false);
                }
            }
            else if (typeName == typeof(Material).FullName)
            {
                sw.Start();
                Material obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Material>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Material>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Material>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Material】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(Shader).FullName)
            {
                sw.Start();
                var obj = AssetBundleLoader.Load <Shader>(runtimePath);
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Shader>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Shader>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Shader>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Shader】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(AudioClip).FullName)
            {
                sw.Start();
                AudioClip obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <AudioClip>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <AudioClip>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <AudioClip>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【AudioClip】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(AnimationClip).FullName)
            {
                sw.Start();
                AnimationClip obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <AnimationClip>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <AnimationClip>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <AnimationClip>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【AnimationClip】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(Mesh).FullName)
            {
                sw.Start();
                Mesh obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Mesh>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Mesh>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Mesh>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Mesh】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(Font).FullName)
            {
                sw.Start();
                Font obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Font>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Font>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Font>(runtimePath);
                }

                sw.Stop();
                loadData.LoadTime = sw.ElapsedTicks;
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Font】加载失败:" + runtimePath);
                }
            }
            else if (typeName == typeof(SpriteAtlas).FullName)
            {
                sw.Start();

                SpriteAtlas obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <SpriteAtlas>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <SpriteAtlas>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <SpriteAtlas>(runtimePath);
                }

                sw.Stop();
                if (!obj)
                {
                    //  UnityEngine.Debug.LogError("【SpriteAtlas】加载失败:" + runtimePath);
                }

                loadData.LoadTime = sw.ElapsedTicks;
            }
            else if (typeName == typeof(ShaderVariantCollection).FullName)
            {
                sw.Start();

                ShaderVariantCollection obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <ShaderVariantCollection>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <ShaderVariantCollection>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <ShaderVariantCollection>(runtimePath);
                }

                obj?.WarmUp();
                sw.Stop();
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【ShaderVariantCollection】加载失败:" + runtimePath);
                }

                loadData.LoadTime = sw.ElapsedTicks;
            }
            else
            {
                sw.Start();
                Object obj = null;
                //异步
                if (isAsyncLoad)
                {
                    var ret = AssetBundleLoader.CreateAsyncLoadTask <Object>(runtimePath);
                    yield return(ret);

                    if (ret.IsSuccess)
                    {
                        obj = ret.GetAssetBundleInstance <Object>();
                    }
                }
                //同步
                else
                {
                    obj = AssetBundleLoader.Load <Object>(runtimePath);
                }
                sw.Stop();
                if (!obj)
                {
                    UnityEngine.Debug.LogError("【Object】加载失败:" + runtimePath);
                }

                UnityEngine.Debug.LogError("待编写测试! -" + typeName);
            }

            //打印

            Debug.LogFormat("<color=yellow>{0}</color> <color=green>【加载】:<color=yellow>{1}ms</color>;【初始化】:<color=yellow>{2}ms</color> </color>", loadData.LoadPath, loadData.LoadTime / 10000f, loadData.InstanceTime / 10000f);
            yield return(null);
        }

        yield return(null);

        // foreach (var item in loadDataMap)
        // {
        //     Debug.Log("<color=red>【" + item.Key + "】</color>");
        //     foreach (var ld in item.Value)
        //     {
        //         Debug.LogFormat("<color=yellow>{0}</color> <color=green>【加载】:<color=yellow>{1}ms</color>;【初始化】:<color=yellow>{2}ms</color> </color>", ld.LoadPath, ld.LoadTime / 10000f, ld.InstanceTime / 10000f);
        //     }
        // }

        //
        var content = JsonMapper.ToJson(loadDataMap);

        FileHelper.WriteAllText(BenchmarkResultPath, content);

        yield return(null);

// #if UNITY_EDITOR
//         EditorUtility.RevealInFinder(outpath);
// #endif
    }
Example #17
0
 void Start()
 {
     // SceneManager.sceneLoaded += DestroyLoadPlayer;
     shaderVariantCollection.WarmUp();
 }
Example #18
0
 void Awake()
 {
     // Do this here because the array in GraphicsSettings doesn't seem to be getting used when running inside the editor
     ShaderVariants.WarmUp();
 }