using System.Collections.Generic; using UnityEngine; namespace UltimateWater.Internal { public class ShaderUtility : ScriptableObjectSingleton { private Dictionary _ShaderList; private Dictionary _ComputeShaderList; [SerializeField] private List _References; private static ShaderUtility _Instance; public static ShaderUtility Instance { get { return (_Instance != null) ? _Instance : (_Instance = ScriptableObjectSingleton.LoadSingleton()); } } public Shader Get(ShaderList type) { if (_ShaderList == null) { InitializeShaderList(); } AddReference(_ShaderList[(int)type]); return _ShaderList[(int)type]; } public ComputeShader Get(ComputeShaderList type) { if (_ComputeShaderList == null) { InitializeComputeShaderList(); } AddReference(_ComputeShaderList[(int)type]); return _ComputeShaderList[(int)type]; } public Material CreateMaterial(ShaderList type, HideFlags flags = HideFlags.None) { Material material = new Material(Get(type)); material.hideFlags = flags; return material; } public void Use(ShaderList shader) { if (_ShaderList == null) { InitializeShaderList(); } AddReference(_ShaderList[(int)shader]); } public void Use(ComputeShaderList shader) { if (_ComputeShaderList == null) { InitializeComputeShaderList(); } AddReference(_ComputeShaderList[(int)shader]); } private void InitializeShaderList() { _ShaderList = new Dictionary { { 0, Shader.Find("UltimateWater/Depth/Depth Copy") }, { 1, Shader.Find("UltimateWater/Depth/Water Depth") }, { 2, Shader.Find("UltimateWater/Volumes/Front") }, { 3, Shader.Find("UltimateWater/Volumes/Back") }, { 4, Shader.Find("UltimateWater/Volumes/Front Simple") }, { 5, Shader.Find("UltimateWater/Dynamic/Depth") }, { 6, Shader.Find("UltimateWater/Dynamic/Velocity") }, { 7, Shader.Find("UltimateWater/Dynamic/Simulation") }, { 8, Shader.Find("UltimateWater/Dynamic/Translate") }, { 9, Shader.Find("UltimateWater/Underwater/Screen-Space Mask") }, { 10, Shader.Find("UltimateWater/Underwater/Base IME") }, { 11, Shader.Find("UltimateWater/Underwater/Compose Underwater Mask") }, { 12, Shader.Find("UltimateWater/IME/Water Drops Mask") }, { 13, Shader.Find("UltimateWater/IME/Water Drops Normal") }, { 15, Shader.Find("UltimateWater/Raindrops/Final") }, { 14, Shader.Find("UltimateWater/Raindrops/Fade") }, { 16, Shader.Find("UltimateWater/Raindrops/PreciseParticle") }, { 17, Shader.Find("UltimateWater/Refraction/Collect Light") }, { 18, Shader.Find("UltimateWater/Refraction/Transmission") }, { 19, Shader.Find("UltimateWater/Deferred/GBuffer0Mix") }, { 20, Shader.Find("UltimateWater/Deferred/GBuffer123Mix") }, { 21, Shader.Find("UltimateWater/Deferred/FinalColorMix") }, { 22, Shader.Find("Hidden/UltimateWater-Internal-DeferredReflections") }, { 23, Shader.Find("Hidden/UltimateWater-Internal-DeferredShading") }, { 24, Shader.Find("UltimateWater/Utility/ShorelineMaskRender") }, { 25, Shader.Find("UltimateWater/Utility/ShorelineMaskRenderSimple") }, { 26, Shader.Find("UltimateWater/Utility/Noise") }, { 27, Shader.Find("UltimateWater/Utility/ShadowEnforcer") }, { 28, Shader.Find("UltimateWater/Utility/MergeDisplacements") } }; } private void InitializeComputeShaderList() { _ComputeShaderList = new Dictionary { { 0, Resources.Load("Shaders/Ripples - Simulation") }, { 1, Resources.Load("Shaders/Ripples - Setup") }, { 2, Resources.Load("Shaders/Gauss") }, { 3, Resources.Load("Shaders/Ripples - Transfer") } }; } private void AddReference(Object obj) { } } }