| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Diagnostics; |
| | 7 | | using UnityEngine.Rendering; |
| | 8 | |
|
| | 9 | | public class ShaderVariantTracker : IDisposable |
| | 10 | | { |
| | 11 | | private ShaderVariantCollection collection; |
| | 12 | |
|
| 0 | 13 | | public ShaderVariantTracker (ShaderVariantCollection collection) |
| | 14 | | { |
| 0 | 15 | | this.collection = collection; |
| | 16 | |
|
| 0 | 17 | | SRPBatchingHelper.OnMaterialProcess += OnMaterialProcess; |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | private void OnMaterialProcess(Material mat) |
| | 21 | | { |
| 0 | 22 | | var variant = CreateVariant(mat); |
| | 23 | |
|
| 0 | 24 | | if ( !collection.Contains(variant) ) |
| | 25 | | { |
| 0 | 26 | | collection.Add(variant); |
| 0 | 27 | | var keywordsString = JsonUtility.ToJson(variant.keywords, true); |
| 0 | 28 | | Debug.Log($"New variant found!\nShader: {variant.shader.name}\nKeywords:{keywordsString}"); |
| | 29 | | } |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | static ShaderVariantCollection.ShaderVariant CreateVariant(Material mat) |
| | 33 | | { |
| 0 | 34 | | var result = new ShaderVariantCollection.ShaderVariant(); |
| 0 | 35 | | result.shader = mat.shader; |
| 0 | 36 | | result.keywords = mat.shaderKeywords; |
| 0 | 37 | | result.passType = PassType.ScriptableRenderPipeline; |
| 0 | 38 | | return result; |
| | 39 | | } |
| | 40 | |
|
| 0 | 41 | | public void Dispose() { SRPBatchingHelper.OnMaterialProcess -= OnMaterialProcess; } |
| | 42 | | } |