Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created July 27, 2021 23:00
Show Gist options
  • Select an option

  • Save whoisryosuke/43332e8fe7b527a339fc3a45703f56f3 to your computer and use it in GitHub Desktop.

Select an option

Save whoisryosuke/43332e8fe7b527a339fc3a45703f56f3 to your computer and use it in GitHub Desktop.
Unity / Shader - Horizontal Skybox
Shader "Custom/Horizontal Skybox"
{
Properties
{
_Color1 ("Top Color", Color) = (1, 1, 1, 0)
_Color2 ("Horizon Color", Color) = (1, 1, 1, 0)
_Color3 ("Bottom Color", Color) = (1, 1, 1, 0)
_Exponent1 ("Exponent Factor for Top Half", Float) = 1.0
_Exponent2 ("Exponent Factor for Bottom Half", Float) = 1.0
_Intensity ("Intensity Amplifier", Float) = 1.0
_Angle ("Angle", Float) = 0.0
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 position : POSITION;
float3 texcoord : TEXCOORD0;
};
struct v2f
{
float4 position : SV_POSITION;
float3 texcoord : TEXCOORD0;
};
half4 _Color1;
half4 _Color2;
half4 _Color3;
half _Intensity;
half _Exponent1;
half _Exponent2;
half _Angle;
v2f vert (appdata v)
{
v2f o;
float sinX = sin ( _Angle );
float cosX = cos ( _Angle );
float sinY = sin ( _Angle );
float2x2 rotationMatrix = float2x2( cosX, -sinX, sinY, cosX);
o.position = mul (UNITY_MATRIX_MVP, v.position);
o.texcoord.xz = mul(v.texcoord.xz, rotationMatrix);
o.texcoord.y = v.texcoord.y;
return o;
}
half4 frag (v2f i) : COLOR
{
float p = normalize (i.texcoord).x;
float p1 = 1.0f - pow (min (1.0f, 1.0f - p), _Exponent1);
float p3 = 1.0f - pow (min (1.0f, 1.0f + p), _Exponent2);
float p2 = 1.0f - p1 - p3;
return (_Color1 * p1 + _Color2 * p2 + _Color3 * p3) * _Intensity;
}
ENDCG
SubShader
{
Tags { "RenderType"="Background" "Queue"="Background" }
Pass
{
ZWrite Off
Cull Off
Fog { Mode Off }
CGPROGRAM
#pragma fragmentoption ARB_precision_hint_fastest
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment