1 |
// final pixel output: |
2 |
// data from pixel shader to frame buffer |
3 |
|
4 |
struct pixelOut { |
5 |
float4 col : COLOR; |
6 |
}; |
7 |
// pixel shader |
8 |
pixelOut mainPS(vertexOut IN, // input from vertex shade |
9 |
uniform float SpecExpon, // constant parameters fro |
10 |
uniform float4 AmbiColor, // application |
11 |
uniform float4 SurfColor, |
12 |
uniform float4 LightColor |
13 |
) |
14 |
{ |
15 |
pixelOut OUT; // output of the pixel shader |
16 |
float3 Ln = normalize(IN.LightVec); |
17 |
float3 Nn = normalize(IN.WorldNormal); |
18 |
float3 Vn = normalize(IN.WorldView); |
19 |
float3 Hn = normalize(Vn + |
20 |
// scalar product between light and normal vectors: |
21 |
float ldn = dot(Ln,Nn); |
22 |
// scalar product between halfway and normal vectors: |
23 |
float hdn = dot(Hn,Nn); |
24 |
// specialized "lit" function computes weights for |
25 |
// diffuse and specular parts: |
26 |
float4 litV = lit(ldn,hdn,SpecExpon); |
27 |
float4 diffContrib = |
28 |
SurfColor * ( litV.y * LightColor + AmbiColor); |
29 |
float4 specContrib = litV.y*litV.z * LightColor; |
30 |
// sum of diffuse and specular contributions: |
31 |
float4 result = diffContrib + specContrib; |
32 |
OUT.col = result; |
33 |
return OUT; // output of pixel shader |
34 |
} |
35 |
|