… | |
… | |
2 | float4 HPosition : POSITION; |
2 | float4 HPosition : POSITION; |
3 | float4 TexCoord : TEXCOORD0; |
3 | float4 TexCoord : TEXCOORD0; |
4 | float3 LightVec : TEXCOORD1; |
4 | float3 LightVec : TEXCOORD1; |
5 | float3 EyeVec : TEXCOORD2; |
5 | float3 EyeVec : TEXCOORD2; |
6 | float3 WorldNormal : TEXCOORD3; |
6 | float3 WorldNormal : TEXCOORD3; |
|
|
7 | float3 WorldView : TEXCOORD4; |
|
|
8 | float3 test1 : TEXCOORD5; |
|
|
9 | float3 test2 : TEXCOORD6; |
7 | }; |
10 | }; |
8 | |
11 | |
9 | struct pixelOut { |
12 | struct pixelOut { |
10 | float4 col : COLOR; |
13 | float4 col : COLOR; |
11 | }; |
14 | }; |
12 | |
15 | |
13 | pixelOut main(vertexOut IN) |
16 | pixelOut main(vertexOut IN, uniform sampler2D Texture) |
14 | { |
17 | { |
15 | pixelOut OUT; // output of the pixel shader |
18 | pixelOut OUT; |
16 | |
19 | |
17 | float SpecExpon = 120; |
20 | half SpecExpon = 200; |
|
|
21 | float4 AmbiColor = { 0.9, 0.9, 0.9, 1.0 }; |
18 | float4 LightColor = { 1, 1, 1, 1 }; |
22 | float4 LightColor = { 1, 1, 1, 1 }; |
|
|
23 | float4 diffuse_color = tex2D (Texture, IN.TexCoord.xy); |
19 | |
24 | |
20 | float3 Ln = IN.LightVec; |
25 | half3 Ln = normalize (IN.LightVec); |
21 | float3 Nn = IN.WorldNormal; |
26 | half3 Nn = normalize (IN.WorldNormal); |
22 | float3 Vn = IN.EyeVec; |
27 | half3 Vn = normalize (IN.WorldView); |
|
|
28 | |
|
|
29 | half3 Hn = normalize (Ln + Vn); |
|
|
30 | half ldn = dot (Ln, Nn); |
|
|
31 | half hdn = dot (Hn, Nn); |
23 | |
32 | |
24 | float3 Hn = 0.5 * (Ln + Vn); |
|
|
25 | float ldn = dot (Ln, Nn); |
|
|
26 | float hdn = dot (Hn, Nn); |
|
|
27 | |
|
|
28 | // specialized "lit" function computes weights for |
|
|
29 | // diffuse and specular parts: |
|
|
30 | float4 litV = lit (ldn, hdn, SpecExpon); |
33 | half4 litV = lit (ldn, hdn, SpecExpon); |
31 | float4 diffContrib = glstate.material.diffuse * (litV.y * LightColor + glstate.lightmodel.ambient); |
34 | half4 diffContrib = diffuse_color * (litV.y * LightColor + glstate.lightmodel.ambient); |
32 | float4 specContrib = litV.y * litV.z * LightColor; |
35 | half4 specContrib = litV.y * litV.z * LightColor; |
33 | float4 result = diffContrib + specContrib; |
36 | half4 result = diffContrib + specContrib; |
|
|
37 | //half4 result = diffuse_color * litV.y + LightColor * litV.z; |
34 | |
38 | |
35 | OUT.col = result; |
39 | OUT.col = result; |
36 | return OUT; |
40 | return OUT; |
37 | } |
41 | } |
38 | |
42 | |