27 const SLVec3f& velocityRandomStart,
28 const SLVec3f& velocityRandomEnd,
34 const bool doInstancedDrawing) :
SLMesh(assetMgr, name)
36 assert(!
name.empty());
47 SL_EXIT_MSG(
"SLParticleSystem supports max. 2^32 vertices.");
69 float x1 = randomXs.
x;
70 float x2 = randomXs.
y;
71 float x3 = randomXs.
z;
73 float mag = sqrt(x1 * x1 + x2 * x2 + x3 * x3);
80 return SLVec3f(x1 * c, x2 * c, x3 * c);
86 float x1 = randomXs.
x;
87 float x2 = randomXs.
y;
88 float x3 = randomXs.
z;
90 float mag = sqrt(x1 * x1 + x2 * x2 + x3 * x3);
95 float c = cbrt(radius);
97 return SLVec3f(x1 * c, x2 * c, x3 * c);
182 float r = radius * sqrt(
random(0.0f, 1.0f));
184 float x = r * cos(theta);
185 float z = r * sin(theta);
203 float x = r * cos(theta);
204 float z = r * sin(theta);
215 float percentX = position.
x / maxRadius;
217 float percentZ = position.
z / maxRadius;
251 float x = 0.0f, z = 0.0f;
284 float percentX = position.
x / maxRadius;
285 float percentZ = position.
z / maxRadius;
294 SLuint seed = (
SLuint)chrono::system_clock::now().time_since_epoch().count();
295 default_random_engine generator(seed);
296 normal_distribution<float> distribution(0.0f, 1.0f);
299 SLVfloat tempR, tempST, tempAngulareVelo;
339 tempAngulareVelo.resize(
_amount);
352 SLVec3f(distribution(generator),
353 distribution(generator),
354 distribution(generator)));
357 SLVec3f(distribution(generator),
358 distribution(generator),
359 distribution(generator)));
414 tempV[i] = tempDirection *
_speed;
421 tempInitV[i] = tempV[i];
431 tempInitP[i] = tempP[i];
621 float difTime = 0.0f;
711 spTF->
uniform1f(
"u_deltaTime", deltaTime);
836 std::cout <<
"vMat" << std::endl;
948 stateGL->
blendFunc(GL_SRC_ALPHA, GL_ONE);
959 GL_ONE_MINUS_SRC_ALPHA);
1025 minV +=
SLVec3f(-radius, -radius, -radius) * tempSpeed;
1026 maxV +=
SLVec3f(radius, radius, radius) * tempSpeed;
1087 if (minVTemp.
x > 0 && maxVTemp.
x > 0) minVTemp.
x = 0.0;
1088 if (minVTemp.
y > 0 && maxVTemp.
y > 0) minVTemp.
y = 0.0;
1089 if (minVTemp.
z > 0 && maxVTemp.
z > 0) minVTemp.
z = 0.0;
1091 if (minVTemp.
x < 0 && maxVTemp.
x < 0) maxVTemp.
x = 0.0;
1092 if (minVTemp.
y < 0 && maxVTemp.
y < 0) maxVTemp.
y = 0.0;
1093 if (minVTemp.
z < 0 && maxVTemp.
z < 0) maxVTemp.
z = 0.0;
1138 float timeForXGrav = 0.0f;
1139 float timeForYGrav = 0.0f;
1140 float timeForZGrav = 0.0f;
1146 if (timeForXGrav < 0.0f)
1148 else if (timeForXGrav > 0.0f)
1150 if (timeForYGrav < 0.0f)
1152 else if (timeForYGrav > 0.0f)
1154 if (timeForZGrav < 0.0f)
1156 else if (timeForZGrav > 0.0f)
1164 if (timeForXGrav < 0.0f)
1166 if (timeForYGrav < 0.0f)
1168 if (timeForZGrav < 0.0f)
1192 if (minVTemp.
x > 0 && maxVTemp.
x > 0) minVTemp.
x = 0.0;
1193 if (minVTemp.
y > 0 && maxVTemp.
y > 0) minVTemp.
y = 0.0;
1194 if (minVTemp.
z > 0 && maxVTemp.
z > 0) minVTemp.
z = 0.0;
1196 if (minVTemp.
x < 0 && maxVTemp.
x < 0) maxVTemp.
x = 0.0;
1197 if (minVTemp.
y < 0 && maxVTemp.
y < 0) maxVTemp.
y = 0.0;
1198 if (minVTemp.
z < 0 && maxVTemp.
z < 0) maxVTemp.
z = 0.0;
vector< SLfloat > SLVfloat
#define SL_EXIT_MSG(message)
#define SL_DB_MESHWIRED
Draw polygons as wired mesh.
@ AT_instancePosition
Vertex instance position for instanced particle drawing.
@ AT_angularVelo
Vertex angular velocity for rotation float.
@ AT_texNum
Vertex texture number int.
@ AT_custom0
Custom vertex attribute 0.
@ AT_position
Vertex position as a 2, 3 or 4 component vectors.
@ AT_rotation
Vertex rotation float.
@ AT_startTime
Vertex start time float.
@ AT_initialPosition
Vertex initial position 3 component vectors.
@ AT_velocity
Vertex velocity 3 component vectors.
@ AT_initialVelocity
Vertex initial velocity 3 component vectors.
vector< SLVec3f > SLVVec3f
SLVec3< SLfloat > SLVec3f
Defines an axis aligned bounding box.
void fromOStoWS(const SLVec3f &minOS, const SLVec3f &maxOS, const SLMat4f &wm)
Recalculate min and max after transformation in world coords.
Toplevel holder of the assets meshes, materials, textures and shaders.
SLbool get(SLuint bit)
Returns the specified bit.
Encapsulation of an OpenGL shader program object.
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint uniform4f(const SLchar *name, SLfloat v0, SLfloat v1, SLfloat v2, SLfloat v3) const
Passes the float values v0,v1,v2 & v3 to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
SLint uniform1fv(const SLchar *name, SLsizei count, const SLfloat *value) const
Passes 1 float value py pointer to the uniform variable "name".
SLint uniform3f(const SLchar *name, SLfloat v0, SLfloat v1, SLfloat v2) const
Passes the float values v0, v1 & v2 to the uniform variable "name".
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Singleton class holding all OpenGL states.
SLMat4f modelMatrix
Init all states.
static SLGLState * instance()
Public static instance getter for singleton pattern.
SLMat4f viewMatrix
matrix for the active cameras view transform
void blendFunc(SLenum blendFuncSFactor, SLenum blendFuncDFactor)
Sets new blend function source and destination factors.
SLbool glHasGeometryShaders() const
Texture object for OpenGL texturing.
void beginTF(SLuint tfoID)
Begin transform feedback.
void setInstanceVBO(SLGLVertexBuffer *vbo, SLuint divisor=0)
Attach a VBO that has been created outside of this VAO.
void endTF()
End transform feedback.
SLuint tfoID() const
Returns the TFO id.
void setAttrib(SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
Adds a vertex attribute with data pointer and an element size.
void generateTF(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB & TF objects.
void drawArrayAs(SLGLPrimitiveType primitiveType, SLint firstVertex=0, SLsizei countVertices=0)
Draws the VAO as an array with a primitive type.
void setIndices(SLuint numIndicesElements, SLGLBufferType indexDataType, void *indexDataElements, SLuint numIndicesEdges=0, void *indexDataEdges=nullptr)
Adds the index array for indexed element drawing.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB objects for a NO. of vertices.
void deleteGL()
Deletes all vertex array & vertex buffer objects.
Defines a standard CG material with textures and a shader program.
void programTF(SLGLProgram *sp)
void removeTextureType(SLTextureType tt)
void generateProgramPS(bool drawInstanced=false)
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
void program(SLGLProgram *sp)
An SLMesh object is a triangulated mesh, drawn with one draw call.
SLVec3f maxP
max. vertex in OS
SLVuint I32
Vector of vertex indices 32 bit.
virtual void draw(SLSceneView *sv, SLNode *node, SLuint intances=0)
virtual void deleteDataGpu()
SLGLPrimitiveType _primitive
Primitive type (default triangles)
SLVec3f minP
min. vertex in OS
SLGLVertexArray _vao
Main OpenGL Vertex Array Object for drawing.
SLVVec3f P
Vector for vertex positions layout (location = 0)
SLMaterial * _mat
Pointer to the inside material.
SLNode represents a node in a hierarchical scene graph.
SLVec3f translationWS() const
const SLstring & name() const
void generateBernsteinPSize()
SLbool _isPaused
Boolean to stop updating.
SLfloat _shapeAngle
Angle of cone and pyramid shapes.
SLbool _doWorldSpace
Boolean for world space position.
SLint _velocityType
Velocity type.
SLbool _doAcceleration
Boolean for acceleration.
SLVec2f _speedRange
Speed random between two value.
void generate()
Function which will generate the particles and attributes them to the VAO.
SLVec3f getDirectionCone(SLVec3f position)
Function which return a direction following the cone shape.
void buildAABB(SLAABBox &aabb, const SLMat4f &wmNode)
SLVec3f _emitterPos
Position of the particle emitter.
SLGLTexture * _texFlipbook
Flipbook texture with e.g. multiple flames at subsequent frames.
int _flipbookFPS
Number of update of flipbook by second.
SLbool _isGenerated
Boolean to generate particle system and load it on the GPU.
AvgFloat _drawTime
Averaged time for drawing in MS.
SLfloat _lastTimeBeforePauseS
Time since the particle system is paused.
SLGLTexture * texFlipbook()
SLfloat _notVisibleTimeS
Time since start when node not visible in S.
SLbool _doShapeSurface
Boolean for shape surface (particle will be spawned on surface)
SLVec2f _angularVelocityRange
Rotation rate range (change in angular rotation divide by change in time)
SLfloat _timeToLive
Time to live of a particle.
SLbool _doSpeedRange
Boolean for speed range.
SLbool _doInstancedDrawing
Boolean for instanced rendering.
SLVec3f getDirectionBox(SLVec3f position)
Function which return the direction towards the exterior of a box.
SLbool _doGravity
Boolean for gravity.
SLfloat _scale
Scale of a particle (Scale the radius)
SLVec3f getPointInSphere(float radius, SLVec3f randomX)
Function which return a position in a sphere.
SLint _amount
Amount of a particle.
SLGLVertexArray _instanceVao2
float _bezierStartEndPointSize[4]
Floats for bezier curve end start points (Start: 01 ; End: 23)
SLfloat _deltaTimeUpdateS
Delta time in between two frames S.
SLVec3f getPointOnCone()
Function which return a position on the cone define in the particle system.
SLTexColorLUT * texGradient()
SLVec3f emitterPos() const
SLfloat _radiusW
width radius of a particle
SLVec4f _bernsteinPYAlpha
Vector for bezier curve (default linear function)
SLbool _doRotation
Boolean for rotation.
SLBillboardType _billboardType
Billboard type (BT_Camera, BT_Vertical, BT_Horizontal.
SLbool _doDirectionSpeed
Boolean for direction and speed (override velocity)
SLfloat _angularVelocityConst
Rotation rate const (change in angular rotation divide by change in time)
SLGLVertexArray _instanceVao1
SLbool _doRotRange
Boolean for rotation range (random value between range)
SLbool _isVisibleInFrustum
Boolean to set time since node not visible.
SLfloat _shapeRadius
Radius of sphere and cone shape.
int _drawBuf
Boolean to switch buffer.
SLfloat _accelerationConst
Acceleration constant (same direction as the velocity)
float _bezierStartEndPointAlpha[4]
Floats for bezier curve end start points (Start: 01 ; End: 23)
SLVec3f getDirectionSphere(SLVec3f position)
Function which return the direction towards the exterior of a sphere.
SLVec3f getPointOnSphere(float radius, SLVec3f randomX)
Function which return a position on a sphere.
SLbool _doColorOverLT
Boolean for color over life time.
SLfloat _shapeWidth
Width of pyramid shape.
void setNotVisibleInFrustum()
SLVec3f getPointInCone()
Function which return a position in the cone define in the particle system.
float _bezierControlPointSize[4]
Floats for bezier curve control points (P1: 01 ; P2: 23)
SLfloat _startUpdateTimeS
Time since start for updating in S.
SLfloat _startUpdateTimeMS
Time since start for updating in MS.
SLbool _doFlipBookTexture
Boolean for flipbook texture.
SLVec4f _bernsteinPYSize
Vector for bezier curve (default linear function)
SLVec3f _direction
Direction of particle.
SLCol4f _color
Color for particle.
SLbool _doShapeOverride
Boolean for override direction for shape direction.
SLVec3f _velocityConst
Velocity constant (go in xyz direction)
AvgFloat _updateTime
Averaged time for updating in MS.
SLParticleSystem(SLAssetManager *assetMgr, const SLint amount, const SLVec3f &velocityRandomStart, const SLVec3f &velocityRandomEnd, const SLfloat &timeToLive, SLGLTexture *texC, const SLstring &name="Particle System", SLGLTexture *texFlipbook=nullptr, SLTexColorLUT *texGradient=nullptr, const bool doInstancedDrawing=false)
SLParticleSystem ctor with some initial values. The number of particles.
SLGLTexture * _texParticle
Main texture of PS (non flipbook)
SLbool _doAccDiffDir
Boolean for acceleration (different direction)
SLVec3f getPointInPyramid()
Function which returns a position in the pyramid that define the PS.
SLint _flipbookColumns
Number of flipbook sub-textures by column.
SLbool _doAlphaOverLTCurve
Boolean for alpha over life time curve.
SLfloat _startDrawTimeMS
Time since start of draw in MS.
float _flipboookLastUpdate
Last time flipbook was updated.
SLint _flipbookRows
Number of flipbook sub-textures by row.
SLbool _doShape
Boolean for shape feature.
SLbool _doBlendBrightness
Boolean for glow/brightness on pixel with many particle.
float _bezierControlPointAlpha[4]
Floats for bezier curve control points (P1: 01 ; P2: 23)
SLfloat _shapeHeight
Height of cone and pyramid shapes.
SLVec3f _gravity
Vector for gravity (2nd. acceleration vector)
SLfloat _radiusH
height radius of a particle
SLbool _doShapeSpawnBase
Boolean for spawn at base of shape (for cone and pyramid)
SLVec3f _shapeScale
Scale of box shape.
SLVec3f getDirectionPyramid(SLVec3f position)
Function which return a direction following the pyramid shape.
SLVec3f getPointOnBox(SLVec3f boxScale)
Function which return a position on a box.
SLVec3f _velocityRndMax
Max. random velocity.
SLTexColorLUT * _texGradient
Color gradient texture.
void draw(SLSceneView *sv, SLNode *node, SLuint instances=1)
SLbool _doSizeOverLTCurve
Boolean for size over life time curve.
void generateBernsteinPAlpha()
SLVec3f _acceleration
Vector for acceleration (different direction as the velocity)
SLbool doInstancedDrawing()
SLVec3f getPointInBox(SLVec3f boxScale)
Function which return a position in a box.
SLShapeType _shapeType
Shape type (ST_)
SLAssetManager * _assetManager
pointer to the asset manager (the owner) if available
SLbool _doColor
Boolean for color.
SLVec3f getPointOnPyramid()
Function which return a position on the pyramid that defines the PS.
SLfloat _speed
Speed of particle.
SLVec3f _velocityRndMin
Min. random velocity.
SceneView class represents a dynamic real time 3D view onto the scene.
SLTexColorLUT defines a lookup table as an 1D texture of (256) RGBA values.
SLVCol3f allColors()
Returns all alpha values of the transfer function as a float vector.
SLVec3 normalized() const
void init(int numValues, T initValue)
Initializes the average value array to a given value.
void set(T value)
Sets the current value in the value array and builds the average.
static const float DEG2RAD
float random(float min, float max)
Returns a uniform distributed random float number between min and max.