1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
struct VS_INPUT
{
float4 Position : POSITION;
float3 Normal : NORMAL;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Color : COLOR0;
};
// Views
float4x4 ModelViewMatrix;
float4x4 ProjectionMatrix;
float3x3 NormalMatrix;
VS_OUTPUT vs_main( in VS_INPUT In )
{
//Material values
float4 MaterialAmbient = float4(1.0,1.0,1.0,1.0);
float4 MaterialDiffuse = float4(1.0,1.0,1.0,1.0);
//Light values
float4 LightPosition = float4(360, 430, 242, 1.0f);
float4 LightDiffuse = float4(1.0f, 1.0f, 1.0f, 1.0f);
float4 LightAmbient = float4(0.5f, 0.5f, 0.5f, 1.0f);
VS_OUTPUT Out;
float3 N = normalize(mul(In.Normal,NormalMatrix));
float3 L = normalize(mul(LightPosition,ModelViewMatrix)).xyz;
float NdotL = max(dot(N,L.xyz), 0.0);
float4 finalColor = mul(LightAmbient,MaterialAmbient);
float4 pos = mul(In.Position,ModelViewMatrix);
if (NdotL > 0.0)
{
finalColor += (mul(LightDiffuse,MaterialDiffuse) * NdotL);
}
Out.Position = mul(pos,ProjectionMatrix);
Out.Color = finalColor;
return Out;
} |
Partager