Guest User

Untitled

a guest
Nov 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #version 430
  2.  
  3. in vec2 pass_textureCoords;
  4. in vec3 surfaceNormal;
  5. in vec3 toLightVector[5];
  6. in vec3 toCameraVector;
  7. in float visibility;
  8.  
  9. out vec4 out_Color;
  10.  
  11. uniform sampler2D textureSampler;
  12. uniform vec3 lightColour[5];
  13. uniform vec3 attenuation[5];
  14. uniform float shineDamper;
  15. uniform float reflectivity;
  16. uniform vec3 skyColour;
  17.  
  18. void main(void) {
  19.  
  20. vec3 unitNormal = normalize(surfaceNormal);
  21. vec3 unitVectorToCamera = normalize(toCameraVector);
  22.  
  23. vec3 totalDiffuse = vec3(0.0);
  24. vec3 totalSpecular = vec3(0.0);
  25.  
  26. for (int i = 0; i < 5; i++) {
  27. float distance = length(toLightVector[i]);
  28. float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance);
  29. vec3 unitLightVector = normalize(toLightVector[i]);
  30. float nDot1 = dot(unitNormal, unitLightVector);
  31. float brightness = max(nDot1, 0.0);
  32. vec3 lightDirection = -unitLightVector;
  33. vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
  34. float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
  35. specularFactor = max(specularFactor, 0.0);
  36. float dampedFactor = pow(specularFactor, shineDamper);
  37. totalDiffuse = totalDiffuse + (brightness * lightColour[i])/attFactor;
  38. totalSpecular = totalSpecular + (dampedFactor * reflectivity * lightColour[i])/attFactor;
  39. }
  40. totalDiffuse = max(totalDiffuse, 0.2);
  41.  
  42.  
  43. ////////////////////////////////////////////////////////////////////////////
  44. vec4 textureColour = texture(textureSampler, pass_textureCoords);
  45. if (textureColour.a < 0.5) {
  46. discard;
  47. }
  48. ////////////////////////////////////////////////////////////////////////////
  49.  
  50. out_Color = vec4(totalDiffuse, 1.0) * textureColour + vec4(totalSpecular, 1.0);
  51. out_Color = mix(vec4(skyColour,1.0),out_Color, visibility);
  52.  
  53. }
Add Comment
Please, Sign In to add comment