Brenta Engine 1.2
Loading...
Searching...
No Matches
particle_update_vs.c
1static const char* particle_update_vs = "#version 330 core\n"
2"\n"
3"layout (location = 0) in vec3 inPosition; // current particle position\n"
4"layout (location = 1) in vec3 inVelocity; // current particle velocity\n"
5"layout (location = 2) in float inTTL; // current particle life\n"
6"\n"
7"out vec3 outPosition;\n"
8"out vec3 outVelocity;\n"
9"out float outTTL;\n"
10"\n"
11"layout (std140) uniform settings\n"
12"{\n"
13" vec3 gravity;\n"
14" float deltaTime;\n"
15" vec3 emitterVel;\n"
16" float emitterTTL;\n"
17" vec3 emitterPos;\n"
18" float spawnProbability;\n"
19" vec3 emitterSpread;\n"
20"};\n"
21"\n"
22"// Random number generator between [-1, 1]\n"
23"float rand(vec2 co);\n"
24"\n"
25"void main()\n"
26"{\n"
27" float random = rand(vec2(deltaTime * float(gl_VertexID)));\n"
28" if (random > spawnProbability)\n"
29" {\n"
30" // New particle\n"
31" outPosition = emitterPos;\n"
32" outVelocity = emitterVel + emitterSpread *\n"
33" vec3(rand(vec2(float(gl_VertexID + 1.0))) -0.5,\n"
34" rand(vec2(float(gl_VertexID + 2.0))) -0.5,\n"
35" rand(vec2(float(gl_VertexID + 3.0))) -0.5);\n"
36" outTTL = emitterTTL;\n"
37" return;\n"
38" }\n"
39"\n"
40" if (inTTL <= 0.0)\n"
41" {\n"
42" // Delete particle\n"
43" outPosition = inPosition;\n"
44" outVelocity = vec3(0.0);\n"
45" outTTL = -1.0;\n"
46" return;\n"
47" }\n"
48"\n"
49" // Update particle\n"
50" outTTL = inTTL - deltaTime;\n"
51"\n"
52" vec3 processed_velocity = inVelocity;\n"
53" float delta = 0.0;\n"
54"\n"
55" vec3 newVelocity = processed_velocity + gravity * deltaTime;\n"
56" vec3 newPosition = inPosition + newVelocity * deltaTime;\n"
57" \n"
58" outVelocity = newVelocity;\n"
59" outPosition = newPosition;\n"
60"}\n"
61" \n"
62"float rand(vec2 co)\n"
63"{\n"
64" return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);\n"
65"}\n"
66;