Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330
  2.  
  3. out vec4 outColour;
  4.  
  5. in vec2 passTexCoord;
  6.  
  7. in vec3 passNormalDirection;    //Normal vector of vertex
  8. in vec3 passVectorToLight;      //Vector which is vertex position - light position
  9. in vec3 passLightDirection;     //Direction of the light source
  10. in float passDistanceToLight;   //Distance from vertex to light source
  11.  
  12. uniform sampler2D tex;
  13. const int MAX_DISTANCE = 25;
  14.  
  15. float getLight()
  16. {
  17.     vec3 nNormal        = normalize(passNormalDirection);
  18.     vec3 nVectorToLight = normalize(passVectorToLight);
  19.  
  20.     //"angle" between direction of object to light, and the light's direction
  21.     float angle = dot(passLightDirection, nVectorToLight);
  22.     if (angle < 0.7)
  23.     {
  24.         return 0.01f;
  25.     }
  26.  
  27.     //apply an attenuation factor
  28.     float dist = 1 - (passDistanceToLight / MAX_DISTANCE);
  29.  
  30.     //angle of surface normal and direction of object to light
  31.     float dir = dot(nNormal, nVectorToLight) * dist;
  32.  
  33.     //apply ambient light
  34.     float light = max(dir, 0.01);
  35.  
  36.     return light;
  37. }
  38.  
  39. void main()
  40. {
  41.     outColour = getLight() * texture(tex, passTexCoord);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement