4

I have four different skyboxes, one for each season in my game.

How can I create a fade transition between the skyboxes in c#?

So for example, at a certain point, the summer skybox fades into the autumn skybox.

Thank you!

Night.owl
  • 121
  • 1
  • 2
  • 13

1 Answers1

0

You'll want to do the blending in a shader, there's one on the Unify wiki that can blend between two skyboxes.

You need to swap the textures in your material using a script (using material.SetTexture) when it's finished blending between 2 of them to get the effect of blending between 4.

Rtyper
  • 44
  • 5
  • I've set up the shader and material and the skybox blends using the slider. How can i write it in my code (c#) so that it gradually animates from blend = 0.0 to blend = 1? I understand you can use skyboxmaterial.SetFloat("_Blend", blendNumber ); But I need the blend Number to be gradually incremented over a set time. – Night.owl Apr 03 '16 at 17:08
  • 1
    You can use Mathf.Lerp(start, end, time) to get a value between two others, where time is between 0 and 1. The easy (but technically wrong) way to use it is something like this: `material.SetFloat("_Blend" , Mathf.Lerp(material.GetFloat("_Blend"),1,Time.deltaTime));` but that gives you fast blending at the start, and slows down to a stop just before reaching 1. The best way to do it is laid out well in this article:https://chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/ – Rtyper Apr 03 '16 at 19:00
  • 1
    Then again, if the _Blend parameter's range is 0 to 1, you probably don't need Lerp anyway, you can just increment a timer variable yourself using Time.deltaTime and use that. – Rtyper Apr 03 '16 at 19:03
  • How do I add the Sky boxes to the blending shader, they are materials and i'm not quite sure how to go about this. – Jajan Jun 01 '17 at 06:59