| | 1 | | using System.Collections; |
| | 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 static Dictionary<string, int> shaderLayersProperties; |
| 0 | 28 | | public static readonly int LightTint = Shader.PropertyToID("_lightTint"); |
| 0 | 29 | | public static readonly int LightDirection = Shader.PropertyToID("_lightDirection"); |
| 0 | 30 | | public static readonly int SkyColor = Shader.PropertyToID("_skyColor"); |
| 0 | 31 | | public static readonly int GroundColor = Shader.PropertyToID("_groundColor"); |
| 0 | 32 | | public static readonly int HorizonColor = Shader.PropertyToID("_horizonColor"); |
| 0 | 33 | | public static readonly int HorizonHeight = Shader.PropertyToID("_horizonHeight"); |
| 0 | 34 | | public static readonly int HorizonWidth = Shader.PropertyToID("_horizonWidth"); |
| 0 | 35 | | public static readonly int HorizonMask = Shader.PropertyToID("_horizonMask"); |
| 0 | 36 | | public static readonly int HorizonMaskValues = Shader.PropertyToID("_horizonMaskValues"); |
| 0 | 37 | | public static readonly int HorizonPlane = Shader.PropertyToID("_horizonPlane"); |
| 0 | 38 | | public static readonly int HorizonPlaneValues = Shader.PropertyToID("_horizonPlaneValues"); |
| 0 | 39 | | public static readonly int HorizonPlaneColor = Shader.PropertyToID("_horizonPlaneColor"); |
| 0 | 40 | | public static readonly int HorizonPlaneHeight = Shader.PropertyToID("_horizonPlaneHeight"); |
| 0 | 41 | | public static readonly int PlaneSmoothRange = Shader.PropertyToID("_smoothRange"); |
| 0 | 42 | | public static readonly int HorizonLightIntensity = Shader.PropertyToID("_horizonLigthIntesity"); |
| 0 | 43 | | public static readonly int FogIntensity = Shader.PropertyToID("_fogIntesity"); |
| 0 | 44 | | public static readonly int Opacity = Shader.PropertyToID("_Opacity"); |
| | 45 | |
|
| 0 | 46 | | static SkyboxShaderUtils() { CacheShaderProperties(); } |
| | 47 | |
|
| | 48 | | static void CacheShaderProperties() |
| | 49 | | { |
| 0 | 50 | | shaderLayersProperties = new Dictionary<string, int>(); |
| 0 | 51 | | for (int i = 0; i < 5; i++) |
| | 52 | | { |
| 0 | 53 | | shaderLayersProperties.Add("_layerType_" + i, Shader.PropertyToID("_layerType_" + i)); |
| 0 | 54 | | shaderLayersProperties.Add("_fadeTime_" + i, Shader.PropertyToID("_fadeTime_" + i)); |
| | 55 | |
|
| 0 | 56 | | shaderLayersProperties.Add("_RenderDistance_" + i, Shader.PropertyToID("_RenderDistance_" + i)); |
| 0 | 57 | | shaderLayersProperties.Add("_tex_" + i, Shader.PropertyToID("_tex_" + i)); |
| 0 | 58 | | shaderLayersProperties.Add("_cubemap_" + i, Shader.PropertyToID("_cubemap_" + i)); |
| 0 | 59 | | shaderLayersProperties.Add("_normals_" + i, Shader.PropertyToID("_normals_" + i)); |
| 0 | 60 | | shaderLayersProperties.Add("_color_" + i, Shader.PropertyToID("_color_" + i)); |
| 0 | 61 | | shaderLayersProperties.Add("_timeFrame_" + i, Shader.PropertyToID("_timeFrame_" + i)); |
| 0 | 62 | | shaderLayersProperties.Add("_rowAndCollumns_" + i, Shader.PropertyToID("_rowAndCollumns_" + i)); |
| | 63 | |
|
| 0 | 64 | | shaderLayersProperties.Add("_lightIntensity_" + i, Shader.PropertyToID("_lightIntensity_" + i)); |
| 0 | 65 | | shaderLayersProperties.Add("_normalIntensity_" + i, Shader.PropertyToID("_normalIntensity_" + i)); |
| | 66 | |
|
| 0 | 67 | | shaderLayersProperties.Add("_distortIntAndSize_" + i, Shader.PropertyToID("_distortIntAndSize_" + i)); |
| 0 | 68 | | shaderLayersProperties.Add("_distortSpeedAndSharp_" + i, Shader.PropertyToID("_distortSpeedAndSharp_" + |
| | 69 | |
|
| | 70 | |
|
| 0 | 71 | | shaderLayersProperties.Add("_particlesMainParameters_" + i, Shader.PropertyToID("_particlesMainParameter |
| 0 | 72 | | shaderLayersProperties.Add("_particlesSecondaryParameters_" + i, Shader.PropertyToID("_particlesSecondar |
| | 73 | |
|
| 0 | 74 | | shaderLayersProperties.Add("_tilingAndOffset_" + i, Shader.PropertyToID("_tilingAndOffset_" + i)); |
| 0 | 75 | | shaderLayersProperties.Add("_speedAndRotation_" + i, Shader.PropertyToID("_speedAndRotation_" + i)); |
| | 76 | | } |
| | 77 | |
|
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | public static int GetLayerProperty(string name) |
| | 81 | | { |
| | 82 | | int propertyInt; |
| 0 | 83 | | if (shaderLayersProperties == null || shaderLayersProperties.Count <= 0) |
| | 84 | | { |
| 0 | 85 | | CacheShaderProperties(); |
| | 86 | | } |
| | 87 | |
|
| 0 | 88 | | if (!shaderLayersProperties.ContainsKey(name)) |
| | 89 | | { |
| 0 | 90 | | propertyInt = Shader.PropertyToID(name); |
| 0 | 91 | | shaderLayersProperties.Add(name, propertyInt); |
| 0 | 92 | | } |
| | 93 | | else |
| | 94 | | { |
| 0 | 95 | | propertyInt = shaderLayersProperties[name]; |
| | 96 | | } |
| | 97 | |
|
| 0 | 98 | | return propertyInt; |
| | 99 | | } |
| | 100 | |
|
| | 101 | | } |
| | 102 | | } |