skia2/resources/particles/fireworks2.json
Brian Osman 9a8b846baf Particles: Sub-effect spawning and some slight refactoring
* Added a new binding type, SkEffectBinding. This stores another
  entire effect params structure (so the JSON is just nested).
  The name is a callable value that spawns a new instance of
  that effect, inheriting the parameters of the spawning effect
  or particle (depending on which kind of script made the call).
* Broke up the monolithic update function into some helpers,
  got some code reuse with the script calling logic.
* Unlike particle capacity, there is no upper limit on child
  effects (yet), so it's easy to trigger runaway memory and
  CPU consumption. Be careful.
* Added death scripts to effects and particles, which are a
  common place to want to spawn sub-effects. Like spawn,
  these run on each loop, but for one-shots they play at the
  end. Even with loops, this is helpful for timing sub-effects
  (see fireworks2.json).
* Finally, added a much more comprehensive example effect,
  raincloud.json. This includes a total of three effects, to
  generate a cloud, raindrops, and splashes when those drops
  hit "the ground".

Change-Id: I3d7b72bcbb684642cd9723518b67ab1c7d7a538a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/242479
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-19 15:18:13 +00:00

80 lines
2.1 KiB
JSON

{
"MaxCount": 1000,
"Drawable": {
"Type": "SkCircleDrawable",
"Radius": 1
},
"EffectCode": [
"void effectSpawn(inout Effect effect) {",
" effect.lifetime = 2;",
" effect.rate = 120;",
" float a = radians(mix(-20, 20, rand) - 90);",
" float s = mix(200, 220, rand);",
" effect.vel.x = cos(a) * s;",
" effect.vel.y = sin(a) * s;",
" effect.color.rgb = float3(rand, rand, rand);",
" effect.pos.x = 0;",
" effect.pos.y = 0;",
"}",
"",
"void effectUpdate(inout Effect effect) {",
" effect.vel.y += dt * 90;",
"}",
"",
"void effectDeath(inout Effect effect) {",
" explode(false);",
"}",
""
],
"Code": [
"void spawn(inout Particle p) {",
" p.lifetime = 0.5;",
" float a = radians(rand * 360);",
" float s = mix(5, 10, rand);",
" p.vel.x = cos(a) * s;",
" p.vel.y = sin(a) * s;",
"}",
"",
"void update(inout Particle p) {",
" p.color.a = 1 - p.age;",
"}",
""
],
"Bindings": [
{
"Type": "SkEffectBinding",
"Name": "explode",
"MaxCount": 50,
"Drawable": {
"Type": "SkCircleDrawable",
"Radius": 3
},
"EffectCode": [
"void effectSpawn(inout Effect effect) {",
" effect.burst = 50;",
" effect.lifetime = 2.5;",
"}",
"",
"void effectUpdate(inout Effect effect) {",
"}",
""
],
"Code": [
"void spawn(inout Particle p) {",
" p.lifetime = 2 + rand * 0.5;",
" float a = radians(rand * 360);",
" float s = mix(90, 100, rand);",
" p.vel.x = cos(a) * s;",
" p.vel.y = sin(a) * s;",
"}",
"",
"void update(inout Particle p) {",
" p.color.a = 1 - p.age;",
" p.vel.y += dt * 50;",
"}",
""
],
"Bindings": []
}
]
}