hnOsmium0001

lighting * 2

Dec 30th, 2019
842
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330 core
  2.  
  3. uniform vec3 lightPos;
  4.  
  5. in vec3 fragPos;
  6. in vec3 interpolatedNormal;
  7.  
  8. out vec4 fragColor;
  9.  
  10. const float ambientStrength = 0.1;
  11. const float lightStrength = 0.5;
  12. const float gamma = 2.2;
  13. const vec3 objectColor = vec3(137.0/255.0, 183.0/255.0, 255.0/255.0);
  14. const vec3 lightColor = vec3(1, 1, 1);
  15.  
  16. // Code adpated from opengl-tutorial.org and learnopengl.com
  17. void main() {
  18.     // Calculation for ambient lighting
  19.     vec3 ambient = ambientStrength * lightColor;
  20.  
  21.     // Calcuation for diffuse lighting
  22.     vec3 norm = normalize(interpolatedNormal);
  23.     vec3 lightDir = normalize(lightPos - fragPos);
  24.     float diff = max(dot(norm, lightDir), 0.0);
  25.     vec3 diffuse = diff * lightColor;
  26.  
  27.     float distance = length(fragPos - lightPos);
  28.  
  29.     vec3 color = (ambient + diffuse) * objectColor / (distance*distance);
  30.     vec3 corrected = pow(color, vec3(1.0 / gamma));
  31.     fragColor = vec4(corrected, 1.0);
  32. }
RAW Paste Data