| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Skybox |
| | 6 | | { |
| | 7 | | public static class SkyboxUtils |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Time for one complete circle. In Hours. default 24 |
| | 11 | | /// </summary> |
| | 12 | | public const float CYCLE_TIME = 24; |
| | 13 | | public const float DOME_DEFAULT_SIZE = 50; |
| | 14 | |
|
| | 15 | | public static float GetNormalizedDayTime(float timeOfTheDay) |
| | 16 | | { |
| | 17 | | float tTime = timeOfTheDay / SkyboxUtils.CYCLE_TIME; |
| | 18 | | tTime = Mathf.Clamp(tTime, 0, 1); |
| | 19 | | return tTime; |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public static Quaternion Vector4ToQuaternion(Vector4 val) { return new Quaternion(val.x, val.y, val.z, val.w); } |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public static class SkyboxShaderUtils |
| | 26 | | { |
| | 27 | | public const int TOTAL_SKYBOX_LAYERS = 5; |
| | 28 | |
|
| 0 | 29 | | private static Dictionary<string, int>[] shaderLayersProperties = null; |
| 0 | 30 | | public static readonly int LightTint = Shader.PropertyToID("_lightTint"); |
| 0 | 31 | | public static readonly int LightDirection = Shader.PropertyToID("_lightDirection"); |
| 0 | 32 | | public static readonly int SkyColor = Shader.PropertyToID("_skyColor"); |
| 0 | 33 | | public static readonly int GroundColor = Shader.PropertyToID("_groundColor"); |
| 0 | 34 | | public static readonly int HorizonColor = Shader.PropertyToID("_horizonColor"); |
| 0 | 35 | | public static readonly int HorizonHeight = Shader.PropertyToID("_horizonHeight"); |
| 0 | 36 | | public static readonly int HorizonWidth = Shader.PropertyToID("_horizonWidth"); |
| 0 | 37 | | public static readonly int HorizonMask = Shader.PropertyToID("_horizonMask"); |
| 0 | 38 | | public static readonly int HorizonMaskValues = Shader.PropertyToID("_horizonMaskValues"); |
| 0 | 39 | | public static readonly int HorizonPlane = Shader.PropertyToID("_horizonPlane"); |
| 0 | 40 | | public static readonly int HorizonPlaneValues = Shader.PropertyToID("_horizonPlaneValues"); |
| 0 | 41 | | public static readonly int HorizonPlaneColor = Shader.PropertyToID("_horizonPlaneColor"); |
| 0 | 42 | | public static readonly int HorizonPlaneHeight = Shader.PropertyToID("_horizonPlaneHeight"); |
| 0 | 43 | | public static readonly int PlaneSmoothRange = Shader.PropertyToID("_smoothRange"); |
| 0 | 44 | | public static readonly int HorizonLightIntensity = Shader.PropertyToID("_horizonLigthIntesity"); |
| 0 | 45 | | public static readonly int FogIntensity = Shader.PropertyToID("_fogIntesity"); |
| 0 | 46 | | public static readonly int Opacity = Shader.PropertyToID("_Opacity"); |
| | 47 | |
|
| 0 | 48 | | static SkyboxShaderUtils() { CacheShaderProperties(); } |
| | 49 | |
|
| | 50 | | static void CacheShaderProperties() |
| | 51 | | { |
| 0 | 52 | | if (shaderLayersProperties != null) return; |
| 0 | 53 | | shaderLayersProperties = new Dictionary<string, int>[TOTAL_SKYBOX_LAYERS]; |
| 0 | 54 | | for (int i = 0; i < TOTAL_SKYBOX_LAYERS; i++) |
| | 55 | | { |
| 0 | 56 | | shaderLayersProperties[i] = new Dictionary<string, int>(); |
| | 57 | |
|
| 0 | 58 | | shaderLayersProperties[i].Add("_layerType_", Shader.PropertyToID("_layerType_" + i)); |
| 0 | 59 | | shaderLayersProperties[i].Add("_fadeTime_" , Shader.PropertyToID("_fadeTime_" + i)); |
| | 60 | |
|
| 0 | 61 | | shaderLayersProperties[i].Add("_RenderDistance_" , Shader.PropertyToID("_RenderDistance_" + i)); |
| 0 | 62 | | shaderLayersProperties[i].Add("_tex_" , Shader.PropertyToID("_tex_" + i)); |
| 0 | 63 | | shaderLayersProperties[i].Add("_cubemap_" , Shader.PropertyToID("_cubemap_" + i)); |
| 0 | 64 | | shaderLayersProperties[i].Add("_normals_" , Shader.PropertyToID("_normals_" + i)); |
| 0 | 65 | | shaderLayersProperties[i].Add("_color_" , Shader.PropertyToID("_color_" + i)); |
| 0 | 66 | | shaderLayersProperties[i].Add("_timeFrame_" , Shader.PropertyToID("_timeFrame_" + i)); |
| 0 | 67 | | shaderLayersProperties[i].Add("_rowAndCollumns_" , Shader.PropertyToID("_rowAndCollumns_" + i)); |
| | 68 | |
|
| 0 | 69 | | shaderLayersProperties[i].Add("_lightIntensity_" , Shader.PropertyToID("_lightIntensity_" + i)); |
| 0 | 70 | | shaderLayersProperties[i].Add("_normalIntensity_" , Shader.PropertyToID("_normalIntensity_" + i)); |
| | 71 | |
|
| 0 | 72 | | shaderLayersProperties[i].Add("_distortIntAndSize_" , Shader.PropertyToID("_distortIntAndSize_" + i)); |
| 0 | 73 | | shaderLayersProperties[i].Add("_distortSpeedAndSharp_" , Shader.PropertyToID("_distortSpeedAndSharp_" + |
| | 74 | |
|
| | 75 | |
|
| 0 | 76 | | shaderLayersProperties[i].Add("_particlesMainParameters_" , Shader.PropertyToID("_particlesMainParameter |
| 0 | 77 | | shaderLayersProperties[i].Add("_particlesSecondaryParameters_" , Shader.PropertyToID("_particlesSecondar |
| | 78 | |
|
| 0 | 79 | | shaderLayersProperties[i].Add("_tilingAndOffset_" , Shader.PropertyToID("_tilingAndOffset_" + i )); |
| 0 | 80 | | shaderLayersProperties[i].Add("_speedAndRotation_" , Shader.PropertyToID("_speedAndRotation_" + i)); |
| | 81 | | } |
| | 82 | |
|
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | public static int GetLayerProperty(string name, int layer) |
| | 86 | | { |
| 0 | 87 | | if (layer >= TOTAL_SKYBOX_LAYERS) |
| | 88 | | { |
| 0 | 89 | | throw new ArgumentException($"Maximum Skybox Layers is {TOTAL_SKYBOX_LAYERS}"); |
| | 90 | | } |
| | 91 | |
|
| | 92 | | int propertyInt; |
| 0 | 93 | | if (shaderLayersProperties is not { Length: > 0 }) |
| | 94 | | { |
| 0 | 95 | | CacheShaderProperties(); |
| | 96 | | } |
| | 97 | |
|
| 0 | 98 | | if (shaderLayersProperties[layer].TryGetValue(name, out int val)) |
| | 99 | | { |
| 0 | 100 | | propertyInt = val; |
| | 101 | | } |
| | 102 | | else |
| | 103 | | { |
| 0 | 104 | | propertyInt = Shader.PropertyToID(name); |
| 0 | 105 | | shaderLayersProperties[layer].Add(name, propertyInt); |
| | 106 | | } |
| | 107 | |
|
| 0 | 108 | | return propertyInt; |
| | 109 | | } |
| | 110 | |
|
| | 111 | | } |
| | 112 | | } |