Last active
August 5, 2024 03:00
-
-
Save philip-peterson/7048408712c4b94d3f45cc2d2b6d255e to your computer and use it in GitHub Desktop.
Sky Shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sky shader made for Starry Expanse Prison Island Demo in 2013. | |
// Designed by Everett Gunther | |
// Implemented by Philip Peterson | |
Shader "Custom/Sky Shader" { | |
Properties { | |
_DSC1("DS Color 1", Color) = (1, 1, 1, 1) | |
_DSC2("DS Color 2", Color) = (1, 1, 1, 1) | |
_DSP1("DS Position 1", Float) = .35 | |
_DSP2("DS Position 2", Float) = .85 | |
_SunColor("Sun Color", Color) = (1, 1, 1, 1) | |
_SunGlowColor("Sun Glow Color", Color) = (1, 1, 1, 1) | |
_HorizonGlowColor("Horizon Glow Color", Color) = (1, 1, 1, 1) | |
_CenterDarkenColor("Center Darkening Color", Color) = (1, 1, 1, 1) | |
_SunPosition("Sun Position", Vector) = (0,.5,0,0) | |
_MoonPosition("Moon Position", Vector) = (0,.5,0,0) | |
_StarIntensity("Star Intensity", range(0,1.0)) = 1.0 | |
_MoonAngle("Moon Angle", Float) = -19 | |
_BoltNumber("Bolt Number (0-7)", Float) = 0 | |
_LightningBrightness("Lightning Brightness", range(0,1)) = 0 | |
_LightningGlowAdjustment("GlowAdjustment", Float) = 0 | |
_LightningGlowPhase("Lightning Glow Phase", Range(0,1)) = 0.0 | |
_LightningAngle("Lightning Angle", Float) = 0 | |
_Cloudiness("Cloudiness", Range(0,1)) = 0.0 | |
_SunLightingIntensity("Sun Lighting Intensity", Range(0,1)) = 1.0 | |
// _TwinkleSpeed("Twinkle speed", Float) = 1.0 | |
// _TwinklePower("Twinkle power", Float) = 1.0 | |
_CloudAngle("Cloud Angle (Degrees)", Float) = 30 | |
_CircularGradients("Circular Gradients", 2D) = "black" {} | |
_MoonDiff("Moon Diffuse", 2D) = "white" {} | |
_MoonAlpha("Moon Alpha", 2D) = "white" {} | |
_LightningBolts("LightningBolts", 2D) = "black" {} | |
_LightningGlow("Lightning Glow", 2D) = "blue" {} | |
_Stars("Stars (RGB) with twinkle mask (A)", 2D) = "black" {} | |
_DisplaceTexture("Cloud displacement map", 2D) = "bump" {} | |
_CloudGradient("Cloud Gradient", 2D) = "black" {} | |
_ClearFadeGradient("Clear/Fade Gradient", 2D) = "black" {} | |
_OvercastZenithGradient("Overcast/Zenith Gradient", 2D) = "black" {} | |
_BaseClouds1("Base Clouds 1", 2D) = "black" {} | |
_BaseClouds2("Base Clouds 2", 2D) = "black" {} | |
_BaseFrame("Frame Number", Float) = 0 | |
} | |
SubShader { | |
Tags { | |
"RenderType"="Opaque" | |
} | |
Lighting Off | |
Pass { | |
CGPROGRAM | |
#pragma fragment frag | |
#pragma vertex vert | |
#include "UnityCG.cginc" | |
#pragma target 3.0 | |
#define BLENDERIFY(x) ((x-float4(.5,.5,0,0))*float4(2,2,1,1)) | |
#define DEBLENDERIFY(x) (x*float4(.5,.5,1,1)+float4(.5,.5,0,0)) | |
/* | |
* Blender (well, Blender 2.49, but this behavior is carried on just by virtue | |
* of a file's being created in Blender 2.49, even if you're running some newer version | |
* of Blender now) has an unusual way of storing/using UV coords. | |
* It goes something like: -1 represents 0% across the UV map, 0 represents 50%, and 1 represents 100%. | |
* When converted to colors, the numbers are dealt with in the way one would usually convert | |
* two-dimensional vectors to colors; coerce R and G to scalars in the range [0,1] and set B to 0. | |
* This means a large portion of a plane (with a projected UVmap) will be black, and a large will be yellow. | |
* | |
* So, when you use coordinates like blender would, most of the time you're doing this | |
* | |
* x = <some UV coordinate source given in Unity's system> | |
* x = BLENDERIFY(x) | |
* x *= this | |
* x -= that | |
* x = some_func(x) | |
* <you can use x as a color here> | |
* x = DEBLENDERIFY(x) | |
* <now use x as UV coordinates> | |
* | |
* Sometimes (usually?) you can leave out the BLENDERIFY and DEBLENDERIFY if all you do | |
* is really basic transformations on x and you don't use x as a color. | |
* | |
* I think a name for this kind of allowed transformation would be a first-order homogeneous | |
* function -- but I'm not sure. | |
* | |
*/ | |
// Some convenience/readability macros | |
#define LUMINANCE float4(.2125, .7154, .072, 1) | |
#define LUM_OF(x) dot(x, LUMINANCE) | |
#define BLACK float4(0,0,0,1) | |
#define WHITE float4(1,1,1,1) | |
#define ONETHIRD .333333333333333333 | |
#define AVG3(q) ((q.x+q.y+q.z)/3) | |
#define AVG4(q) ((q.x+q.y+q.z+q.w)/4) | |
#define HEX(c) ( float4( \ | |
float(c/pow(256, 2))/255, \ | |
float((c - c/pow(256, 2)*256*256)/256)/255, \ | |
float(c - c/256*256)/255, \ | |
1.0) ) | |
// HEX macro: give it a 0x###### and it will turn it into float4(0x##, 0x##, 0x##, 1) | |
#define MOON_SCALE 6 | |
#define SUN_SCALE 3.0 | |
sampler2D _CircularGradients; | |
sampler2D _MoonDiff; | |
sampler2D _MoonAlpha; | |
sampler2D _Stars; | |
sampler2D _DisplaceTexture; | |
sampler2D _LightningBolts; | |
sampler2D _LightningGlow; | |
float _LightningGlowAdjustment; | |
sampler2D _CloudGradient; | |
sampler2D _ClearFadeGradient; | |
sampler2D _OvercastZenithGradient; | |
sampler2D _BaseClouds1; | |
sampler2D _BaseClouds2; | |
float _BaseFrame; | |
float4 _DSC1; | |
float4 _DSC2; | |
float _DSP1; | |
float _DSP2; | |
float4 _SunColor; | |
float4 _SunGlowColor; | |
float4 _HorizonGlowColor; | |
float4 _CenterDarkenColor; | |
float4 _SunPosition; | |
float4 _MoonPosition; | |
float _StarIntensity; | |
float _MoonAngle; | |
float _BoltNumber; | |
float _Cloudiness; | |
float _SunLightingIntensity; | |
float _LightningGlowPhase; | |
float _LightningAngle; | |
// float _TwinkleSpeed; | |
// float _TwinklePower; | |
float _CloudAngle; | |
float _LightningBrightness; | |
float _StarScale; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
v2f vert (appdata_base v) | |
{ | |
v2f o; | |
o.pos = mul (UNITY_MATRIX_MVP, v.vertex); | |
o.uv = v.texcoord; | |
return o; | |
} | |
inline float4 generic_ramp_two_color(float apos, float bpos, float4 acol, float4 bcol, float input) { | |
return lerp(acol, bcol, saturate((input-apos)/(bpos-apos))); | |
} | |
inline float4 generic_animated_ramp_two_color( float aposi, | |
float bposi, | |
float aposf, | |
float bposf, | |
float4 acoli, | |
float4 bcoli, | |
float4 acolf, | |
float4 bcolf, | |
float input, | |
float time) { | |
return generic_ramp_two_color( | |
lerp(aposi, aposf, time), | |
lerp(bposi, bposf, time), | |
lerp(acoli, acolf, time), | |
lerp(bcoli, bcolf, time), | |
input | |
); | |
} | |
inline float4 generic_ramp_three_color (in float pos1, | |
in float pos2, | |
in float pos3, | |
in float4 col1, | |
in float4 col2, | |
in float4 col3, | |
in float input) { | |
// generic 3-color ramp | |
// TODO: branchless | |
if(input < pos1) { | |
return col1; | |
} | |
if (input < pos2) { | |
return lerp( | |
col1, | |
col2, | |
(input-pos1)/(pos2 - pos1)); | |
} | |
if (input < pos3) { | |
return lerp( | |
col2, | |
col3, | |
(input-pos2)/(pos3 - pos2)); | |
} | |
return col3; | |
} | |
inline float4 generic_animated_ramp_three_color( float aposi, | |
float bposi, | |
float cposi, | |
float aposf, | |
float bposf, | |
float cposf, | |
float4 acoli, | |
float4 bcoli, | |
float4 ccoli, | |
float4 acolf, | |
float4 bcolf, | |
float4 ccolf, | |
float input, | |
float time) { | |
return generic_ramp_three_color( | |
lerp(aposi, aposf, time), | |
lerp(bposi, bposf, time), | |
lerp(cposi, cposf, time), | |
lerp(acoli, acolf, time), | |
lerp(bcoli, bcolf, time), | |
lerp(ccoli, ccolf, time), | |
input | |
); | |
} | |
inline float4 generic_ramp_four_color (in float pos1, | |
in float pos2, | |
in float pos3, | |
in float pos4, | |
in float4 col1, | |
in float4 col2, | |
in float4 col3, | |
in float4 col4, | |
in float input) { | |
// generic 4-color ramp | |
// TODO: branchless | |
if(input < pos1) { | |
return col1; | |
} | |
if (input < pos2) { | |
return lerp( | |
col1, | |
col2, | |
(input-pos1)/(pos2 - pos1)); | |
} | |
if (input < pos3) { | |
return lerp( | |
col2, | |
col3, | |
(input-pos2)/(pos3 - pos2)); | |
} | |
if (input < pos4) { | |
return lerp( | |
col3, | |
col4, | |
(input-pos3)/(pos4 - pos3)); | |
} | |
return col4; | |
} | |
// inline float4 rampSunAdjustment (float input) { | |
// return generic_ramp_two_color( | |
// 0.0, | |
// 370.0/508.0, | |
// BLACK, | |
// WHITE, | |
// input | |
// ); | |
// } | |
inline float4 rampMoonGlowAdjustment (float input) { | |
return 0; | |
return generic_ramp_four_color( | |
5.0/509.0, | |
253.0/509.0, | |
442.0/509.0, | |
1.0, | |
BLACK, | |
HEX(0x383838), | |
HEX(0xA1A1A1), | |
WHITE, | |
input | |
); | |
} | |
inline float4 rampMoonWashoutGradient (float input) { | |
return 1-input*0.125490196; | |
// return generic_ramp_two_color( | |
// 0.0, | |
// 509.0/509.0, | |
// WHITE, | |
// HEX(0x202020), | |
// input | |
// ); | |
} | |
float2 rotated_origin(in float2 xyorig, float theta) { | |
float costheta = cos(theta); | |
float sintheta = sin(theta); | |
float2 xyfinal = xyorig; | |
xyfinal.x = dot(xyorig, float2(costheta, -sintheta)); | |
xyfinal.y = dot(xyorig, float2(sintheta, costheta)); | |
return xyfinal; | |
} | |
float2 rotated_about(in float2 pivot, in float2 xyorig, float theta) { | |
return rotated_origin(xyorig-pivot, theta)+pivot; | |
} | |
float4 overlay (float4 canvas, float4 image, float factor) { | |
float4 node1 = sign(canvas - .5); | |
float4 node2 = (node1 - abs(node1)) * -.5; | |
float4 node3 = canvas*2*image; | |
float4 node4 = 1 - ( ((1-image)*2) * (1-canvas) ); | |
float4 node5 = node4 * (1-node2) + (node2*node3); | |
return lerp(canvas, node5, factor); | |
} | |
void _burn (float fac, float4 col1, float4 col2, out float4 outcol) | |
{ | |
// This is more or less taken directly from Blender. | |
fac = saturate(fac); | |
float tmp, facm = 1.0 - fac; | |
outcol = col1; | |
tmp = facm + fac*col2.r; | |
if(tmp <= 0.0) | |
outcol.r = 0.0; | |
else if((tmp = (1.0 - (1.0 - outcol.r)/tmp)) < 0.0) | |
outcol.r = 0.0; | |
else if(tmp > 1.0) | |
outcol.r = 1.0; | |
else | |
outcol.r = tmp; | |
tmp = facm + fac*col2.g; | |
if(tmp <= 0.0) | |
outcol.g = 0.0; | |
else if((tmp = (1.0 - (1.0 - outcol.g)/tmp)) < 0.0) | |
outcol.g = 0.0; | |
else if(tmp > 1.0) | |
outcol.g = 1.0; | |
else | |
outcol.g = tmp; | |
tmp = facm + fac*col2.b; | |
if(tmp <= 0.0) | |
outcol.b = 0.0; | |
else if((tmp = (1.0 - (1.0 - outcol.b)/tmp)) < 0.0) | |
outcol.b = 0.0; | |
else if(tmp > 1.0) | |
outcol.b = 1.0; | |
else | |
outcol.b = tmp; | |
} | |
float4 burn (in float fac, in float4 col1, in float4 col2) { | |
// Out-of-place version of _burn. | |
float4 outcol; | |
_burn(fac, col1, col2, outcol); | |
return outcol; | |
} | |
void _screen (in float fac, in float4 col1, in float4 col2, out float4 outcol) | |
{ | |
// Basically taken from Blender. | |
fac = clamp(fac, 0.0, 1.0); | |
float facm = 1.0 - fac; | |
outcol.rgb = 1.0 - (facm + fac*(1.0 - col2))*(1.0 - col1); | |
} | |
float4 screen (in float4 col1, in float4 col2, in float fac) { | |
// Out-of-place version of _screen | |
float4 outcol; | |
_screen(fac, col1, col2, outcol); | |
return outcol; | |
} | |
void _dodge(in float fac, in float4 col1, in float4 col2, out float4 outcol) | |
{ | |
// Also ported from Blender. | |
// fac = saturate(fac); | |
outcol = col1; | |
if(outcol.r != 0.0) { | |
float tmp = 1.0 - fac*col2.r; | |
if(tmp <= 0.0) | |
outcol.r = 1.0; | |
else if((tmp = outcol.r/tmp) > 1.0) | |
outcol.r = 1.0; | |
else | |
outcol.r = tmp; | |
} | |
if(outcol.g != 0.0) { | |
float tmp = 1.0 - fac*col2.g; | |
if(tmp <= 0.0) | |
outcol.g = 1.0; | |
else if((tmp = outcol.g/tmp) > 1.0) | |
outcol.g = 1.0; | |
else | |
outcol.g = tmp; | |
} | |
if(outcol.b != 0.0) { | |
float tmp = 1.0 - fac*col2.b; | |
if(tmp <= 0.0) | |
outcol.b = 1.0; | |
else if((tmp = outcol.b/tmp) > 1.0) | |
outcol.b = 1.0; | |
else | |
outcol.b = tmp; | |
} | |
} | |
float4 dodge (in float4 col1, in float4 col2, in float fac) { | |
// Out-of-place version of _dodge | |
float4 outcol; | |
_dodge(fac, col1, col2, outcol); | |
return outcol; | |
} | |
inline float4 multiply(in float4 col1, in float4 col2, float fac) { | |
// Half-baked multiplication. | |
// Partially mix in a color (or image) by multiplying it, but | |
// not taking a 100% wet result. | |
// | |
// Perhaps this can be rewritten. Instead of lerp(a, a*x, f) | |
// perhaps we can use a*(f*(x-1)+1). The question is whether | |
// two multiplys is faster than a multiply and a lerp. | |
return lerp(col1, col1*col2, fac); | |
} | |
inline float4 subtract(in float4 col1, in float4 col2, float fac) { | |
// Half-baked subtraction. | |
// ^^ Ditto. | |
return col1-col2*fac; | |
} | |
inline float4 add(in float4 col1, in float4 col2, float fac) { | |
// Half-baked addition. | |
// ^^ Ditto. | |
return col1+col2*fac; | |
} | |
half4 frag (v2f i) : COLOR { | |
// stripes for checking UV directions (change .x to .y for horizontal stripes; stripes increase in brightness in positive direction) | |
// if (fmod(i.uv.x, .2f) <= .04f) { | |
// return half4(i.uv.x, 0, 0, 1); | |
// } | |
// return half4(0, 0, 0, 1); | |
float4 UvInColor = BLENDERIFY(i.uv).xyyy * float4(1,1,0,0) + float4(0,0,0,1); | |
float4 DistortionTexture = tex2D(_DisplaceTexture, i.uv); | |
float4 DistortionOverlay = overlay(UvInColor, DistortionTexture, .150); | |
float2 DODB = DEBLENDERIFY(DistortionOverlay).xy; | |
float4 BaseClouds1 = tex2D(_BaseClouds1, DODB).xyzw; | |
float4 BaseClouds2 = tex2D(_BaseClouds2, DODB).xyzw; | |
float BaseClouds = lerp(BaseClouds1.x, BaseClouds1.y, _BaseFrame) * (_BaseFrame <= 1) + | |
lerp(BaseClouds1.y, BaseClouds1.z, _BaseFrame-1) * (1 < _BaseFrame && _BaseFrame <= 2) + | |
lerp(BaseClouds1.z, BaseClouds1.w, _BaseFrame-2) * (2 < _BaseFrame && _BaseFrame <= 3) + | |
lerp(BaseClouds1.w, BaseClouds2.x, _BaseFrame-3) * (3 < _BaseFrame && _BaseFrame <= 4) + | |
lerp(BaseClouds2.x, BaseClouds2.y, _BaseFrame-4) * (4 < _BaseFrame && _BaseFrame <= 5) + | |
lerp(BaseClouds2.y, BaseClouds2.z, _BaseFrame-5) * (5 < _BaseFrame && _BaseFrame <= 6) + | |
lerp(BaseClouds2.z, BaseClouds2.w, _BaseFrame-6) * (6 < _BaseFrame && _BaseFrame <= 7); | |
float Radius = length(BLENDERIFY(i.uv)); // TODO replace me with sample | |
float2 sample_point = 0.00390625; // skip the padding. same with the constant below. | |
sample_point.xy += 0.9921875*float2(BaseClouds, _Cloudiness); | |
float4 CloudGradientsSample = tex2D(_CloudGradient, sample_point); | |
float CloudAlpha = CloudGradientsSample.x; | |
float CloudEdge = CloudGradientsSample.y; | |
float CloudCenters = CloudGradientsSample.z; | |
float Backlighting = CloudGradientsSample.w; | |
float4 ClearFadeGradientSample = tex2D(_ClearFadeGradient, i.uv); | |
float4 ClearGradient = float4(ClearFadeGradientSample.x, ClearFadeGradientSample.y, ClearFadeGradientSample.z, 1.0); | |
float FadeGradient = ClearFadeGradientSample.w; | |
float4 OvercastZenithGradient = tex2D(_OvercastZenithGradient, i.uv); | |
float4 OvercastGradient = float4(OvercastZenithGradient.x, OvercastZenithGradient.y, OvercastZenithGradient.z, 1.0); | |
float HorizonZenithValue = OvercastZenithGradient.w; | |
float4 EdgeFade = FadeGradient * CloudEdge.xxxx; | |
/// | |
float4 GradientMix = lerp(ClearGradient, OvercastGradient, _Cloudiness); | |
float4 AlphaFade = FadeGradient*CloudAlpha.xxxx; | |
float4 OvercastDarkness = multiply(AlphaFade, HEX(0x59595C), _Cloudiness); | |
float4 CloudScreening = screen(GradientMix, OvercastDarkness, 1.0); | |
float2 SunPositionMapping = BLENDERIFY(i.uv - _SunPosition + .5) * .3; | |
float3 CircularGradientsSample1 = tex2D(_CircularGradients, saturate(DEBLENDERIFY(SunPositionMapping))).yzw; | |
float SunLighting = CircularGradientsSample1.x; | |
SunLighting *= _SunLightingIntensity; | |
float4 DynamicSunColor = generic_ramp_two_color(_DSP1, _DSP2, _DSC1, _DSC2, SunLighting); | |
float4 SunAdjustment = CircularGradientsSample1.y * _SunLightingIntensity; | |
float4 SunColorMultiply = SunAdjustment * DynamicSunColor; // TODO | |
//return SunColorMultiply; | |
float4 NightDarkness = multiply(CloudScreening, SunColorMultiply,.9); | |
float2 SunGlowMapping = saturate(DEBLENDERIFY(SunPositionMapping*6.0)); | |
float SunGlow = tex2D(_CircularGradients, SunGlowMapping).y; | |
float4 GlowSunColor = SunGlow * _SunGlowColor; | |
//float4 OvercastGlowDarkening = multiply(GlowSunColor, HEX(0x777777), _Cloudiness); | |
float4 GlowAdd = saturate(add(NightDarkness, GlowSunColor, SunGlow*_SunLightingIntensity)); | |
float4 GlowSunMix = lerp(GlowAdd, DynamicSunColor, 0.1); // TODO maybe? | |
float2 SunCircleMapping = saturate(DEBLENDERIFY(BLENDERIFY(SunGlowMapping)*20)); | |
float SunCircle = tex2D(_MoonAlpha, SunCircleMapping).x; // TODO combine with other sample | |
float4 AlphaInvert = 1-AlphaFade; | |
float4 CloudsBlockingSunCircle = SunCircle*AlphaInvert; | |
float4 SunCircleColor = AlphaInvert * _SunColor; | |
// [old] float4 SunCircleColor = multiply(CloudsBlockingSunCircle, _SunColor, .7); | |
float4 SunCircleAdd = screen(GlowSunMix, SunCircleColor, CloudsBlockingSunCircle); // TODO what's wrong with this | |
float4 EdgeGlowCombine = SunGlow * EdgeFade; | |
float4 OvercastEdgeDarkening = multiply(EdgeGlowCombine, .3, _Cloudiness); | |
float4 EdgeSunColor = OvercastEdgeDarkening * DynamicSunColor; | |
float4 SunEdgeAdd = saturate(SunCircleAdd + EdgeSunColor); | |
float4 BacklightingDarkeningMix = lerp(CloudCenters.xxxx, Backlighting, SunGlow); | |
float4 CenterDarkeningAndBacklighting = multiply(SunEdgeAdd, _CenterDarkenColor, BacklightingDarkeningMix); | |
float4 HorizonGlowGradient = 1-saturate(HorizonZenithValue*2); | |
float4 HorizonGlowColoring = HorizonGlowGradient * _HorizonGlowColor; | |
#define HORIZON_INTENSITY .23 | |
float4 HorizonGlowAdd = saturate(screen(CenterDarkeningAndBacklighting, HorizonGlowColoring, _SunLightingIntensity*HorizonGlowGradient*SunLighting*HORIZON_INTENSITY)); | |
float4 ZenithGradient = 2*HorizonZenithValue-1; | |
float4 ZenithSubtract = saturate(subtract(HorizonGlowAdd, ZenithGradient, .05)); | |
// MOON | |
float2 MoonPositionMapping = i.uv; | |
MoonPositionMapping = rotated_about(.5, MoonPositionMapping, _MoonAngle); | |
MoonPositionMapping -= rotated_origin(_MoonPosition-.5, _MoonAngle); | |
float2 MoonPositionMappingB = BLENDERIFY(MoonPositionMapping); // B means BLENDERIFY'd | |
///float2 MoonPositionMappingB = i.uv; | |
///MoonPositionMappingB = rotated_about(float2(.5,.5), MoonPositionMappingB, radians(_MoonAngle)); | |
///MoonPositionMappingB -= _MoonPosition*.5; | |
///MoonPositionMappingB = BLENDERIFY(MoonPositionMappingB); // B means BLENDERIFY'd | |
float2 MoonScaleMapping = saturate(DEBLENDERIFY(MoonPositionMappingB*20)); | |
float4 Moon = tex2D(_MoonDiff, MoonScaleMapping); | |
float4 MoonWashoutGradient = CircularGradientsSample1.z; | |
float4 WashoutMultiply1 = Moon * MoonWashoutGradient; | |
float4 WashoutSunColorMultiply = multiply(WashoutMultiply1, DynamicSunColor, .4); // SunGlowColor instead? | |
float4 CloudBlocking = WashoutSunColorMultiply * AlphaInvert; | |
float4 MoonAdd = saturate(add(ZenithSubtract, CloudBlocking, .7)); | |
/// | |
// Moon Glow | |
float2 MoonGlowScaleMapping = saturate(DEBLENDERIFY(MoonPositionMappingB*2)); | |
float MoonGlow = tex2D(_CircularGradients, MoonGlowScaleMapping).x; | |
float4 MoonGlowAdjust = rampMoonGlowAdjustment(MoonGlow); | |
float4 MoonGlowSunColorMultiply = multiply(MoonGlowAdjust, DynamicSunColor, .5); // used to be _MoonGlowColor | |
float4 WashoutMultiply2 = MoonGlowSunColorMultiply * MoonWashoutGradient; | |
float4 MoonGlowAdd = saturate(add(MoonAdd, WashoutMultiply2, .6)); | |
float4 EdgeMultiply = MoonGlowAdjust * EdgeFade; | |
float4 SunColorMultiply2 = multiply(EdgeMultiply, DynamicSunColor, .4); // used to be _MoonGlowColor | |
float4 MoonWashoutMultiply = SunColorMultiply2 * MoonWashoutGradient; | |
float4 EdgeMoonGlow = saturate(add(MoonGlowAdd, MoonWashoutMultiply, .2)); | |
// End Moon Glow | |
// Stars | |
float4 MoonAlphaInvert = 1-tex2D(_MoonAlpha, MoonScaleMapping); | |
float4 Stars = tex2D(_Stars, i.uv); | |
//float AlteredTime = _Time*_TwinkleSpeed; | |
//float TimeFac = sin(200*(AlteredTime+3*BaseClouds*BaseClouds)); | |
//TimeFac = .5*TimeFac+.5; | |
//Stars.xyz = Stars.xyz*pow(Stars.xyz, 1+(Stars.w*(Stars.w*3+1))*TimeFac*_TwinklePower); | |
float4 SunLightingInvert = 1-SunAdjustment; | |
float4 SunLightingMultiply = Stars * SunLightingInvert; | |
float4 CloudsBlockStars = SunLightingMultiply * AlphaInvert; | |
float4 MoonBlocksStars = CloudsBlockStars * MoonAlphaInvert; | |
float4 StarsWithIntensity = MoonBlocksStars * _StarIntensity; | |
float4 StarsAdd = saturate(EdgeMoonGlow + StarsWithIntensity); | |
// Lightning | |
float4 LightningColor = HEX(0x5890FF); | |
float2 LightningGlowControl = i.uv; | |
LightningGlowControl = rotated_about(.5, LightningGlowControl, radians(_LightningAngle)); | |
float2 LightningBoltsControl = LightningGlowControl; | |
int IntBltNum = int(_BoltNumber); | |
int BltRow = IntBltNum/3; | |
int BltCol = IntBltNum%3; | |
float2 BltCoord = float2(BltCol, BltRow)*ONETHIRD; | |
LightningBoltsControl += BltCoord - float2(ONETHIRD, 0); | |
LightningBoltsControl = clamp(LightningBoltsControl, BltCoord, BltCoord+ONETHIRD-float2(0,.1)); | |
float4 LightningBolts = tex2D(_LightningBolts, LightningBoltsControl).x; | |
float4 LightningBlockedByClouds = LightningBolts*AlphaInvert; | |
float4 LightningColoring = overlay(LightningBlockedByClouds, LightningColor, 1.0); | |
float4 BoltBrightnessControl = LightningColoring * _LightningBrightness; | |
//float4 LightningAdd1 = saturate(StarsAdd + BoltBrightnessControl); | |
float4 LightningAdd2 = saturate(StarsAdd + BoltBrightnessControl + BoltBrightnessControl); | |
float2 GlowAdjustChans = tex2D(_LightningGlow, LightningGlowControl).xy; | |
float4 GlowAdjust = lerp(GlowAdjustChans.x, GlowAdjustChans.y, _LightningGlowPhase).xxxx; | |
float4 GlowColorization = GlowAdjust * LightningColor; | |
float4 GlowBrightnessControl = GlowColorization*_LightningBrightness; | |
float4 LightningGlowAdd = saturate(add(LightningAdd2, GlowBrightnessControl, .574+_LightningGlowAdjustment)); | |
float4 CloudEdgeMultiply = GlowColorization * EdgeFade; | |
float4 EdgeBrightnessControl = CloudEdgeMultiply * _LightningBrightness; | |
float4 LightningGlowEdge = saturate(add(LightningGlowAdd, EdgeBrightnessControl, .6)); | |
return LightningGlowEdge; | |
} | |
ENDCG | |
} | |
} | |
FallBack "RenderFX/Skybox" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment