Created
January 1, 2021 23:45
-
-
Save partybusiness/3efb0e384ebb549f23d02f3ba2cb013a to your computer and use it in GitHub Desktop.
Skybox has four-colour gradient aligned with screen-space rather than world space.
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 "Unlit/FourCornerGradientScreen" | |
{ | |
Properties{ | |
_TopLeft("Top Left", Color) = (0.5,0.5,0.5,1) | |
_TopRight("Top Right", Color) = (0.5,0.5,0.5,1) | |
_BottomLeft("Bottom Left", Color) = (0.5,0.5,0.5,1) | |
_BottomRight("Bottom Right", Color) = (0.5,0.5,0.5,1) | |
} | |
SubShader{ | |
Tags{ "Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox" } | |
Cull Back | |
Lighting Off | |
ZWrite Off | |
Pass{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
float4 _TopLeft; | |
float4 _TopRight; | |
float4 _BottomLeft; | |
float4 _BottomRight; | |
struct appdata { | |
float4 vertex : POSITION; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float4 scrPos: TEXCOORD0; | |
}; | |
v2f vert(appdata v) { | |
v2f o; | |
o.pos = UnityObjectToClipPos(v.vertex); | |
o.scrPos = ComputeScreenPos(o.pos); | |
return o; | |
} | |
fixed4 frag(v2f i) : COLOR { | |
fixed2 screenUV = i.scrPos.xy / i.scrPos.w; | |
fixed4 color = | |
lerp( | |
lerp(_BottomLeft, _BottomRight, screenUV.x), | |
lerp(_TopLeft, _TopRight, screenUV.x), | |
screenUV.y); | |
return color; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment