hnOsmium0001

some lighting experiement - ice sculptures

Dec 30th, 2019
869
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 modelPos;
  6. in vec3 faceNormal;
  7.  
  8. // Code adpated from opengl-tutorial.org
  9. void main() {
  10.     vec3 n = normalize(faceNormal);
  11.     vec3 l = normalize(lightPos);
  12.  
  13.     // Cosine of the angle between the normal and the light direction,
  14.     // clamped above 0
  15.     //  - light is at the vertical of the triangle -> 1
  16.     //  - light is perpendicular to the triangle -> 0
  17.     //  - light is behind the triangle -> 0
  18.     float cosTheta = clamp(dot(n, l), 0, 1);
  19.     float distance = abs(modelPos - lightPos);
  20.  
  21.     vec3 diffuseColor = vec3(137/255, 183/255, 255/255);
  22.     vec3 lightColor = vec3(1,1,1);
  23.     float lightPower = 60;
  24.     vec3 color = diffuseColor * lightColor * lightPower * cosTheta / (distance*distance);
  25.     gl_FragColor = color;
  26.  
  27.     //float lv = dot(normal, lightPos);
  28.     //float corrected = pow(lv, 1.0 / 2.2);
  29.     //gl_FragColor = vec4(137.0 / 255.0, 183.0 / 255.0, 1.0, 1.0);
  30.     //gl_FragColor = vec4(corrected, corrected, corrected, 1.0);
  31. }
RAW Paste Data