Overte C++ Documentation
RenderableParticleEffectEntityItem.h
1 //
2 // RenderableParticleEffectEntityItem.h
3 // interface/src/entities
4 //
5 // Created by Jason Rickwald on 3/2/15.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_RenderableParticleEffectEntityItem_h
12 #define hifi_RenderableParticleEffectEntityItem_h
13 
14 #include "RenderableEntityItem.h"
15 #include <ParticleEffectEntityItem.h>
16 #include <TextureCache.h>
17 
18 namespace render { namespace entities {
19 
20 class ParticleEffectEntityRenderer : public TypedEntityRenderer<ParticleEffectEntityItem> {
21  using Parent = TypedEntityRenderer<ParticleEffectEntityItem>;
22  friend class EntityRenderer;
23 
24 public:
25  ParticleEffectEntityRenderer(const EntityItemPointer& entity);
26 
27 protected:
28  virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
29  virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override;
30 
31  bool isTransparent() const override;
32  virtual ShapeKey getShapeKey() override;
33  virtual Item::Bound getBound(RenderArgs* args) override;
34  virtual void doRender(RenderArgs* args) override;
35 
36 private:
37  using PipelinePointer = gpu::PipelinePointer;
38  using BufferPointer = gpu::BufferPointer;
39  using TexturePointer = gpu::TexturePointer;
40  using Format = gpu::Stream::Format;
41  using Buffer = gpu::Buffer;
42  using BufferView = gpu::BufferView;
43 
44  // CPU particles
45  // FIXME either switch to GPU compute particles or switch to simd updating of the particles
46  struct CpuParticle {
47  float seed { 0.0f };
48  uint64_t expiration { 0 };
49  float lifetime { 0.0f };
50  glm::vec3 basePosition;
51  glm::vec3 relativePosition;
52  glm::vec3 velocity;
53  glm::vec3 acceleration;
54 
55  void integrate(float deltaTime) {
56  glm::vec3 atSquared = (0.5f * deltaTime * deltaTime) * acceleration;
57  relativePosition += velocity * deltaTime + atSquared;
58  velocity += acceleration * deltaTime;
59  lifetime += deltaTime;
60  }
61  };
62  using CpuParticles = std::deque<CpuParticle>;
63 
64 
65  template<typename T>
66  struct InterpolationData {
67  T start;
68  T middle;
69  T finish;
70  T spread;
71  };
72 
73  struct ParticleUniforms {
74  InterpolationData<float> radius;
75  InterpolationData<glm::vec4> color; // rgba
76  InterpolationData<float> spin;
77  float lifespan;
78  int rotateWithEntity;
79  glm::vec2 spare;
80  };
81 
82  void computeTriangles(const hfm::Model& hfmModel);
83  bool _hasComputedTriangles{ false };
84  struct TriangleInfo {
85  std::vector<Triangle> triangles;
86  std::vector<size_t> samplesPerTriangle;
87  size_t totalSamples;
88  glm::mat4 transform;
89  } _triangleInfo;
90 
91  static CpuParticle createParticle(const Transform& baseTransform, const particle::Properties& particleProperties,
92  const ShapeType& shapeType, const GeometryResource::Pointer& geometryResource,
93  const TriangleInfo& triangleInfo);
94  void stepSimulation();
95 
96  particle::Properties _particleProperties;
97  bool _prevEmitterShouldTrail;
98  bool _prevEmitterShouldTrailInitialized { false };
99  CpuParticles _cpuParticles;
100  bool _emitting { false };
101  uint64_t _timeUntilNextEmit { 0 };
102  BufferPointer _particleBuffer { std::make_shared<Buffer>() };
103  BufferView _uniformBuffer;
104  quint64 _lastSimulated { 0 };
105 
106  PulsePropertyGroup _pulseProperties;
107  ShapeType _shapeType;
108  QString _compoundShapeURL;
109 
110  void fetchGeometryResource();
111  GeometryResource::Pointer _geometryResource;
112 
113  NetworkTexturePointer _networkTexture;
114  bool _textureLoaded { false };
115  ScenePointer _scene;
116 };
117 
118 } } // namespace
119 
120 #endif // hifi_RenderableParticleEffectEntityItem_h
The runtime model format.
Definition: HFM.h:302