Created
July 28, 2021 07:29
-
-
Save cs-altshift/e6933d793de0a4ec2ee548f4b0ad552d to your computer and use it in GitHub Desktop.
Crying Suns Command-Center Glass 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
Shader "Crying Suns/Command Center Glass" | |
{ | |
Properties | |
{ | |
[PerRendererData] _MainTex ("Main Texture (ignored)", 2D) = "white" {} | |
[NoScaleOffset] _ReflectionTex ("Reflection Texture", 2D) = "black" {} | |
_ReflectionAlpha ("Reflection Alpha", Range(0, 1)) = 0.25 | |
_ReflectionScale ("Reflection Scale", Range(0, 1)) = 1 | |
[HideInInspector] _SunCenteredViewportPos ("Sun Centered Viewport Position", Vector) = (0, 0, 0, 0) | |
[HideInInspector] _SunAngle ("Sun Angle", Float) = 0 | |
_MaxSunGazeAlpha ("Max Sun Gaze Alpha", Range(0, 1)) = 0.5 | |
} | |
SubShader | |
{ | |
Tags { | |
"RenderType"="Transparent" | |
"Queue"="Transparent" | |
} | |
Cull Off | |
Lighting Off | |
ZWrite Off | |
ZTest [unity_GUIZTestMode] | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass | |
{ | |
Name "SUN" | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
}; | |
struct v2f | |
{ | |
float4 screenPos : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.screenPos = ComputeScreenPos(o.vertex); | |
return o; | |
} | |
fixed4 _SunCenteredViewportPos; | |
fixed _SunAngle; | |
fixed _MaxSunGazeAlpha; | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
float intensity = abs(_SunCenteredViewportPos.x) / 0.5; | |
intensity = clamp(intensity, 0, 1); | |
fixed inverseScreenRatio = _ScreenParams.y / _ScreenParams.x; | |
fixed2 centeredScreenPos = (i.screenPos.xy / i.screenPos.w) - fixed2(0.5, 0.5); | |
fixed2 remappedCenteredScreenPos = fixed2(centeredScreenPos.x, centeredScreenPos.y * inverseScreenRatio); | |
fixed2 remappedSunCenteredViewportPos = fixed2(_SunCenteredViewportPos.x, _SunCenteredViewportPos.y * inverseScreenRatio); | |
float minDistance = 0.35; | |
float paramDistance = distance(remappedCenteredScreenPos, remappedSunCenteredViewportPos); | |
float sunDistance = paramDistance * paramDistance; | |
fixed alpha = 0; | |
float lineBand = 2 * minDistance / 3; | |
if (sunDistance > lineBand && sunDistance < 3 * lineBand) { | |
alpha = lerp(0.2, 0.6, (sunDistance - lineBand)/lineBand); | |
} else if (sunDistance >= 3 * lineBand) { | |
alpha = lerp(0.6, 0, (sunDistance - 3 * lineBand) / (3 * lineBand)); | |
} | |
return fixed4(1, 1, 1, intensity * alpha * _MaxSunGazeAlpha); | |
} | |
ENDCG | |
} | |
Pass | |
{ | |
Name "COLOR" | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR; | |
}; | |
struct v2f | |
{ | |
float4 color : COLOR; | |
float4 vertex : SV_POSITION; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.color = v.color; | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
return i.color; | |
} | |
ENDCG | |
} | |
Pass | |
{ | |
Name "REFLECTION" | |
Blend One One | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
}; | |
struct v2f | |
{ | |
float4 screenPos : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _ReflectionTex; | |
float4 _ReflectionTex_ST; | |
float _ReflectionAlpha; | |
float _ReflectionScale; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.screenPos = ComputeScreenPos(o.vertex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
float2 uv = (i.screenPos.xy / i.screenPos.w); | |
uv -= float2((1.0 - _ReflectionScale) / 2, (1.0 - _ReflectionScale) / 2); | |
uv /= _ReflectionScale; | |
fixed4 col = tex2D(_ReflectionTex, uv); | |
col *= _ReflectionAlpha; | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment