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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
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;
//Material values
float4 MaterialAmbient;
float4 MaterialDiffuse;
float4 MaterialSpecular;
float4 MaterialEmissive;
float MaterialShininess;
//Light values
float4 LightPosition;
float4 LightDiffuse;
float4 LightSpecular;
float4 LightAmbient;
VS_OUTPUT vs_main( in VS_INPUT In )
{
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);
float3 E = -pos.xyz;
if (NdotL > 0.0)
{
float3 HV = normalize(L + E);
finalColor += MaterialDiffuse * LightDiffuse * NdotL;
}
Out.Position = mul(pos,ProjectionMatrix);
Out.Color = finalColor;
return Out;
}
/*****************************************************/
/*****************************************************/
/*****************************************************/
// Pixel shader input structure
struct PS_INPUT
{
float4 Color : COLOR0;
};
// Pixel shader output structure
struct PS_OUTPUT
{
float4 Color : COLOR0;
};
PS_OUTPUT ps_main( in PS_INPUT In )
{
PS_OUTPUT Out;
Out.Color = In.Color;
return Out;
} |
Partager