LfSpritePass.vert.glsl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // LF sprites vert shader
  6. #include "shaders/Common.glsl"
  7. // Per flare information
  8. struct Sprite
  9. {
  10. vec4 posScale; // xy: Position, zw: Scale
  11. vec4 color;
  12. vec4 depthPad3;
  13. };
  14. // WORKAROUND: See glslang issue 304
  15. #define COPY_SPRITE(src_, dst_) \
  16. dst_.posScale = src_.posScale; \
  17. dst_.color = src_.color; \
  18. dst_.depthPad3.x = src_.depthPad3.x
  19. // The block contains data for all flares
  20. layout(std140, ANKI_UBO_BINDING(0, 0)) uniform _blk
  21. {
  22. Sprite u_sprites[MAX_SPRITES];
  23. };
  24. layout(location = 0) out vec3 out_uv;
  25. layout(location = 1) flat out vec4 out_color;
  26. out gl_PerVertex
  27. {
  28. vec4 gl_Position;
  29. };
  30. void main()
  31. {
  32. const vec2 POSITIONS[4] = vec2[](vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0), vec2(1.0, 1.0));
  33. vec2 position = POSITIONS[gl_VertexID];
  34. Sprite sprite;
  35. COPY_SPRITE(u_sprites[gl_InstanceID], sprite);
  36. // Write tex coords of the 2D array texture
  37. out_uv = vec3((position * 0.5) + 0.5, sprite.depthPad3.x);
  38. vec4 posScale = sprite.posScale;
  39. gl_Position = vec4(position * posScale.zw + posScale.xy, 0.0, 1.0);
  40. out_color = sprite.color;
  41. }