hnOsmium0001

lighting fsh draft 3

Dec 30th, 2019
667
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330 core
  2.  
  3. uniform vec3 lightPos;
  4. uniform float ambientStrength;
  5.  
  6. in vec3 fragPos;
  7. in vec3 interpolatedNormal;
  8.  
  9. out vec4 fragColor;
  10.  
  11. const float lightStrength = 0.1;
  12. const float gamma = 2.2;
  13. const vec3 lightColor = vec3(1, 1, 1);
  14.  
  15. // Code adpated from opengl-tutorial.org
  16. void main() {
  17.     vec3 n = normalize(interpolatedNormal);
  18.     vec3 l = normalize(lightPos);
  19.  
  20.     // Cosine of the angle between the normal and the light direction,
  21.     // clamped above 0
  22.     //  - light is at the vertical of the triangle -> 1
  23.     //  - light is perpendicular to the triangle -> 0
  24.     //  - light is behind the triangle -> 0
  25.     float cosTheta = clamp(dot(n, l), 0, 1);
  26.     float distance = length(lightPos - fragPos);
  27.  
  28.     vec3 object = vec3(137.0/255.0, 183.0/255.0, 255.0/255.0);
  29.     vec3 light = lightStrength * lightColor;
  30.     vec3 ambient = ambientStrength * lightColor;
  31.  
  32.     vec3 color = object * (ambient + light) * cosTheta / (distance*distance);
  33.     vec3 corrected = pow(color, vec3(1.0 / gamma));
  34.     fragColor = vec4(corrected, 1.0);
  35. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×