Skip to content

Instantly share code, notes, and snippets.

@went5
Created April 26, 2022 23:51
Show Gist options
  • Save went5/e5c9a80ed1ab5599f5cb67c7871cb5c9 to your computer and use it in GitHub Desktop.
Save went5/e5c9a80ed1ab5599f5cb67c7871cb5c9 to your computer and use it in GitHub Desktop.
Shader "Custom/HalfLambert"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
[Toggle(IS_DARK)] _IsDark ("Is Dark", Float) = 0
}
SubShader
{
Tags
{
"RenderType"="Opaque"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature IS_DARK
#include "UnityCG.cginc"
#include "Lighting.cginc"
struct v2f
{
float4 vertex : SV_POSITION;
float3 worldNormal:NORMAL;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
float _isDark;
v2f vert(appdata_base v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.worldNormal = UnityObjectToWorldNormal(v.normal);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
float3 NdotL = dot(i.worldNormal, lightDir);
#ifdef IS_DARK
float3 HNdotL = pow(0.5 * NdotL + 0.5, 2);
#else
float3 HNdotL = 0.5 * NdotL + 0.5;
#endif
// color
fixed4 mainTexColor = tex2D(_MainTex, i.uv);
float3 HNdotLColor = HNdotL * _LightColor0 * mainTexColor * _Color;
fixed4 col = fixed4(HNdotLColor, 1.0);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment