ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/fsh.cg
(Generate patch)

Comparing libgender/fsh.cg (file contents):
Revision 1.3 by root, Tue Oct 5 07:35:26 2004 UTC vs.
Revision 1.11 by root, Tue Oct 5 11:27:11 2004 UTC

1// final pixel output:
2// data from pixel shader to frame buffer
3struct vertexOut { 1struct vertexOut {
4 float4 HPosition : POSITION; 2 float4 HPosition : POSITION;
5 float4 TexCoord : TEXCOORD0; 3 float4 TexCoord : TEXCOORD0;
6 float3 LightVec : TEXCOORD1; 4 float3 LightVec : TEXCOORD1;
5 float3 EyeVec : TEXCOORD2;
7 float3 WorldNormal : TEXCOORD2; 6 float3 WorldNormal : TEXCOORD3;
8 float3 WorldPos : TEXCOORD3;
9 float3 WorldView : TEXCOORD4;
10}; 7};
11 8
12struct pixelOut { 9struct pixelOut {
13 float4 col : COLOR; 10 float4 col : COLOR;
14}; 11};
15 12
16// pixel shader 13pixelOut main(vertexOut IN)
17pixelOut 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 )
23{ 14{
15 pixelOut OUT; // output of the pixel shader
16
24 float SpecExpon = 100; 17 float SpecExpon = 120;
25 float4 AmbiColor = { 0.5, 0, 0, 1 };
26 float4 SurfColor = { 0, 0.5, 0, 1 };
27 float4 LightColor = { 1, 1, 1, 1 }; 18 float4 LightColor = { 1, 1, 1, 1 };
28 19
29 pixelOut OUT; // output of the pixel shader 20 half3 n = IN.WorldNormal;
21 half3 v = IN.EyeVec;
22 half3 l = IN.LightVec;
23
24 half r = reflect (-v, n);
25 half spec = pow (clamp (dot (l, r), 0, 1), SpecExpon);
26 half diff = clamp (dot (n, l), 0.0, 1);
27
28 OUT.col = glstate.material.diffuse * diff + LightColor * spec;
29 return OUT;
30
31 /*
30 float3 Ln = normalize(IN.LightVec); 32 float3 Ln = normalize (IN.LightVec);
31 float3 Nn = normalize(IN.WorldNormal); 33 float3 Nn = normalize (IN.WorldNormal);
32 float3 Vn = normalize(IN.WorldView); 34 float3 Vn = normalize (IN.EyeVec);
33 float3 Hn = normalize(Vn + Ln); 35
34 // scalar product between light and normal vectors: 36 float3 Hn = 0.5 * (Ln + Vn);
35 float ldn = dot(Ln,Nn); 37 float ldn = dot (Ln, Nn);
36 // scalar product between halfway and normal vectors:
37 float hdn = dot(Hn,Nn); 38 float hdn = dot (Hn, Nn);
39
38 // specialized "lit" function computes weights for 40 // specialized "lit" function computes weights for
39 // diffuse and specular parts: 41 // diffuse and specular parts:
40 float4 litV = lit(ldn,hdn,SpecExpon); 42 float4 litV = lit (ldn, hdn, SpecExpon);
41 OUT.col = litV.x * AmbiColor + litV.y * SurfColor + litV.z * LightColor; 43 float4 diffContrib = glstate.material.diffuse * (litV.y * LightColor + glstate.lightmodel.ambient);
44 float4 specContrib = litV.y * litV.z * LightColor;
45 float4 result = diffContrib + specContrib;
46
47 OUT.col = result;
42 return OUT; 48 return OUT;
43 float4 diffContrib = SurfColor * ( litV.y * LightColor + AmbiColor); 49 */
44 float4 specContrib = litV.y*litV.z * LightColor;
45 // sum of diffuse and specular contributions:
46 float4 result = diffContrib + specContrib;
47 OUT.col = result + AmbiColor;
48 return OUT; // output of pixel shader
49} 50}
50 51

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines