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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| //-------------------------------------------------------
// PPL effect.
//-------------------------------------------------------
//-------------------------------------------------------
// Globals.
//-------------------------------------------------------
float4x4 g_mWorldViewProj;
float4x4 g_mWorld;
float3 g_vLightPos;
float3 g_vEyePos;
float4 g_cMaterialAmbient;
float4 g_cMaterialDiffuse;
float4 g_cMaterialSpecular;
float4 g_cLightAmbient;
float4 g_cLightDiffuse;
float4 g_cLightSpecular;
texture g_tDiffuseMap;
//-------------------------------------------------------
// Sampler.
//-------------------------------------------------------
sampler g_sDiffuseMap =
sampler_state
{
Texture = <g_tDiffuseMap>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
//-------------------------------------------------------
// VS & PS struct.
//-------------------------------------------------------
struct VS_IN
{
float4 position : POSITION;
float2 texCoord0 : TEXCOORD0;
float3 normal : NORMAL;
};
struct VS_OUT
{
float4 position : POSITION;
float2 texCoord0 : TEXCOORD0;
float3 normal : TEXCOORD1;
float3 pixPos : TEXCOORD2;
};
//-------------------------------------------------------
// Vs
//-------------------------------------------------------
void main_vs(in VS_IN input, out VS_OUT output)
{
output.position = mul(input.position, g_mWorldViewProj);
output.texCoord0 = input.texCoord0;
output.normal = mul(input.normal, (float3x3)g_mWorld);
float3 vVertex = mul(input.position, g_mWorld);
output.pixPos = vVertex;
}
//-------------------------------------------------------
//Ps
//-------------------------------------------------------
void main_ps(in VS_OUT input, out float4 color : COLOR)
{
float4 If, Ia, Id, Is;
Ia = g_cMaterialAmbient * g_cLightAmbient;
float3 lightDir(g_vLightPos);
lightDir -= input.pixPos;
float3 N = normalize(input.normal);
float3 L = normalize(lightDir);
float lambert = max(dot(N, L), 0);
if(lambert > 0)
{
Id = g_cLightDiffuse * g_cMaterialDiffuse * lambert;
float3 eyeDir(g_vEyePos);
eyeDir -= input.pixPos;
float3 E = normalize(eyeDir);
float3 R = reflect(-L, E);
float spec = pow(max(dot(R, E), 0), 1);
Is = g_cLightSpecular * g_cMaterialSpecular * spec;
If = Ia + Id + Is;
}
color = If * tex2D(g_sDiffuseMap, input.texCoord0);
};
technique T
{
pass P
{
VertexShader = compile vs_3_0 main_vs();
PixelShader = compile ps_3_0 main_ps();
}
} |
Partager