| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Skybox |
| | 6 | | { |
| | 7 | | public static class TextureLayerFunctionality |
| | 8 | | { |
| | 9 | | public static void ApplyTextureLayer(Material selectedMat, float dayTime, float normalizedDayTime, int slotNum, |
| | 10 | | { |
| 0 | 11 | | float endTimeEdited = layer.timeSpan_End; |
| 0 | 12 | | float dayTimeEdited = dayTime; |
| 0 | 13 | | if (layer.timeSpan_End < layer.timeSpan_start) |
| | 14 | | { |
| 0 | 15 | | endTimeEdited = cycleTime + layer.timeSpan_End; |
| 0 | 16 | | if (dayTime < layer.timeSpan_start) |
| | 17 | | { |
| 0 | 18 | | dayTimeEdited = cycleTime + dayTime; |
| | 19 | | } |
| | 20 | | } |
| 0 | 21 | | float normalizedLayerTime = Mathf.InverseLerp(layer.timeSpan_start, endTimeEdited, dayTimeEdited); |
| | 22 | |
|
| 0 | 23 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_layerType_" + slotNum), (int)layer.layerType); |
| | 24 | |
|
| 0 | 25 | | bool fadeInChange = CheckFadingIn(selectedMat, dayTime, normalizedDayTime, slotNum, layer, cycleTime); |
| | 26 | |
|
| 0 | 27 | | bool fadeOutChange = CheckFadingOut(selectedMat, dayTime, normalizedDayTime, slotNum, layer, cycleTime); |
| | 28 | |
|
| 0 | 29 | | if (!fadeInChange && !fadeOutChange) |
| | 30 | | { |
| 0 | 31 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotNum), 1); |
| | 32 | | } |
| | 33 | |
|
| 0 | 34 | | switch (layer.layerType) |
| | 35 | | { |
| | 36 | | case LayerType.Planar: |
| | 37 | | case LayerType.Radial: |
| 0 | 38 | | ApplyPlanarTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true); |
| 0 | 39 | | break; |
| | 40 | | case LayerType.Satellite: |
| 0 | 41 | | ApplySatelliteTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true); |
| 0 | 42 | | break; |
| | 43 | | case LayerType.Cubemap: |
| 0 | 44 | | ApplyCubemapTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true); |
| 0 | 45 | | break; |
| | 46 | | case LayerType.Particles: |
| 0 | 47 | | ApplyParticleTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true); |
| | 48 | | break; |
| | 49 | | default: |
| | 50 | | break; |
| | 51 | | } |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | private static bool CheckFadingIn(Material selectedMat, float dayTime, float normalizedDayTime, int slotNum, Tex |
| | 55 | | { |
| 0 | 56 | | bool fadeChanged = false; |
| 0 | 57 | | float fadeInCompletionTime = layer.timeSpan_start + layer.fadingInTime; |
| 0 | 58 | | float dayTimeEdited = dayTime; |
| 0 | 59 | | if (dayTime < layer.timeSpan_start) |
| | 60 | | { |
| 0 | 61 | | dayTimeEdited = 24 + dayTime; |
| | 62 | | } |
| | 63 | |
|
| 0 | 64 | | if (dayTimeEdited < fadeInCompletionTime) |
| | 65 | | { |
| 0 | 66 | | float percentage = Mathf.InverseLerp(layer.timeSpan_start, fadeInCompletionTime, dayTimeEdited); |
| 0 | 67 | | fadeChanged = true; |
| 0 | 68 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotNum), percentage); |
| | 69 | | } |
| | 70 | |
|
| 0 | 71 | | return fadeChanged; |
| | 72 | | } |
| | 73 | |
|
| | 74 | | private static bool CheckFadingOut(Material selectedMat, float dayTime, float normalizedDayTime, int slotNum, Te |
| | 75 | | { |
| 0 | 76 | | bool fadeChanged = false; |
| 0 | 77 | | float endTimeEdited = layer.timeSpan_End; |
| 0 | 78 | | float dayTimeEdited = dayTime; |
| | 79 | |
|
| 0 | 80 | | if (layer.timeSpan_End < layer.timeSpan_start) |
| | 81 | | { |
| 0 | 82 | | endTimeEdited = cycleTime + layer.timeSpan_End; |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | if (dayTime < layer.timeSpan_start) |
| | 86 | | { |
| 0 | 87 | | dayTimeEdited = cycleTime + dayTime; |
| | 88 | | } |
| | 89 | |
|
| | 90 | |
|
| 0 | 91 | | float fadeOutStartTime = endTimeEdited - layer.fadingOutTime; |
| | 92 | |
|
| 0 | 93 | | if (dayTimeEdited > fadeOutStartTime) |
| | 94 | | { |
| 0 | 95 | | float percentage = Mathf.InverseLerp(endTimeEdited, fadeOutStartTime, dayTimeEdited); |
| 0 | 96 | | fadeChanged = true; |
| 0 | 97 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotNum), percentage); |
| | 98 | | } |
| | 99 | |
|
| 0 | 100 | | return fadeChanged; |
| | 101 | | } |
| | 102 | |
|
| | 103 | | private static void ApplyCubemapTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, int |
| | 104 | | { |
| 0 | 105 | | if (changeAlllValues) |
| | 106 | | { |
| 0 | 107 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + layerNum), 0); |
| 0 | 108 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), null); |
| 0 | 109 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), layer.cubemap); |
| 0 | 110 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_normals_" + layerNum), null); |
| 0 | 111 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.ti |
| 0 | 112 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercen |
| 0 | 113 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_normalIntensity_" + layerNum), 0); |
| 0 | 114 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), Vector2.zero |
| 0 | 115 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), Vector4.z |
| | 116 | | // Particles |
| 0 | 117 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), Vector2.zero); |
| 0 | 118 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), Vector |
| 0 | 119 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), V |
| | 120 | | } |
| | 121 | |
|
| | 122 | |
|
| 0 | 123 | | selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz |
| | 124 | |
|
| | 125 | | // Set cubemap rotation. (Shader variable reused) |
| 0 | 126 | | if (layer.movementTypeCubemap == MovementType.PointBased) |
| | 127 | | { |
| 0 | 128 | | Vector3 currentRotation = TransitioningValues.GetTransitionValue(layer.rotations_Vector3, normalizedLaye |
| 0 | 129 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), new Vector4(cu |
| 0 | 130 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(0 |
| 0 | 131 | | } |
| | 132 | | else |
| | 133 | | { |
| 0 | 134 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), new Vector4(0, |
| 0 | 135 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(l |
| | 136 | | } |
| | 137 | |
|
| 0 | 138 | | } |
| | 139 | |
|
| | 140 | | private static void ApplyPlanarTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, int |
| | 141 | | { |
| 0 | 142 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + layerNum), TransitioningValues. |
| 0 | 143 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), layer.texture); |
| 0 | 144 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), null); |
| | 145 | |
|
| 0 | 146 | | selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz |
| | 147 | |
|
| | 148 | |
|
| 0 | 149 | | if (layer.movementTypePlanar_Radial == MovementType.Speed) |
| | 150 | | { |
| | 151 | | // speed and Rotation |
| 0 | 152 | | float rot = 0; |
| 0 | 153 | | if (layer.layerType == LayerType.Planar) |
| | 154 | | { |
| 0 | 155 | | rot = TransitioningValues.GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100); |
| | 156 | | } |
| | 157 | |
|
| 0 | 158 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(l |
| | 159 | |
|
| | 160 | | // Tiling and Offset |
| 0 | 161 | | Vector4 t = new Vector4(layer.tiling.x, layer.tiling.y, 0, 0); |
| 0 | 162 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t); |
| 0 | 163 | | } |
| | 164 | | else |
| | 165 | | { |
| | 166 | | // speed and Rotation |
| 0 | 167 | | float rot = 0; |
| 0 | 168 | | if (layer.layerType == LayerType.Planar) |
| | 169 | | { |
| 0 | 170 | | rot = TransitioningValues.GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100); |
| | 171 | | } |
| | 172 | |
|
| 0 | 173 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(0 |
| | 174 | |
|
| | 175 | | // Tiling and Offset |
| 0 | 176 | | Vector2 currentOffset = TransitioningValues.GetTransitionValue(layer.offset, normalizedLayerTime * 100); |
| 0 | 177 | | Vector4 t = new Vector4(layer.tiling.x, layer.tiling.y, currentOffset.x, currentOffset.y); |
| 0 | 178 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t); |
| | 179 | | } |
| | 180 | |
|
| | 181 | |
|
| | 182 | | // Time frame |
| 0 | 183 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.timeSp |
| | 184 | | // Tint |
| 0 | 185 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercentage |
| | 186 | |
|
| | 187 | | // Reset Particle related Params |
| 0 | 188 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), layer.flipbookRowsA |
| 0 | 189 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), new Vector |
| 0 | 190 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), Vecto |
| | 191 | |
|
| | 192 | | // Apply Distortion Values |
| 0 | 193 | | Vector2 distortIntAndSize = new Vector2(TransitioningValues.GetTransitionValue(layer.distortIntensity, norma |
| 0 | 194 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), distortIntAndSiz |
| | 195 | |
|
| 0 | 196 | | Vector2 distortSpeed = TransitioningValues.GetTransitionValue(layer.distortSpeed, normalizedLayerTime * 100) |
| 0 | 197 | | Vector2 distortSharpness = TransitioningValues.GetTransitionValue(layer.distortSharpness, normalizedLayerTim |
| 0 | 198 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), new Vector4(d |
| 0 | 199 | | } |
| | 200 | |
|
| | 201 | | private static void ApplySatelliteTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, i |
| | 202 | | { |
| 0 | 203 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), layer.texture); |
| 0 | 204 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), null); |
| | 205 | |
|
| 0 | 206 | | selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz |
| | 207 | |
|
| 0 | 208 | | if (layer.movementTypeSatellite == MovementType.Speed) |
| | 209 | | { |
| | 210 | | // Tiling and Offset |
| 0 | 211 | | Vector2 currentWidthHeight = TransitioningValues.GetTransitionValue(layer.satelliteWidthHeight, normaliz |
| 0 | 212 | | Vector4 t = new Vector4(currentWidthHeight.x, currentWidthHeight.y, 0, 0); |
| 0 | 213 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t); |
| | 214 | |
|
| | 215 | |
|
| | 216 | | // speed and Rotation |
| 0 | 217 | | float rot = TransitioningValues.GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100); |
| 0 | 218 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(l |
| 0 | 219 | | } |
| | 220 | | else |
| | 221 | | { |
| | 222 | | // Tiling and Offset |
| 0 | 223 | | Vector2 currentOffset = TransitioningValues.GetTransitionValue(layer.offset, normalizedLayerTime * 100); |
| 0 | 224 | | Vector2 currentWidthHeight = TransitioningValues.GetTransitionValue(layer.satelliteWidthHeight, normaliz |
| 0 | 225 | | Vector4 t = new Vector4(currentWidthHeight.x, currentWidthHeight.y, currentOffset.x, currentOffset.y); |
| 0 | 226 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t); |
| | 227 | |
|
| | 228 | | // speed and Rotation |
| 0 | 229 | | float rot = TransitioningValues.GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100); |
| 0 | 230 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(0 |
| | 231 | | } |
| | 232 | |
|
| | 233 | | // Time frame |
| 0 | 234 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.timeSp |
| | 235 | | // Tint |
| 0 | 236 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercentage |
| | 237 | |
|
| | 238 | | // Reset Particle related Params |
| 0 | 239 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), layer.flipbookRowsA |
| 0 | 240 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), new Vector |
| 0 | 241 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), Vecto |
| | 242 | |
|
| | 243 | | // Reset Distortion values |
| 0 | 244 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), Vector2.zero); |
| 0 | 245 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), Vector4.zero) |
| | 246 | |
|
| 0 | 247 | | } |
| | 248 | |
|
| | 249 | | private static void ApplyParticleTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, in |
| | 250 | | { |
| | 251 | | // Reset Unused params |
| 0 | 252 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + layerNum), 0); |
| 0 | 253 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), null); |
| 0 | 254 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), Vector2.zero); |
| 0 | 255 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), Vector4.zero) |
| | 256 | |
|
| | 257 | |
|
| | 258 | | // Time frame |
| 0 | 259 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.timeSp |
| | 260 | | // Tint |
| 0 | 261 | | selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercentage |
| | 262 | |
|
| | 263 | | // Particles |
| 0 | 264 | | selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), layer.texture); |
| 0 | 265 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), layer.flipbookRowsA |
| 0 | 266 | | selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz |
| 0 | 267 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), new Vector4(layer. |
| 0 | 268 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), TransitioningValu |
| 0 | 269 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), new Vector |
| 0 | 270 | | selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), new V |
| | 271 | |
|
| | 272 | |
|
| 0 | 273 | | } |
| | 274 | |
|
| | 275 | | } |
| | 276 | | } |