Last active
December 12, 2018 06:06
-
-
Save baobao/0dd059b7832f57854c1e956ba1aa4930 to your computer and use it in GitHub Desktop.
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 "shibuya24/Lambert" | |
{ | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque"} | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 normal : NORMAL; | |
}; | |
// Lighting.cgincをインクルードしない場合、 | |
// 定義するとUnityが自動でライトカラーを代入してくれる | |
fixed4 _LightColor0; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.normal = v.normal; | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
float4 invLightDir = mul(UNITY_MATRIX_M, -_WorldSpaceLightPos0); | |
// 法線ベクトルとライトベクトルの内積で拡散反射光の輝度を取得 | |
float luminance = dot(normalize(i.normal), invLightDir.xyz); | |
return float4(luminance,luminance,luminance, 1) * _LightColor0; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment