Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. //gouraudShader.vert
  2. #version 330
  3.  
  4. struct lightStruct{
  5. vec4 ambient;
  6. vec4 diffuse;
  7. vec4 specular;
  8. vec4 position;
  9. };
  10.  
  11. struct materialStruct{
  12. vec4 ambient;
  13. vec4 diffuse;
  14. vec4 specular;
  15. float shininess;
  16. };
  17.  
  18. uniform mat4 projection;
  19. uniform mat4 modelView;
  20. uniform lightStruct light;
  21. uniform materialStruct material;
  22.  
  23. uniform float attConst;
  24. uniform float attLinear;
  25. uniform float attQuadratic;
  26. uniform bool addAttenuation;
  27.  
  28. in vec3 in_Pos;
  29. in vec3 in_Normal;
  30.  
  31. in vec2 in_TexCoord;
  32. out vec2 ex_TexCoord;
  33.  
  34. out vec4 ex_Color;
  35.  
  36. void main (void){
  37. vec4 vertexPosition = modelView * vec4(in_Pos, 1.0);
  38. gl_Position = projection * vertexPosition;
  39.  
  40. vec3 V = normalize(-vertexPosition.xyz);
  41.  
  42. mat3 normalMatrix = transpose(inverse(mat3(modelView)));
  43. vec3 screenNormal = normalize(normalMatrix * in_Normal);
  44.  
  45. vec4 ambientI = light.ambient * material.ambient;
  46.  
  47. vec3 L = normalize(light.position.xyz - vertexPosition.xyz);
  48.  
  49. vec4 diffuseI = light.diffuse * material.diffuse * max(dot(screenNormal, L),0);
  50.  
  51. vec3 R = normalize(-reflect(L, screenNormal));
  52. vec4 specularI = light.specular * material.specular;
  53.  
  54. specularI = specularI * pow(max(dot(R, V), 0), material.shininess);
  55.  
  56. if (addAttenuation) {
  57. float D = distance(vertexPosition,light.position);
  58. float attenuation = (1/(attConst + attLinear*D + attQuadratic*D*D));
  59. ex_Color = (ambientI + vec4((diffuseI.rgb + specularI.rgb)/attenuation,1.0));
  60. } else
  61. ex_Color = ambientI + diffuseI + specularI;
  62.  
  63. ex_TexCoord = in_TexCoord;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement