Skip to content

Instantly share code, notes, and snippets.

@hiepnd
Last active December 2, 2015 10:37
Show Gist options
  • Save hiepnd/d2f8820737fea52b1145 to your computer and use it in GitHub Desktop.
Save hiepnd/d2f8820737fea52b1145 to your computer and use it in GitHub Desktop.
Unity Color Lit shader
Shader "Screw/Lit Color" {
Properties {
_Color ("Color", Color) = (1, 1, 1, 1)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct VertexInput {
half4 vertex : POSITION;
half2 texcoord : TEXCOORD;
half3 normal : NORMAL;
};
struct VertexOutput {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD;
half3 normalDir : NORMAL;
};
half4 _Color;
half4 _LightColor0;
VertexOutput vert (VertexInput i) {
VertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, i.vertex);
o.uv = i.texcoord;
o.normalDir = normalize(mul(float4( i.normal, 0.0 ), _World2Object ).xyz );
return o;
}
half4 frag (VertexOutput i) : COLOR {
half3 lightDirection = normalize(-_WorldSpaceLightPos0.xyz);
half4 color = _LightColor0 * max(0.0, dot(i.normalDir, lightDirection));
color = color + UNITY_LIGHTMODEL_AMBIENT;
return color * _Color;
}
ENDCG
}
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment