d46cb9729b
This change adds another layer of complexity and control to the particle system. There are now two code chunks: the old code that's run per-particle, and new code that's run for the effect itself. This allows for effect lifetime to be set by the script (eg, randomly), as well as the emission rate. Rate can vary over time (see pulse.json), and particles can be emitted in bursts by setting the effect's burst field (see fireworks.json). Additionally, the effect has its own frame of reference and color, which becomes the default state for newly emitted particles. This allows synchronizing state across particles in various interesting ways (see color in fireworks.json). Change-Id: Iec2f7a3427ce1d6411ed7ef5b3023cbef2e8a134 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/240498 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
35 lines
856 B
JSON
35 lines
856 B
JSON
{
|
|
"MaxCount": 6000,
|
|
"Drawable": {
|
|
"Type": "SkCircleDrawable",
|
|
"Radius": 2
|
|
},
|
|
"EffectCode": [
|
|
"void effectSpawn(inout Effect effect) {",
|
|
" effect.rate = 2000;",
|
|
"}",
|
|
"",
|
|
"void effectUpdate(inout Effect effect) {",
|
|
" effect.pos.y = sin(effect.age * 6.28) * 40;",
|
|
"}",
|
|
""
|
|
],
|
|
"Code": [
|
|
"void spawn(inout Particle p) {",
|
|
" p.lifetime = 2 + (rand * 2);",
|
|
" p.vel.x = (30 * rand) + 50;",
|
|
" p.vel.y = (20 * rand) - 10;",
|
|
"}",
|
|
"",
|
|
"void update(inout Particle p) {",
|
|
" p.color.r = p.age;",
|
|
" p.color.g = 1 - p.age;",
|
|
" float s1 = 0.5 + (1.5 * p.age);",
|
|
" float s2 = 1.0 + (-0.75 * p.age);",
|
|
" p.scale = s1 + (s2 - s1) * rand;",
|
|
" p.vel.y += 20.0 * dt;",
|
|
"}",
|
|
""
|
|
],
|
|
"Bindings": []
|
|
} |