Advertisement
Guest User

Skybox.shader

a guest
Nov 27th, 2023
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/SkyboxProc"
  2. {
  3.     Properties
  4.     {
  5.          [Header(Stars Settings)]
  6.         _Stars("Stars Texture", 2D) = "black" {}
  7.         _StarsCutoff("Stars Cutoff",  Range(0, 1)) = 0.08
  8.         _StarsSpeed("Stars Move Speed",  Range(0, 1)) = 0.3
  9.         _StarsSkyColor("Stars Sky Color", Color) = (0.0,0.2,0.1,1)
  10.  
  11.  
  12.          [Header(Horizon Settings)]
  13.         _OffsetHorizon("Horizon Offset",  Range(-1, 1)) = 0
  14.         _HorizonIntensity("Horizon Intensity",  Range(0, 10)) = 3.3
  15.         _SunSet("Sunset/Rise Color", Color) = (1,0.8,1,1)
  16.         _HorizonColorDay("Day Horizon Color", Color) = (0,0.8,1,1)
  17.         _HorizonColorNight("Night Horizon Color", Color) = (0,0.8,1,1)
  18.  
  19.          [Header(Sun Settings)]
  20.          _SunColor("Sun Color", Color) = (1,1,1,1)
  21.         _SunRadius("Sun Radius",  Range(0, 2)) = 0.1
  22.  
  23.         [Header(Moon Settings)]
  24.         _MoonColor("Moon Color", Color) = (1,1,1,1)
  25.         _MoonRadius("Moon Radius",  Range(0, 2)) = 0.15
  26.         _MoonOffset("Moon Crescent",  Range(-1, 1)) = -0.1
  27.  
  28.         [Header(Day Sky Settings)]
  29.         _DayTopColor("Day Sky Color Top", Color) = (0.4,1,1,1)
  30.         _DayBottomColor("Day Sky Color Bottom", Color) = (0,0.8,1,1)
  31.  
  32.         [Header(Main Cloud Settings)]
  33.         _BaseNoise("Base Noise", 2D) = "black" {}
  34.         _Distort("Distort", 2D) = "black" {}
  35.         _SecNoise("Secondary Noise", 2D) = "black" {}
  36.         _BaseNoiseScale("Base Noise Scale",  Range(0, 1)) = 0.2
  37.         _DistortScale("Distort Noise Scale",  Range(0, 1)) = 0.06
  38.         _SecNoiseScale("Secondary Noise Scale",  Range(0, 1)) = 0.05
  39.         _Distortion("Extra Distortion",  Range(0, 1)) = 0.1
  40.         _Speed("Movement Speed",  Range(0, 10)) = 1.4
  41.         _CloudCutoff("Cloud Cutoff",  Range(0, 1)) = 0.3
  42.         _Fuzziness("Cloud Fuzziness",  Range(0, 1)) = 0.04
  43.         _FuzzinessUnder("Cloud Fuzziness Under",  Range(0, 1)) = 0.01
  44.         [Toggle(FUZZY)] _FUZZY("Extra Fuzzy clouds", Float) = 1
  45.  
  46.         [Header(Day Clouds Settings)]
  47.         _CloudColorDayEdge("Clouds Edge Day", Color) = (1,1,1,1)
  48.         _CloudColorDayMain("Clouds Main Day", Color) = (0.8,0.9,0.8,1)
  49.         _CloudColorDayUnder("Clouds Under Day", Color) = (0.6,0.7,0.6,1)
  50.         _Brightness("Cloud Brightness",  Range(1, 10)) = 2.5
  51.         [Header(Night Sky Settings)]
  52.         _NightTopColor("Night Sky Color Top", Color) = (0,0,0,1)
  53.         _NightBottomColor("Night Sky Color Bottom", Color) = (0,0,0.2,1)
  54.  
  55.         [Header(Night Clouds Settings)]
  56.         _CloudColorNightEdge("Clouds Edge Night", Color) = (0,1,1,1)
  57.         _CloudColorNightMain("Clouds Main Night", Color) = (0,0.2,0.8,1)
  58.         _CloudColorNightUnder("Clouds Under Night", Color) = (0,0.2,0.6,1)
  59.     }
  60.         SubShader
  61.         {
  62.             Tags { "RenderType" = "Opaque" }
  63.             LOD 100
  64.  
  65.             Pass
  66.             {
  67.                 CGPROGRAM
  68.                 #pragma vertex vert
  69.                 #pragma fragment frag
  70.                 #pragma shader_feature FUZZY
  71.                 #include "UnityCG.cginc"
  72.  
  73.                 struct appdata
  74.                 {
  75.                     float4 vertex : POSITION;
  76.                     float3 uv : TEXCOORD0;
  77.                 };
  78.  
  79.                 struct v2f
  80.                 {
  81.                     float3 uv : TEXCOORD0;
  82.                     float4 vertex : SV_POSITION;
  83.                     float3 worldPos : TEXCOORD1;
  84.                 };
  85.  
  86.                 sampler2D _Stars, _BaseNoise, _Distort, _SecNoise;
  87.  
  88.                 float _SunRadius, _MoonRadius, _MoonOffset, _OffsetHorizon;
  89.                 float4 _SunColor, _MoonColor;
  90.                 float4 _DayTopColor, _DayBottomColor, _NightBottomColor, _NightTopColor;
  91.                 float4 _HorizonColorDay, _HorizonColorNight, _SunSet;
  92.                 float _StarsCutoff, _StarsSpeed, _HorizonIntensity;
  93.                 float _BaseNoiseScale, _DistortScale, _SecNoiseScale, _Distortion;
  94.                 float _Speed, _CloudCutoff, _Fuzziness, _FuzzinessUnder, _Brightness;
  95.                 float4 _CloudColorDayEdge, _CloudColorDayMain, _CloudColorDayUnder;
  96.                 float4 _CloudColorNightEdge, _CloudColorNightMain, _CloudColorNightUnder, _StarsSkyColor;
  97.  
  98.                 v2f vert(appdata v)
  99.                 {
  100.                     v2f o;
  101.                     o.vertex = UnityObjectToClipPos(v.vertex);
  102.                     o.uv = v.uv;
  103.                     o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  104.                     return o;
  105.                 }
  106.  
  107.                 fixed4 frag(v2f i) : SV_Target
  108.                 {
  109.  
  110.                     float horizon = abs((i.uv.y * _HorizonIntensity) - _OffsetHorizon);
  111.  
  112.                 // uv for the sky
  113.                 float2 skyUV = i.worldPos.xz / i.worldPos.y;
  114.  
  115.                 // moving clouds
  116.                 float baseNoise = tex2D(_BaseNoise, (skyUV - _Time.x) * _BaseNoiseScale).x;
  117.  
  118.                 float noise1 = tex2D(_Distort, ((skyUV + baseNoise) - (_Time.x * _Speed)) * _DistortScale);
  119.  
  120.                 float noise2 = tex2D(_SecNoise, ((skyUV + (noise1 * _Distortion)) - (_Time.x * (_Speed * 0.5))) * _SecNoiseScale);
  121.  
  122.                 float finalNoise = saturate(noise1 * noise2) * 3 * saturate(i.worldPos.y);
  123.  
  124.  
  125. #if FUZZY
  126.                 float clouds = saturate(smoothstep(_CloudCutoff * baseNoise, _CloudCutoff * baseNoise + _Fuzziness, finalNoise));
  127.                 float cloudsunder = saturate(smoothstep(_CloudCutoff* baseNoise, _CloudCutoff * baseNoise + _FuzzinessUnder + _Fuzziness, noise2) * clouds);
  128.  
  129. #else
  130.                 float clouds = saturate(smoothstep(_CloudCutoff, _CloudCutoff + _Fuzziness, finalNoise));
  131.                 float cloudsunder = saturate(smoothstep(_CloudCutoff, _CloudCutoff + _Fuzziness + _FuzzinessUnder , noise2) * clouds);
  132.  
  133.  
  134. #endif
  135.                 float3 cloudsColored = lerp(_CloudColorDayEdge, lerp(_CloudColorDayUnder, _CloudColorDayMain, cloudsunder), clouds) * clouds;
  136.                 float3 cloudsColoredNight = lerp(_CloudColorNightEdge, lerp(_CloudColorNightUnder,_CloudColorNightMain , cloudsunder), clouds) * clouds;
  137.                 cloudsColoredNight *= horizon;
  138.  
  139.  
  140.                 cloudsColored = lerp(cloudsColoredNight, cloudsColored, saturate(_WorldSpaceLightPos0.y)); // lerp the night and day clouds over the light direction
  141.                 cloudsColored += (_Brightness * cloudsColored * horizon); // add some extra brightness
  142.  
  143.  
  144.                 float cloudsNegative = (1 - clouds) * horizon;
  145.                 // sun
  146.                 float sun = distance(i.uv.xyz, _WorldSpaceLightPos0);
  147.                 float sunDisc = 1 - (sun / _SunRadius);
  148.                 sunDisc = saturate(sunDisc * 50);
  149.  
  150.                 // (crescent) moon
  151.                 float moon = distance(i.uv.xyz, -_WorldSpaceLightPos0);
  152.                 float crescentMoon = distance(float3(i.uv.x + _MoonOffset, i.uv.yz), -_WorldSpaceLightPos0);
  153.                 float crescentMoonDisc = 1 - (crescentMoon / _MoonRadius);
  154.                 crescentMoonDisc = saturate(crescentMoonDisc * 50);
  155.                 float moonDisc = 1 - (moon / _MoonRadius);
  156.                 moonDisc = saturate(moonDisc * 50);
  157.                 moonDisc = saturate(moonDisc - crescentMoonDisc);
  158.  
  159.                 float3 sunAndMoon = (sunDisc * _SunColor) + (moonDisc * _MoonColor);
  160.                 sunAndMoon *= cloudsNegative;
  161.  
  162.                 //stars
  163.                 float3 stars = tex2D(_Stars, skyUV + (_StarsSpeed * _Time.x));
  164.                 stars *= saturate(-_WorldSpaceLightPos0.y);
  165.                 stars = step(_StarsCutoff, stars);
  166.                 stars += (baseNoise * _StarsSkyColor);
  167.                 stars *= cloudsNegative;
  168.  
  169.                 // gradient day sky
  170.                 float3 gradientDay = lerp(_DayBottomColor, _DayTopColor, saturate(horizon));
  171.  
  172.                 // gradient night sky
  173.                 float3 gradientNight = lerp(_NightBottomColor, _NightTopColor, saturate(horizon));
  174.  
  175.                 float3 skyGradients = lerp(gradientNight, gradientDay, saturate(_WorldSpaceLightPos0.y)) * cloudsNegative;
  176.  
  177.                 // horizon glow / sunset/rise
  178.                 float sunset = saturate((1 - horizon) * saturate(_WorldSpaceLightPos0.y * 5));
  179.  
  180.  
  181.                 float3 sunsetColoured = sunset * _SunSet;
  182.  
  183.                 float3 horizonGlow = saturate((1 - horizon * 5) * saturate(_WorldSpaceLightPos0.y * 10)) * _HorizonColorDay;//
  184.                 float3 horizonGlowNight = saturate((1 - horizon * 5) * saturate(-_WorldSpaceLightPos0.y * 10)) * _HorizonColorNight;//
  185.                 horizonGlow += horizonGlowNight;
  186.  
  187.            
  188.  
  189.                float3 combined = skyGradients + sunAndMoon + sunsetColoured + stars + cloudsColored + horizonGlow;
  190.              
  191.                return float4(combined,1);
  192.  
  193.            }
  194.            ENDCG
  195.        }
  196.         }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement