Hello peoples,
I would need some help on my current project. I’m trying to blend three different skyboxes (One for day, one for dusk / dawn, one for night) and make them transitioning smoothly according to the system time. But can’t manage to get through this. I’ve spent two fulls days on that. So if any of you could help me please !
Here’s what i have :
SkyboxCycle.cs
Here i’ll manage the cycles according to real time. The script is obviously not finished.
using System;
using UnityEngine;
public class SkyboxCycle : MonoBehaviour
{
public Material skybox;
public float ActualTime;
public enum Dayphase
{
Dawn,
Day,
Dusk,
Night
}
private void Update()
{
ActualTime = DateTime.Now.Hour;
skybox.SetFloat("_Blend", Mathf.Lerp(skybox.GetFloat("_Blend"), ActualTime * 0.1f, Time.deltaTime));
}
}
SjyboxBlend.Shader
Here’s my Shader managing the blending of the severals skyboxes.
Shader "RenderFX/Skybox Blended" {
Properties {
_Tint ("Tint Color", Color) = (1, 1, 1, 1)
_Tint1 ("Tint Color one", Color) = (1, 1, 1, 1)
_Tint2 ("Tint Color two", Color) = (1, 1, 1, 1)
_Blend ("Blend", Range(0,1)) = 0.5
_Skybox1 ("Skybox one", Cube) = ""
_Skybox2 ("Skybox two", Cube) = ""
_Skybox3 ("Skybox three", Cube) = ""
}
SubShader {
Tags { "Queue" = "Background" }
Cull Off
Fog { Mode Off }
Lighting On
Color [_Tint]
Pass {
SetTexture [_Skybox1] { combine texture }
SetTexture [_Skybox2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_Skybox2] { combine previous +- primary, previous * primary }
SetTexture [_Skybox2] { combine texture }
SetTexture [_Skybox3] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_Skybox3] { combine previous +- primary, previous * primary }
}
}
Fallback "RenderFX/Skybox", 1
}
What is the problem ?
My Skyboxes are blending. But they are blending way too fast to each others. And i don’t get how to increase the Blend slider. I increased the value of the slider from 0 to 24, that’s not difficult, just needed to change the “Range” property, but it doesn’t increase the blending gap (the skyboxes will still be blending between 0 and 1, and after 1 the skybox is becoming darker and weirder until the max 24).
Also, how will i make the slider increase related to time ?
Thanks everyone.