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>
41 lines
890 B
JSON
41 lines
890 B
JSON
{
|
|
"MaxCount": 32,
|
|
"Drawable": {
|
|
"Type": "SkImageDrawable",
|
|
"Path": "resources/images/explosion_sprites.png",
|
|
"Columns": 4,
|
|
"Rows": 4
|
|
},
|
|
"EffectCode": [
|
|
"void effectSpawn(inout Effect effect) {",
|
|
" effect.rate = 8;",
|
|
"}",
|
|
"",
|
|
"void effectUpdate(inout Effect effect) {",
|
|
"}",
|
|
""
|
|
],
|
|
"Code": [
|
|
"float2 circle() {",
|
|
" float x;",
|
|
" float y;",
|
|
" do {",
|
|
" x = rand * 2 - 1;",
|
|
" y = rand * 2 - 1;",
|
|
" } while (x*x + y*y > 1);",
|
|
" return float2(x, y);",
|
|
"}",
|
|
"",
|
|
"void spawn(inout Particle p) {",
|
|
" p.lifetime = 1.0 + rand * 2.0;",
|
|
" p.pos = circle() * 60;",
|
|
" p.vel = p.pos / 3;",
|
|
"}",
|
|
"",
|
|
"void update(inout Particle p) {",
|
|
" p.frame = p.age;",
|
|
"}",
|
|
""
|
|
],
|
|
"Bindings": []
|
|
} |