particle_system.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2011-2025 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #ifndef PARTICLE_SYSTEM_H_HEADER_GUARD
  6. #define PARTICLE_SYSTEM_H_HEADER_GUARD
  7. #include <bx/allocator.h>
  8. #include <bx/bounds.h>
  9. #include <bx/easing.h>
  10. #include <bx/rng.h>
  11. struct EmitterHandle { uint16_t idx; };
  12. struct EmitterSpriteHandle { uint16_t idx; };
  13. template<typename Ty>
  14. inline bool isValid(Ty _handle)
  15. {
  16. return _handle.idx != UINT16_MAX;
  17. }
  18. struct EmitterShape
  19. {
  20. enum Enum
  21. {
  22. Sphere,
  23. Hemisphere,
  24. Circle,
  25. Disc,
  26. Rect,
  27. Count
  28. };
  29. };
  30. struct EmitterDirection
  31. {
  32. enum Enum
  33. {
  34. Up,
  35. Outward,
  36. Count
  37. };
  38. };
  39. struct EmitterUniforms
  40. {
  41. void reset();
  42. float m_position[3];
  43. float m_angle[3];
  44. float m_blendStart[2];
  45. float m_blendEnd[2];
  46. float m_offsetStart[2];
  47. float m_offsetEnd[2];
  48. float m_scaleStart[2];
  49. float m_scaleEnd[2];
  50. float m_lifeSpan[2];
  51. float m_gravityScale;
  52. uint32_t m_rgba[5];
  53. uint32_t m_particlesPerSecond;
  54. bx::Easing::Enum m_easePos;
  55. bx::Easing::Enum m_easeRgba;
  56. bx::Easing::Enum m_easeBlend;
  57. bx::Easing::Enum m_easeScale;
  58. EmitterSpriteHandle m_handle;
  59. };
  60. ///
  61. void psInit(uint16_t _maxEmitters = 64, bx::AllocatorI* _allocator = NULL);
  62. ///
  63. void psShutdown();
  64. ///
  65. EmitterSpriteHandle psCreateSprite(uint16_t _width, uint16_t _height, const void* _data);
  66. ///
  67. void psDestroy(EmitterSpriteHandle _handle);
  68. ///
  69. EmitterHandle psCreateEmitter(EmitterShape::Enum _shape, EmitterDirection::Enum _direction, uint32_t _maxParticles);
  70. ///
  71. void psUpdateEmitter(EmitterHandle _handle, const EmitterUniforms* _uniforms = NULL);
  72. ///
  73. void psGetAabb(EmitterHandle _handle, bx::Aabb& _outAabb);
  74. ///
  75. void psDestroyEmitter(EmitterHandle _handle);
  76. ///
  77. void psUpdate(float _dt);
  78. ///
  79. void psRender(uint8_t _view, const float* _mtxView, const bx::Vec3& _eye);
  80. #endif // PARTICLE_SYSTEM_H_HEADER_GUARD