--- libgender/fsh.cg 2004/10/05 08:14:21 1.6 +++ libgender/fsh.cg 2004/10/06 14:37:34 1.17 @@ -1,46 +1,42 @@ -// final pixel output: -// data from pixel shader to frame buffer struct vertexOut { - float4 HPosition : POSITION; - float4 TexCoord : TEXCOORD0; - float3 LightVec : TEXCOORD1; - float3 WorldNormal : TEXCOORD2; - float3 WorldPos : TEXCOORD3; - float3 WorldView : TEXCOORD4; + float4 HPosition : POSITION; + float4 TexCoord : TEXCOORD0; + float3 LightVec : TEXCOORD1; + float3 EyeVec : TEXCOORD2; + float3 WorldNormal : TEXCOORD3; + float3 WorldView : TEXCOORD4; + float3 test1 : TEXCOORD5; + float3 test2 : TEXCOORD6; }; struct pixelOut { float4 col : COLOR; }; -// pixel shader -pixelOut main(vertexOut IN // input from vertex shade - //uniform float SpecExpon, // constant parameters fro - //uniform float4 AmbiColor, // application - //uniform float4 SurfColor, - //uniform float4 LightColor - ) +pixelOut main(vertexOut IN, uniform sampler2D Texture) { - float SpecExpon = 120; + pixelOut OUT; + + half SpecExpon = 200; + float4 AmbiColor = { 0.1, 0.1, 0.1, 1.0 }; float4 LightColor = { 1, 1, 1, 1 }; + float4 diffuse_color = tex2D (Texture, IN.TexCoord.xy); + + half3 Ln = normalize (IN.LightVec); + half3 Nn = normalize (IN.WorldNormal); + half3 Vn = normalize (IN.WorldView); + + half3 Hn = normalize (Ln + Vn); + half ldn = dot (Ln, Nn); + half hdn = dot (Hn, Nn); + + half4 litV = lit (ldn, hdn, SpecExpon); + half4 diffContrib = diffuse_color * (litV.y * LightColor + glstate.lightmodel.ambient); + half4 specContrib = litV.y * litV.z * LightColor; + half4 result = diffContrib + specContrib; + //half4 result = diffuse_color * litV.y + LightColor * litV.z; - pixelOut OUT; // output of the pixel shader - float3 Ln = normalize(IN.LightVec); - float3 Nn = normalize(IN.WorldNormal); - float3 Vn = normalize(IN.WorldView); - float3 Hn = normalize(Vn + Ln); - // scalar product between light and normal vectors: - float ldn = abs(dot(Ln,Nn)); - // scalar product between halfway and normal vectors: - float hdn = abs(dot(Hn,Nn)); - // specialized "lit" function computes weights for - // diffuse and specular parts: - float4 litV = lit(ldn,hdn,SpecExpon); - float4 diffContrib = glstate.material.diffuse * ( litV.y * LightColor + glstate.lightmodel.ambient); - float4 specContrib = litV.y*litV.z * LightColor; - // sum of diffuse and specular contributions: - float4 result = diffContrib + specContrib; OUT.col = result; - return OUT; // output of pixel shader + return OUT; }