float4x4 view_proj_matrix; float4 Light_Ambient; float4 Light1_Position; float4 Light1_Attenuation; float4 Light1_Color; float4 view_position; float4x4 inv_view_matrix; float4x4 view_matrix; float4 rflxColor; struct VS_OUTPUT { float4 Pos: POSITION; float2 TexCoord: TEXCOORD0; float4 Color: COLOR0; }; float4 Light_Point( float3 VertPos, float3 VertNorm, float3 LightPos, float4 LightColor, float3 EyeDir) { // This stuff happens per vertex, so, we want a LightColor as result // Determine the distance from the light to the vertex and the direction float3 LightDir = LightPos - (VertPos); float Dist = length(LightDir); float3 LightV = LightDir / Dist; // Compute half vector float3 HalfVect = normalize(LightV-EyeDir); // Specular float SpecularAttn = pow( clamp(0,1, dot(VertNorm, HalfVect)),128); //==============================================================================// // Special Reflectivity float4 rflxBRDF = pow(max(0, dot(LightV,HalfVect+0.03)), dot(32,LightV) ); // here we can clamp the effect, so we see color rflxBRDF = clamp(rflxBRDF,0,5.5); // filter the inner material color rflxBRDF *= rflxColor; //==============================================================================// // Diffuse float AngleAttn = clamp(0,1, dot(VertNorm, LightV) ); // Compute final lighting return LightColor * (SpecularAttn+AngleAttn+(rflxBRDF)); } VS_OUTPUT vs_main( float4 inPos: POSITION, float3 inNormal: NORMAL, float2 inTxr: TEXCOORD0) { VS_OUTPUT Out; // Compute the position and send out the texture coordinates Out.Pos = mul(view_proj_matrix, inPos); Out.TexCoord = inTxr; // Determine the eye vector float3 EyeVector = -normalize(mul(inv_view_matrix,vector(0,0,10,1))+inPos); // Compute light contribution float4 Color = Light_Point(inPos, // vert position (P) inNormal, // vert normal (N) Light1_Position, // light position (lP1) Light1_Color, // light color (lC1) EyeVector); // eye vector (I) // clamp the color to prevent lightwrapping, add ambient Color = clamp(Color,0,1) + Light_Ambient; // Output Final Color Out.Color = Color; return Out; }