// The ending's Earth's air: a shell a little bigger than the ball, drawn from the inside, glowing just past the ball's edge // and fading out into space. Dusty brown while the ball is dead, blue once it lives. Shader "GrassCutter/EarthAir" { Properties { _SunDir ("Sun (world)", Vector) = (0, 0, 1, 0) _AirColor ("Air", Color) = (0.8, 0.55, 0.3, 1) _Edge ("Edge (cos at the ball's rim)", Float) = 0.33 _Power ("Power", Float) = 1 } SubShader { Tags { "RenderType" = "Transparent" "Queue" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" } Pass { Name "Air" Tags { "LightMode" = "UniversalForward" } Blend One One ZWrite Off Cull Front HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" CBUFFER_START(UnityPerMaterial) float4 _SunDir; float4 _AirColor; float _Edge; float _Power; CBUFFER_END struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; }; struct Varyings { float4 positionCS : SV_POSITION; float3 normalWS : TEXCOORD0; float3 positionWS : TEXCOORD1; }; Varyings vert(Attributes v) { Varyings o; o.positionWS = TransformObjectToWorld(v.positionOS.xyz); o.positionCS = TransformWorldToHClip(o.positionWS); o.normalWS = TransformObjectToWorldNormal(v.normalOS); return o; } float4 frag(Varyings i) : SV_Target { float3 n = normalize(i.normalWS); float3 view = normalize(GetCameraPositionWS() - i.positionWS); // the far side of the shell: 0 at its own rim, _Edge where it meets the ball's rim float k = saturate(-dot(n, view) / _Edge); float glow = pow(k, 1.6) * (1 - smoothstep(0.92, 1.0, k) * 0.4); float lit = saturate(dot(n, normalize(_SunDir.xyz)) * 0.8 + 0.35); return float4(_AirColor.rgb * glow * lit * _Power, 1); } ENDHLSL } } }