Skip to content

Instantly share code, notes, and snippets.

@yasirkula
Last active March 3, 2021 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yasirkula/42ecade9688cf0508c83b6bc02948dbe to your computer and use it in GitHub Desktop.
Save yasirkula/42ecade9688cf0508c83b6bc02948dbe to your computer and use it in GitHub Desktop.
Unlit shader with shadows support for Unity's Built-in Render Pipeline
Shader "Unlit/Texture with Shadows"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white"
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry" }
LOD 100
Pass
{
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
SHADOW_COORDS(2)
};
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o, o.vertex);
TRANSFER_SHADOW(o)
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv) * _Color * SHADOW_ATTENUATION(i);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}
@yasirkula
Copy link
Author

yasirkula commented Jan 21, 2021

How To

Simply create a new Unlit Shader and replace its contents with this shader. Then, assign Unlit/Texture with Shadows shader to your materials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment