Unity と CG で基本的な n-dot-l ライティングを実行しようとしています。
私の理解では、カメラでオブジェクトを見る場所によって照明が変わるべきではありません。しかし、私の状況ではそうです。
struct v2f {
float4 pos : SV_POSITION;
float3 LightDirection: TEXCOORD2;
float3 Normal: TEXCOORD3;
};
uniform float4 _LightPos;
v2f vert (appdata_tan v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.Texcoord = v.texcoord;
float3 p = mul(UNITY_MATRIX_MV, v.vertex);
o.LightDirection = _LightPos.xyz - p;
o.Normal = v.normal;
return o;
}
half4 frag (v2f i) : COLOR
{
float3 l = normalize(i.LightDirection);
float3 n = normalize(i.Normal);
float x = dot(n,l);
return float4(x,x,x,1);
}
このコードには何が欠けていますか?
モデルビュー マトリックスでもライトの位置を変換する必要がありますか?
ありがとう!