Advertisement
Lynix

Nazara: Point-Lighting fragment shader

Jan 29th, 2013
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. vec3 lightDir = LightPosition - vWorldPos;
  2.  
  3. float att = max(LightAttenuation - LightInvRadius*length(lightDir), 0.0);
  4. light += att * LightAmbient * (MaterialAmbient + SceneAmbient);
  5.  
  6. lightDir = normalize(lightDir);
  7. float lambert = max(dot(normal, lightDir), 0.0);
  8. light += att * lambert * LightDiffuse * MaterialDiffuse;
  9.  
  10. if (MaterialShininess > 0.0)
  11. {
  12.     vec3 reflection = reflect(-lightDir, normal);
  13.     vec3 eyeVec = normalize(CameraPosition - vWorldPos);
  14.  
  15.     float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
  16.  
  17.     light += att * specular * LightSpecular * MaterialSpecular;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement