Skip to content

Instantly share code, notes, and snippets.

@sapphire-al2o3
Created September 29, 2014 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sapphire-al2o3/fab0d7396ca96b25cb63 to your computer and use it in GitHub Desktop.
Save sapphire-al2o3/fab0d7396ca96b25cb63 to your computer and use it in GitHub Desktop.
Unityで陰の色を指定するシェーダ
Shader "Custom/VtxColor4" {
Properties {
_LightColor("Light Color", Color) = (1, 1, 1, 1)
_DarkColor("Dark Color", Color) = (1, 1, 1, 1)
_Dir("Dir", Vector) = (1, 1, 1, 0)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
half3 normal : NORMAL;
fixed4 color : COLOR;
};
struct v2f {
float4 position : SV_POSITION;
fixed4 color : COLOR;
};
uniform fixed4 _LightColor;
uniform fixed4 _DarkColor;
uniform half3 _Dir;
v2f vert(appdata_t v) {
v2f o;
o.position = mul(UNITY_MATRIX_MVP, v.vertex);
float l = dot(normalize(_Dir), v.normal) * 0.5 + 0.5;
o.color = lerp(_DarkColor, _LightColor, l * l);
return o;
}
fixed4 frag(v2f i) : COLOR {
fixed4 col = i.color;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment