1 |
root |
1.1 |
// final pixel output: |
2 |
|
|
// data from pixel shader to frame buffer |
3 |
root |
1.2 |
struct vertexOut { |
4 |
|
|
float4 HPosition : POSITION; |
5 |
|
|
float4 TexCoord : TEXCOORD0; |
6 |
|
|
float3 LightVec : TEXCOORD1; |
7 |
|
|
float3 WorldNormal : TEXCOORD2; |
8 |
|
|
float3 WorldPos : TEXCOORD3; |
9 |
|
|
float3 WorldView : TEXCOORD4; |
10 |
|
|
}; |
11 |
root |
1.1 |
|
12 |
|
|
struct pixelOut { |
13 |
|
|
float4 col : COLOR; |
14 |
|
|
}; |
15 |
root |
1.3 |
|
16 |
root |
1.1 |
// pixel shader |
17 |
root |
1.3 |
pixelOut main(vertexOut IN // input from vertex shade |
18 |
|
|
//uniform float SpecExpon, // constant parameters fro |
19 |
|
|
//uniform float4 AmbiColor, // application |
20 |
|
|
//uniform float4 SurfColor, |
21 |
|
|
//uniform float4 LightColor |
22 |
root |
1.1 |
) |
23 |
|
|
{ |
24 |
root |
1.4 |
float SpecExpon = 120; |
25 |
root |
1.5 |
float4 LightColor = { 1, 1, 1, 1 }; |
26 |
root |
1.3 |
|
27 |
root |
1.1 |
pixelOut OUT; // output of the pixel shader |
28 |
|
|
float3 Ln = normalize(IN.LightVec); |
29 |
|
|
float3 Nn = normalize(IN.WorldNormal); |
30 |
|
|
float3 Vn = normalize(IN.WorldView); |
31 |
root |
1.3 |
float3 Hn = normalize(Vn + Ln); |
32 |
root |
1.1 |
// scalar product between light and normal vectors: |
33 |
|
|
float ldn = dot(Ln,Nn); |
34 |
|
|
// scalar product between halfway and normal vectors: |
35 |
|
|
float hdn = dot(Hn,Nn); |
36 |
|
|
// specialized "lit" function computes weights for |
37 |
|
|
// diffuse and specular parts: |
38 |
|
|
float4 litV = lit(ldn,hdn,SpecExpon); |
39 |
root |
1.5 |
float4 diffContrib = glstate.material.diffuse * ( litV.y * LightColor + glstate.lightmodel.ambient); |
40 |
root |
1.1 |
float4 specContrib = litV.y*litV.z * LightColor; |
41 |
|
|
// sum of diffuse and specular contributions: |
42 |
|
|
float4 result = diffContrib + specContrib; |
43 |
root |
1.5 |
OUT.col = result; |
44 |
root |
1.1 |
return OUT; // output of pixel shader |
45 |
|
|
} |
46 |
|
|
|