Search Unity

How to blend two independent Skyboxes

Discussion in 'Scripting' started by betaFlux, Feb 24, 2020.

  1. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    Hi, I'm trying to implement my own simple day night cycle. Light and ambience blending works fine. Blending two skyboxes via shader is also easy (thanks to the shader scripters), but I try to have the night sky rotate on x or z, while the day sky should be static, since there is a horizon in the image.

    I have tried adding two cameras with skybox components attached for day and night respectively, but I can't seem to find a way to blend between those two, since you can't just fade out a skybox. If this would be possible I could just do:
    Code (CSharp):
    1. daySkybox.material.SetFloat("_Blend", 1-skyboxBlendCurve.Evaluate(currentTime));
    2. nightSkybox.material.SetFloat("_Blend", skyboxBlendCurve.Evaluate(currentTime));
    Is there a better way to blend two independent skyboxes, while allowing one of them to be rotated?
     
    jemlilli likes this.
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    If you already have access to a shader that blends two skyboxes, I think it would be easiest to add rotation (properties & code) of the night sky texture to the shader itself. That being said, I found unity skybox shaders to be woefully underdocumented, so you are looking at some definite hair-loss o_O

    Note that while you can't fade a skybox itself, you could (although I find that to be a too-roundabout way) apply the second skybox to a dome in the scene, set it's index in the render queue directly after the skybox and blend it with the previous skybox.
     
    betaFlux likes this.
  3. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    @csofranz, thank you for the suggestions!

    I actually searched for a rotatable skybox blend shader for hours and found this one, but I have to admit that this is beyond my skills, since there are 6 textures for each skybox and I have no clue what to change to make only one of them rotate.

    So, I'm going to try out your second suggestion for now.
     
  4. UmeshKonduru

    UmeshKonduru

    Joined:
    Apr 22, 2020
    Posts:
    1
    Hey, if you could post a link to the normal skybox shader, that would be really helpful. Thank you!