TriangleVertexShader.vert 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #version 450
  2. #include "VertexConstants.h"
  3. layout(location = 0) in vec3 vPos;
  4. layout(location = 1) in vec3 vNorm;
  5. layout(location = 2) in vec2 vTex;
  6. layout(location = 3) in vec4 vCol;
  7. layout(location = 4) in mat4 iModel;
  8. layout(location = 8) in mat4 iModelInvTrans;
  9. layout(location = 12) in vec4 iCol;
  10. layout(location = 0) out vec3 oNormal;
  11. layout(location = 1) out vec3 oWorldPos;
  12. layout(location = 2) out vec2 oTex;
  13. layout(location = 3) out vec4 oPositionL;
  14. layout(location = 4) out vec4 oColor;
  15. void main()
  16. {
  17. // Get world position
  18. vec4 pos = vec4(vPos, 1.0f);
  19. vec4 world_pos = iModel * pos;
  20. // Transform the position from world space to homogeneous projection space
  21. vec4 proj_pos = c.View * world_pos;
  22. proj_pos = c.Projection * proj_pos;
  23. gl_Position = proj_pos;
  24. // Transform the position from world space to projection space of the light
  25. vec4 proj_lpos = c.LightView * world_pos;
  26. proj_lpos = c.LightProjection * proj_lpos;
  27. oPositionL = proj_lpos;
  28. // output normal
  29. vec4 norm = vec4(vNorm, 0.0f);
  30. oNormal = normalize(iModelInvTrans * norm).xyz;
  31. // output world position of the vertex
  32. oWorldPos = world_pos.xyz;
  33. // output texture coordinates
  34. oTex = vTex;
  35. // output color
  36. oColor = vCol * iCol;
  37. }