instanced_grass.vert 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. uniform vec3 windDir;
  2. #if __VERSION__ >= 330
  3. layout(location = 0) in vec3 Position;
  4. layout(location = 1) in vec3 Normal;
  5. layout(location = 2) in vec4 Color;
  6. layout(location = 3) in vec2 Texcoord;
  7. layout(location = 7) in vec3 Origin;
  8. layout(location = 8) in vec3 Orientation;
  9. layout(location = 9) in vec3 Scale;
  10. #ifdef Use_Bindless_Texture
  11. layout(location = 10) in sampler2D Handle;
  12. layout(location = 11) in sampler2D SecondHandle;
  13. #endif
  14. #else
  15. in vec3 Position;
  16. in vec3 Normal;
  17. in vec4 Color;
  18. in vec2 Texcoord;
  19. in vec3 Origin;
  20. in vec3 Orientation;
  21. in vec3 Scale;
  22. #endif
  23. out vec3 nor;
  24. out vec2 uv;
  25. #ifdef Use_Bindless_Texture
  26. flat out sampler2D handle;
  27. flat out sampler2D secondhandle;
  28. #endif
  29. mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
  30. mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
  31. void main()
  32. {
  33. mat4 ModelMatrix = getWorldMatrix(Origin + windDir * Color.r, Orientation, Scale);
  34. mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + windDir * Color.r, Orientation, Scale) * InverseViewMatrix);
  35. gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.);
  36. nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
  37. uv = Texcoord;
  38. #ifdef Use_Bindless_Texture
  39. handle = Handle;
  40. secondhandle = SecondHandle;
  41. #endif
  42. }