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

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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines