Skip to content

Instantly share code, notes, and snippets.

@baobao
Created December 12, 2018 18:26
Show Gist options
  • Save baobao/0d5afa4883cb682c4149959f1ccf28e0 to your computer and use it in GitHub Desktop.
Save baobao/0d5afa4883cb682c4149959f1ccf28e0 to your computer and use it in GitHub Desktop.
WorldSpaceLightDir関数使ってる
/**
* 頂点ライティング
*/
Shader "VertexLighting"
{
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;
float luminance : TEXCOORD0;
};
fixed4 _LightColor0;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
float4 invLightDir = mul(UNITY_MATRIX_M, -WorldSpaceLightDir(v.vertex));
// 各頂点の拡散反射輝度を算出
float luminance = dot(v.normal, normalize(invLightDir));
o.luminance = luminance;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return float4(i.luminance, i.luminance, i.luminance, 1) * _LightColor0;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment