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