Gradient Skybox Shader for Unity URP
A URP stylized skybox shader for Unity 6: a three-colour gradient sky with a sun disc and glow that follow your main directional light. No textures needed.
Also called: stylized skybox, sky gradient shader, procedural sky, sunset skybox.
Environment URP, Unity 6000.0+ beginner MIT licensed
Use it for: Stylized and low-poly scenes that need a clean sky with no texture, from midday blue to sunset.
The preview is a WebGL copy of the shader's maths with one fixed light, so it shows no shadows, Bloom or textures.
What it does
- Top, horizon and bottom colours with separate falloffs
- Sun disc and glow that track the main directional light
- HDR sun colour for Bloom
- No textures, so it costs almost nothing
How it works
The skybox mesh is centred on the camera, so each vertex position is also a view direction. Its height picks the blend between the horizon colour and the top or bottom colour. The angle between the view direction and the main light direction draws the sun disc, and a power of that dot product adds the glow around it.
Setup
- Save the file as SkyboxGradient.shader under Assets and create a material that uses Scripts For Unity > Skybox Gradient.
- Open Window > Rendering > Lighting > Environment and assign the material to Skybox Material.
- Rotate your Directional Light to move the sun.
- Press Generate Lighting if you want the ambient light to match the new sky.
Common mistakes
- The sun does not move with the light: the sun follows the main directional light URP picks, which is the Sun Source in the Lighting window or the brightest directional light. Set Sun Source to the light you rotate.
- The scene's lighting still matches the old sky: ambient light is baked from the skybox. Generate lighting again after changing colours.
Questions
- How do I use it as the sky?
- Create a material with the shader, then assign it to Skybox Material in Window > Rendering > Lighting > Environment.
- Why doesn't the sun move with my light?
- The sun follows URP's main directional light: the Sun Source in the Lighting window, or the brightest directional light. Set Sun Source to the light you rotate.
- Does it work in HDRP?
- No. It is written for the Universal Render Pipeline.
Source
SkyboxGradient.shader · 97 lines · ShaderLab and HLSL for the Universal Render Pipeline 17 (Unity 6)
// Gradient Skybox: a three-colour stylized sky with a sun disc and glow
// that follow the scene's main directional light. URP 17 (Unity 6).
// Assign it in Window > Rendering > Lighting > Environment > Skybox Material.
// Scripts For Unity, MIT licensed.
Shader "Scripts For Unity/Skybox Gradient"
{
Properties
{
_TopColor ("Top Color", Color) = (0.18, 0.42, 0.85, 1)
_HorizonColor ("Horizon Color", Color) = (0.95, 0.72, 0.55, 1)
_BottomColor ("Bottom Color", Color) = (0.2, 0.18, 0.24, 1)
_TopExponent ("Top Falloff", Range(0.1, 8)) = 0.8
_BottomExponent ("Bottom Falloff", Range(0.1, 8)) = 0.6
[HDR] _SunColor ("Sun Color", Color) = (2.2, 1.8, 1.3, 1)
_SunSize ("Sun Size", Range(0.001, 0.3)) = 0.05
_SunGlow ("Sun Glow", Range(0, 2)) = 0.35
_SunGlowFalloff ("Sun Glow Falloff", Range(1, 64)) = 24
}
SubShader
{
Tags
{
"Queue" = "Background"
"RenderType" = "Background"
"PreviewType" = "Skybox"
"RenderPipeline" = "UniversalPipeline"
}
Cull Off
ZWrite Off
Pass
{
Name "Sky"
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
half4 _TopColor;
half4 _HorizonColor;
half4 _BottomColor;
float _TopExponent;
float _BottomExponent;
half4 _SunColor;
float _SunSize;
float _SunGlow;
float _SunGlowFalloff;
CBUFFER_END
struct Attributes
{
float4 positionOS : POSITION;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 directionWS : TEXCOORD0;
};
Varyings vert(Attributes input)
{
Varyings output;
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
// On the skybox mesh, object space position is the view direction
output.directionWS = input.positionOS.xyz;
return output;
}
half4 frag(Varyings input) : SV_Target
{
float3 direction = normalize(input.directionWS);
float top = pow(saturate(direction.y), _TopExponent);
float bottom = pow(saturate(-direction.y), _BottomExponent);
float3 color = lerp(_HorizonColor.rgb, _TopColor.rgb, top);
color = lerp(color, _BottomColor.rgb, bottom);
// _MainLightPosition.xyz points towards the main directional light
float sunDot = dot(direction, _MainLightPosition.xyz);
float sunAngle = acos(clamp(sunDot, -1.0, 1.0));
float disc = 1.0 - smoothstep(_SunSize * 0.85, _SunSize, sunAngle);
float glow = pow(saturate(sunDot), _SunGlowFalloff) * _SunGlow;
color += _SunColor.rgb * (disc + glow);
return half4(color, 1.0);
}
ENDHLSL
}
}
FallBack Off
}
More shaders
- Stylized Water ShaderA URP stylized water shader for Unity 6: rolling vertex waves, a deep-to-horizon colour ramp, crest foam, a sun glint and optional shore foam from the depth texture.
- Wind Foliage ShaderA URP grass and leaves shader for Unity 6: alpha-cut foliage that sways in gusts of wind, with a root-to-tip colour gradient. Shadows and depth sway with it.
- Toon Lit Shader with OutlineA URP toon shader for Unity 6: two-band cel shading that receives shadows, a hard specular highlight, a rim light and an inverted-hull outline, in one .shader file.
- Dissolve ShaderA URP dissolve shader for Unity 6 that burns a mesh away along procedural noise with a glowing HDR edge. No noise texture needed, and its shadow dissolves with it.