167 lines
6.1 KiB
GLSL
167 lines
6.1 KiB
GLSL
Shader "GAME/StylizedSky"
|
|
{
|
|
Properties
|
|
{
|
|
[Header(Sky Gradient Day)][Space]
|
|
[HDR] _DayZenith("Day Zenith", Color) = (0.18,0.42,0.78,1)
|
|
[HDR] _DayHorizon("Day Horizon", Color) = (0.62,0.78,0.92,1)
|
|
|
|
[Header(Sky Gradient Night)][Space]
|
|
[HDR] _NightZenith("Night Zenith", Color) = (0.01,0.02,0.06,1)
|
|
[HDR] _NightHorizon("Night Horizon", Color) = (0.04,0.06,0.12,1)
|
|
|
|
[Header(Twilight)][Space]
|
|
[HDR] _TwilightColor("Twilight Tint (dawn/dusk)", Color) = (0.95,0.45,0.25,1)
|
|
_HorizonSharpness("Horizon Sharpness", Range(0.2,6)) = 2.2
|
|
|
|
[Header(Sun)][Space]
|
|
[HDR] _SunColor("Sun Color", Color) = (1.0,0.95,0.85,1)
|
|
_SunSize("Sun Size", Range(0.0005,0.2)) = 0.03
|
|
[HDR] _SunGlowColor("Sun Glow Color", Color) = (1.0,0.7,0.4,1)
|
|
_SunGlowSize("Sun Glow Falloff", Range(1,512)) = 64
|
|
_SunGlowStrength("Sun Glow Strength", Range(0,4)) = 1.0
|
|
|
|
[Header(Clouds)][Space]
|
|
[HDR] _CloudColor("Cloud Color (lit)", Color) = (1.0,0.98,0.95,1)
|
|
[HDR] _CloudShadowColor("Cloud Color (shadow)", Color) = (0.55,0.6,0.72,1)
|
|
_CloudCoverage("Cloud Coverage", Range(0,1)) = 0.5
|
|
_CloudSoftness("Cloud Edge Softness", Range(0.01,0.6)) = 0.2
|
|
_CloudScale("Cloud Scale", Range(0.2,4)) = 1.2
|
|
_CloudSpeed("Cloud Speed", Range(0,0.2)) = 0.01
|
|
_CloudWindDir("Cloud Wind Dir (xy)", Vector) = (1,0.3,0,0)
|
|
|
|
[Header(Stars)][Space]
|
|
_StarDensity("Star Density", Range(0,0.2)) = 0.04
|
|
_StarTwinkleSpeed("Star Twinkle Speed", Range(0,8)) = 2.0
|
|
|
|
[Header(Shooting Stars)][Space]
|
|
[HDR] _ShootingStarColor("Shooting Star Color", Color) = (1,1,0.9,1)
|
|
_ShootingStarRate("Shooting Star Rate", Range(0.01,0.5)) = 0.06
|
|
|
|
[Header(Exposure)][Space]
|
|
_Exposure("Exposure", Range(0,4)) = 1.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Background"
|
|
"Queue" = "Background"
|
|
"PreviewType" = "Skybox"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
}
|
|
|
|
// =================================================================================
|
|
// Skybox (rendu par RenderSettings.skybox via le pass DrawSkybox d'URP)
|
|
// =================================================================================
|
|
Pass
|
|
{
|
|
Name "StylizedSky"
|
|
Cull Off
|
|
ZWrite Off
|
|
ZTest LEqual
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex SkyVertex
|
|
#pragma fragment SkyFragment
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "SkyCore.hlsl"
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _DayZenith;
|
|
half4 _DayHorizon;
|
|
half4 _NightZenith;
|
|
half4 _NightHorizon;
|
|
half4 _TwilightColor;
|
|
float _HorizonSharpness;
|
|
|
|
half4 _SunColor;
|
|
float _SunSize;
|
|
half4 _SunGlowColor;
|
|
float _SunGlowSize;
|
|
float _SunGlowStrength;
|
|
|
|
half4 _CloudColor;
|
|
half4 _CloudShadowColor;
|
|
float _CloudCoverage;
|
|
float _CloudSoftness;
|
|
float _CloudScale;
|
|
float _CloudSpeed;
|
|
float4 _CloudWindDir;
|
|
|
|
float _StarDensity;
|
|
float _StarTwinkleSpeed;
|
|
|
|
half4 _ShootingStarColor;
|
|
float _ShootingStarRate;
|
|
|
|
float _Exposure;
|
|
CBUFFER_END
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float3 viewDirOS : TEXCOORD0;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
// La skybox est dessinée autour de la caméra : la position objet du mesh est
|
|
// directement la direction de vue. On la transmet brute et on la normalise au fragment.
|
|
Varyings SkyVertex(Attributes IN)
|
|
{
|
|
Varyings OUT = (Varyings)0;
|
|
UNITY_SETUP_INSTANCE_ID(IN);
|
|
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
|
|
|
OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
|
|
OUT.viewDirOS = IN.positionOS.xyz;
|
|
return OUT;
|
|
}
|
|
|
|
// Compose le ciel dans l'ordre fond -> nuages -> soleil -> étoiles -> filantes.
|
|
// Toute l'animation lit _SkyTime (synchronisé) et tout dépend de _SunDirection /
|
|
// _TimeOfDay (synchronisés), donc le rendu est identique sur tous les clients.
|
|
half4 SkyFragment(Varyings IN) : SV_Target
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
|
|
|
|
float3 viewDir = normalize(IN.viewDirOS);
|
|
|
|
float3 col = SkyGradient(viewDir,
|
|
_DayZenith.rgb, _DayHorizon.rgb,
|
|
_NightZenith.rgb, _NightHorizon.rgb,
|
|
_TwilightColor.rgb, _HorizonSharpness);
|
|
|
|
col += SunGlow(viewDir, _SunGlowColor.rgb, _SunGlowSize, _SunGlowStrength);
|
|
|
|
float4 clouds = Clouds(viewDir, _SkyTime * _CloudSpeed,
|
|
_CloudColor.rgb, _CloudShadowColor.rgb,
|
|
_CloudCoverage, _CloudSoftness, _CloudScale, _CloudWindDir.xy);
|
|
col = col * (1.0 - clouds.a) + clouds.rgb;
|
|
|
|
col += SunDisk(viewDir, _SunColor.rgb, _SunSize) * (1.0 - clouds.a);
|
|
|
|
col += Stars(viewDir, _StarDensity, _StarTwinkleSpeed, _SkyTime) * (1.0 - clouds.a);
|
|
col += ShootingStars(viewDir, _SkyTime, _ShootingStarColor.rgb, _ShootingStarRate) * (1.0 - clouds.a);
|
|
|
|
col *= _Exposure;
|
|
return half4(col, 1.0);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
Fallback Off
|
|
}
|