Skip to content

Instantly share code, notes, and snippets.

@dpchamps
Last active February 16, 2021 00:24
Show Gist options
  • Save dpchamps/90b1c9df1ad6d9c5a1a7c65c82888fd7 to your computer and use it in GitHub Desktop.
Save dpchamps/90b1c9df1ad6d9c5a1a7c65c82888fd7 to your computer and use it in GitHub Desktop.
Shader "NightImageEffect"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_NightColor ("Night Color", Color) = (1,1,1,1)
_Alpha ("Alpha", Range(0, 1)) = 1
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
Tags
{
"Queue"="Transparent"
"RenderType"="Transparent"
"LightMode"="ForwardBase"
}
Lighting On
CGPROGRAM
// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members light)
#pragma exclude_renderers d3d11
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _LightColor0;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal: NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 posWorld : TEXCOORD1;
float light: COLOR0;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
return o;
}
sampler2D _MainTex;
float4 _NightColor;
float _Alpha;
fixed4 frag (v2f i) : SV_Target
{
float dist = _Alpha;
fixed4 col = tex2D(_MainTex, i.uv);
float4 mult = _NightColor + (float4(1,1,1,1) * dist);
return col * clamp( mult, float4(0,0,0,0), float4(1,1,1,1) );
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment