skia2/resources/particles/swirl.json
Brian Osman fe49163cd1 Major rewrite of the particle system based on the SkSL interpreter
This removes all of the fixed-function particle affector classes.
Instead, each particle effect just has two SkSL snippets, one for
spawn logic, and one for update logic. Each one gets an inout copy
of the particle struct. Ultimately, this makes the effects much
simpler and smaller, while also being far more flexible (you can
do whatever you want with any values you want). Finally, because
the interpreter is vectorized and a particular effect's scripts
are usually tuned to the specific behaviors desired, it's faster
on basically every effect I compared.

I re-created all of the old effects in the new system. Many just
use pure SkSL (no curves or anything). Some of the old curve and
path/text stuff was very handy, though - so those are now exposed
as external values in the interpreter. Basically, an effect can
have any number of named "bindings" that are a callable thing.
This can be a path, text (shortcut for making fancy paths), curve,
or color curve. The path ones return a float4 with position and
normal, the curves return one or four floats.

... and this transposes all of the particle data storage into
SoA form, so that it can use the much faster interpreter entry
point.

Change-Id: Iebe711c45994c4201041b12d171af976bc5e758e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222057
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2019-07-25 19:59:03 +00:00

48 lines
2.0 KiB
JSON

{
"MaxCount": 4096,
"Duration": 1,
"Rate": 400,
"Drawable": {
"Type": "SkCircleDrawable",
"Radius": 2
},
"Spawn": "// float rand; Every read returns a random float [0 .. 1)\nlayout(ctype=float) in uniform float dt;\nlayout(ctype=float) in uniform float effectAge;\n\nstruct Particle {\n float age;\n float lifetime;\n float2 pos;\n float2 dir;\n float scale;\n float2 vel;\n float spin;\n float4 color;\n float frame;\n};\n\nvoid main(inout Particle p) {\n p.lifetime = 1 + 2 * rand;\n p.pos.x = rand * 50;\n float a = radians(-10 + 20 * rand);\n float s = 50 + 10 * rand;\n p.vel.x = sin(a) * s;\n p.vel.y = -cos(a) * s;\n}\n",
"Update": "// float rand; Every read returns a random float [0 .. 1)\nlayout(ctype=float) in uniform float dt;\nlayout(ctype=float) in uniform float effectAge;\n\nstruct Particle {\n float age;\n float lifetime;\n float2 pos;\n float2 dir;\n float scale;\n float2 vel;\n float spin;\n float4 color;\n float frame;\n};\n\nvoid main(inout Particle p) {\n p.vel.x += wind(p.age) * dt;\n p.scale = 3 - (1.5 * p.age);\n p.color = color(p.age);\n}\n",
"Bindings": [
{
"Type": "SkCurveBinding",
"Name": "wind",
"Curve": {
"XValues": [],
"Segments": [
{
"Type": "Cubic",
"Ranged": false,
"Bidirectional": true,
"A0": 180,
"B0": -90,
"C0": -120,
"D0": -200
}
]
}
},
{
"Type": "SkColorCurveBinding",
"Name": "color",
"Curve": {
"XValues": [],
"Segments": [
{
"Type": "Linear",
"Ranged": true,
"A0": [ 1, 0, 0, 1 ],
"D0": [ 1, 0.735294, 0, 1 ],
"A1": [ 1, 0.588235, 0, 1 ],
"D1": [ 0.941177, 1, 0, 1 ]
}
]
}
}
]
}