How to add night sky using Unity 5 procedural skybox?

I’m using Unity 5 and it’s new procedural skybox. It looks amazing!

In my game, I have a day/night cycle. I can’t find a way to use a night skybox which will slowly appear (blend) to replace the procedural skybox when the night comes.

I know a shader exists to blend between two skyboxes, but it won’t work with the new procedural skybox.

I want to be able to keep the procedural skybox, so I can keep my amaizing sunrise/sunset, but be able to add stars at night.

Is there a way to replace the “Black” color at night with a standard skybox? An image?
Should I add a huge sphere to my game to act like a skybox and make it transparent on day time?

I really have no idea how to achieve that. There must be a way to change the night sky…

If you just want to add stars then particles could work very nicely. Make a particle emitter emit in a circle from the edge, make the circle really big, and make the particles spawn a lot more often and live longer. You can attach the particles to the directional light and they rotate with your sun!

Yes, I tought about that, but it wont appear if the particles are further than the camera clip distance. If I make it follow the position of the player, the particles will sometimes appear over walls or mountains far away.

My goal is to add more complex sky, like the old skyboxes, at night.

You could have another camera be only looking at the stars and put that camera on a different layer than the players. When you set it up the stars can be rendered in front of the skybox, but behind the everything else.

1 Like

I tought that was impossible!!

How can I do this, rendering
1: procedural skybox
2: Fake skybox (stars), moon, far space objects
3: The world (terrain, etc.)
4: arms

I already have a camera for the player arms, which is drawn on top of the rest.

Do I need 4 cameras now? I have a feeling that i’m gonna have fps issues… haha

Or is there another magic way of doing this?

Thank you

Actually 3 cameras, number 1 and 2 can be rendered in the same camera I guess

It seems to work!

But I’m now facing a new problem…

to simulate a skybox, I made a cube in blender, inverted the normals so I can see it from inside.
I created a Cubemap and applyed it to my cube with the Skybox>Cubemap shader.

I can’t find a way to play with this object’s transparency, to make it fully transparent at day time.

Thanks for your help.

Shader “Unlit/UnlitAlphaWithFade”
{
Properties
{
_Color(“Color Tint”, Color) = (1,1,1,1)
_MainTex(“Base (RGB) Alpha (A)”, 2D) = “white”
}
Category
{
Lighting Off
ZWrite Off
//ZWrite On // uncomment if you have problems like the sprite disappear in some rotations.
Cull back
Blend SrcAlpha OneMinusSrcAlpha
//AlphaTest Greater 0.001 // uncomment if you have problems like the sprites or 3d text have white quads instead of alpha pixels.
Tags {Queue = Transparent}
SubShader
{
Pass
{
SetTexture[_MainTex]
{
ConstantColor[_Color]
Combine Texture * constant
}
}
}
}
}

This shader will give you an unlit material with an adjustable alpha

Thanks for sharing! :slight_smile: Using code tags would make it easier to understand though:

Shader "Unlit/UnlitAlphaWithFade"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}

Now, how do you use it? There is no accessible material for the procedural skybox; it seems to apply automatically if I drop it in the project but how do you control it?