LensFlareSprite.ankiprog 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!--
  2. Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
  3. All rights reserved.
  4. Code licensed under the BSD License.
  5. http://www.anki3d.org/LICENSE
  6. -->
  7. <shaderProgram>
  8. <shaders>
  9. <shader type="vert">
  10. <inputs>
  11. <input name="MAX_SPRITES" type="uint" const="1"/>
  12. </inputs>
  13. <source><![CDATA[
  14. #include "shaders/Common.glsl"
  15. // Per flare information
  16. struct Sprite
  17. {
  18. vec4 posScale; // xy: Position, zw: Scale
  19. vec4 color;
  20. vec4 depthPad3;
  21. };
  22. // The block contains data for all flares
  23. layout(std140, ANKI_UBO_BINDING(0, 0)) uniform _blk
  24. {
  25. Sprite u_sprites[MAX_SPRITES];
  26. };
  27. layout(location = 0) out vec3 out_uv;
  28. layout(location = 1) flat out vec4 out_color;
  29. out gl_PerVertex
  30. {
  31. vec4 gl_Position;
  32. };
  33. void main()
  34. {
  35. vec2 position = UV_TO_NDC(vec2(gl_VertexID & 1, gl_VertexID >> 1));
  36. Sprite sprite = u_sprites[gl_InstanceID];
  37. // Write tex coords of the 2D array texture
  38. out_uv = vec3((position * 0.5) + 0.5, sprite.depthPad3.x);
  39. vec4 posScale = sprite.posScale;
  40. gl_Position = vec4(position * posScale.zw + posScale.xy, 0.0, 1.0);
  41. out_color = sprite.color;
  42. }
  43. ]]></source>
  44. </shader>
  45. <shader type="frag">
  46. <source><![CDATA[
  47. #include "shaders/Common.glsl"
  48. layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2DArray u_tex;
  49. layout(location = 0) in vec3 in_uv;
  50. layout(location = 1) flat in vec4 in_color;
  51. layout(location = 0) out vec4 out_color;
  52. void main()
  53. {
  54. vec4 col = texture(u_tex, in_uv);
  55. out_color = col * in_color;
  56. }
  57. ]]></source>
  58. </shader>
  59. </shaders>
  60. </shaderProgram>