Last active
December 2, 2015 10:37
-
-
Save hiepnd/d2f8820737fea52b1145 to your computer and use it in GitHub Desktop.
Unity Color Lit shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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