Advertisement
Guest User

Untitled

a guest
Apr 10th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #version 330
  2.  
  3. // Matrices
  4. uniform mat4 matrixProjection;
  5. uniform mat4 matrixView;
  6. uniform mat4 matrixModelView;
  7. uniform mat4 matrixShadow;
  8.  
  9. // Materials
  10. uniform vec3 materialAmbient;
  11. uniform vec3 materialDiffuse;
  12. uniform float fogThickness;
  13.  
  14. layout (location = 0) in vec3 aVertex;
  15. layout (location = 2) in vec3 aNormal;
  16. layout (location = 3) in vec2 aTexCoord;
  17. layout (location = 4) in vec3 aTangent;
  18. layout (location = 5) in vec3 aBiTangent;
  19.  
  20. out vec4 color;
  21. out vec4 position;
  22. out vec3 normal;
  23. out float fogStrength;
  24. out vec2 texCoord0;
  25. out mat3 matrixTangent;
  26. out vec4 shadowCoord;
  27.  
  28.  
  29.  
  30. // ambient light declaration
  31. struct AMBIENT
  32. {
  33. int on;
  34. vec3 color;
  35. };
  36. uniform AMBIENT lightAmbient;
  37.  
  38.  
  39. // ambient light function
  40. vec4 AmbientLight(AMBIENT light)
  41. {
  42. return vec4(materialAmbient * light.color, 1);
  43. }
  44.  
  45.  
  46. void main(void)
  47. {
  48. // calculate position
  49. position = matrixModelView * vec4(aVertex, 1.0);
  50. //gl_Position = vec4(aVertex, 100.0);
  51. //gl_Position = vec4(vec2(aVertex.x, aVertex.y), 1.0, 50.0) - vec4(20.0, 50.0, 0.0, 0.0);
  52. gl_Position = matrixProjection * position;
  53.  
  54. // calculating color
  55. color = vec4 (0, 0, 0, 1);
  56.  
  57. // calculating normals
  58. normal = normalize(mat3(matrixModelView) * aNormal);
  59.  
  60. // calculating tangents for normal maps
  61. vec3 tangent = normalize(mat3(matrixModelView) * aTangent);
  62. vec3 biTangent = normalize(mat3(matrixModelView) * aBiTangent);
  63. matrixTangent = mat3(tangent, biTangent, normal);
  64.  
  65. // calculating fog
  66. fogStrength = exp2(-fogThickness * length(position));
  67.  
  68. // prepare texture vertexes to be sent to fragment shader
  69. texCoord0 = aTexCoord;
  70.  
  71. // calculate shadow coordinate – using the Shadow Matrix
  72. mat4 matrixModel = inverse(matrixView) * matrixModelView;
  73. shadowCoord = matrixShadow * matrixModel * vec4(aVertex + aNormal * 2.0, 1.0);
  74.  
  75. if (lightAmbient.on == 1) color += AmbientLight(lightAmbient);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement