hnOsmium0001

lighting fsh which doesn't work (4)

Dec 30th, 2019
830
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330 core
  2.  
  3. uniform vec3 viewPos;
  4. uniform vec3 lightPos;
  5. uniform float ambientStrength;
  6.  
  7. in vec3 fragPos;
  8. in vec3 interpolatedNormal;
  9.  
  10. out vec4 fragColor;
  11.  
  12. const float lightStrength = 0.1;
  13. const float specularStrength = 0.5;
  14. const float gamma = 2.2;
  15. const vec3 lightColor = vec3(1, 1, 1);
  16. const vec3 objectColor = vec3(137.0/255.0, 183.0/255.0, 255.0/255.0);
  17.  
  18. // Code adpated from learnopengl.com
  19. void main() {
  20.     vec3 ambient = ambientStrength * lightColor;
  21.  
  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.     vec3 viewDir = normalize(viewPos - fragPos);
  28.     vec3 reflectDir = reflect(-lightDir, norm);
  29.     float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
  30.     vec3 specular = specularStrength * spec * lightColor;
  31.  
  32.     vec3 color = (ambient + diffuse + specular) * objectColor;
  33.     vec3 corrected = pow(color, vec3(1.0 / gamma));
  34.     fragColor = vec4(corrected, 1.0);
  35. }
RAW Paste Data