Commit Graph

40 Commits

Author SHA1 Message Date
Brian Osman
38d8deae8f Revert "Add particle GM that uses uniforms, fix related bug in particle effect"
This reverts commit 964b4465c4.

Reason for revert: Earlier CL needs revert

Original change's description:
> Add particle GM that uses uniforms, fix related bug in particle effect
>
> We weren't allocating uniform storage until after the first update, far
> too late for users to pump uniform values in. They're now allocated as
> soon as the effect is created, which is tested by the new GM.
>
> Change-Id: Ia0084bcec5986479c350ead27d14344c3ed82520
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/362176
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>

TBR=brianosman@google.com

Change-Id: Ib6f963840af2abba0a4e6b99185f4010b61dde54
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/362418
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-01-29 19:21:49 +00:00
Brian Osman
964b4465c4 Add particle GM that uses uniforms, fix related bug in particle effect
We weren't allocating uniform storage until after the first update, far
too late for users to pump uniform values in. They're now allocated as
soon as the effect is created, which is tested by the new GM.

Change-Id: Ia0084bcec5986479c350ead27d14344c3ed82520
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/362176
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-01-29 18:01:48 +00:00
Brian Osman
e89d8ea20b Update particle system to use skvm, rather than ByteCode
This was the last remaining user of ByteCode. The skvm solution
is faster, and lets us delete the ByteCode system.

Testing on 15 instances of sinusoidal_emitter (90k particles):
  - ByteCode                     ~9   ms
  - ByteCode (older, optimized): ~5.5 ms
  - skvm                         ~2.1 ms

Change-Id: Ia2e5c9ab2d36c97e59af28a6f989bf212889e439
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356919
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2021-01-21 23:07:29 +00:00
Brian Osman
ace3f2939f Remove SkEffectBinding feature from particle system
This is no longer used, and the current design is fairly incompatible
with skvm.

Change-Id: Ibebb9b42a0f4277c333839c3d1e9cf0f691b37cc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353079
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-01-12 19:36:27 +00:00
Brian Osman
be0b3b7363 Strip down SkSL::ExternalValues, limit them to functions
Previously ExternalValues were flexible, and could be used as raw values
(with the ability to chain access via dot notation), or they could be
callable. The only non-test use-case has been for functions (in
particles) for a long time. With the push towards SkVM, limiting
ourselves to this interface simplifies things: external functions are
basically custom intrinsics (and with the SkVM backend, they'll just get
access to the builder, and be able to do any math, as well as
loads/stores, etc).

By narrowing the feature set, we can rename everything to reflect that,
and it's overall clearer (the SkSL types now mirror FunctionReference
and FunctionCall directly, particularly in how they're handled by the
CFG and inliner).

Change-Id: Ib5dd34158ff85aae6c297408a92ace5485a08190
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350704
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-01-07 14:28:41 +00:00
Brian Osman
e11c43804b Remove use of uint from particle random system
uint (and bitwise operations) aren't supported by our minimum spec, and
they're going to be removed from public SkSL. For now, convert the
random generator to a good-enough chaotic sequence of high-frequency
sine waves.

If/when the interpreter (and particles) are converted to the newer skvm
backend, it will be straightforward to support custom intrinsics that
emit skvm instructions directly into the builder, and re-introduce a
better integer-based PRNG, without requiring SkSL language support.

Bug: skia:11093
Change-Id: I885b15a51a9e5c12b4274b5938d8deb77219d41b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347036
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2020-12-23 16:21:17 +00:00
Brian Osman
265064450f Remove 'flags' feature from particles
No longer used by any example content, and it requires unsigned integers
and bitwise ops (which are both going to be hidden from public SkSL).

Bug: skia:11093
Change-Id: I1941f7a1bed6c8512a5117ef256d18e420cbabee
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/346779
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2020-12-22 21:05:23 +00:00
Brian Osman
32d53550c8 Remove unsafe compiler methods related to external values
We don't want to be polluting the global namespace with external values,
especially when the typical/recommended way to use the Compiler is with
a single long-lived instance. Force client code to manage ownership (the
only non-unit-test case was already doing this), and pass external
values to convertProgram, so they can be added to the Program's symbol
table.

Change-Id: If4c1db5e48a62e2cf4333b8d80420f2dfede27ab
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319125
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-09-24 14:12:08 +00:00
John Stiles
a6841be235 Enable ClangTidy check llvm-namespace-comment.
This fixes a large number of SkSL namespaces which were labeled as if
they were anonymous, and also a handful of other mislabeled namespaces.
Missing namespace-end comments have been added throughout.
A number of diffs are just indentation-related (adjusting 1- or 3-
space indents to 2-space).

Change-Id: I6c62052a0d3aea4ae12ca07e0c2a8587b2fce4ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308503
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-06 19:07:52 +00:00
Brian Osman
95c26efc90 Pure SkSL RNG for particles
Change-Id: I2cb6255a553852a292427d6dc9ef8c5ed7f8286d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/252926
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2020-04-10 17:20:07 +00:00
Brian Osman
b08cc024cd Switch back to stack-based SkSL interpreter
It's slower, but code size is quite a bit smaller, memory usage is
smaller, and we think that mapping it to SkVM is just as easy.

This effectively reverts all of the following commits:

"Fix gcc9 warning around size of memset."
https://skia-review.googlesource.com/c/skia/+/279861

"Remove unused (and misleading) 'instruction' from SkSLInterpreter.h"
https://skia-review.googlesource.com/c/skia/+/278177

"Interpreter: Fix intrinsics when called with vector types"
https://skia-review.googlesource.com/c/skia/+/272721

"Make it easier to add vector versions of byte code instructions"
https://skia-review.googlesource.com/c/skia/+/272527

"Interpreter: Support returns from runStriped"
https://skia-review.googlesource.com/c/skia/+/268941

"add SkSLInterpreter vector instructions"
https://skia-review.googlesource.com/c/skia/+/266560

"Fix crash when editing particle scripts"
https://skia-review.googlesource.com/c/skia/+/269487

"Revert "Revert "Complete rewrite of the SkSL interpreter"""
https://skia-review.googlesource.com/c/skia/+/266205

Change-Id: I4258596399c4ca94489d4faf8aacfec88afeee13
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281205
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2020-04-03 17:20:04 +00:00
Ethan Nicholas
b962eff76c Revert "Revert "Complete rewrite of the SkSL interpreter""
This reverts commit 99c54f0290.

Change-Id: I010ac4fdb6c5b6bfbdf63f4dcac5dbf962b0ad9c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266205
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-01-24 14:42:37 +00:00
Ben Wagner
470e0ac14a Revert "Revert "Revert "Complete rewrite of the SkSL interpreter"""
This reverts commit 7deb1c26ba.

Revert "maybe fixed?"

This reverts commit 7ad3f229c7.

Revert "removed extraneous change"

This reverts commit 682f299aa8.

Revert "test change"

This reverts commit 5f40986cef.

Revert "derp"

This reverts commit 4f830b8df3.

Revert "let's see what happens"

This reverts commit d5290563f0.

Change-Id: Ib3c13c2a6ade9fc42382509d036e212c7fe50cc6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265979
Reviewed-by: Ben Wagner aka dogben <benjaminwagner@google.com>
2020-01-22 21:59:48 +00:00
Ethan Nicholas
7deb1c26ba Revert "Revert "Complete rewrite of the SkSL interpreter""
This reverts commit 99c54f0290.
2020-01-22 16:44:31 -05:00
Ethan Nicholas
99c54f0290 Revert "Complete rewrite of the SkSL interpreter"
This reverts commit 2cde3a1320.

Reason for revert: breaking the Chrome roll

Original change's description:
> Complete rewrite of the SkSL interpreter
> 
> Change-Id: Idf4037b04c22f8ace5c1ef16c7a28d8c3df92e91
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/250817
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

TBR=brianosman@google.com,ethannicholas@google.com

Change-Id: If0fbc78118173e0cacbe1e01cabe3331e35aa49e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265516
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-01-21 16:07:08 +00:00
Ethan Nicholas
2cde3a1320 Complete rewrite of the SkSL interpreter
Change-Id: Idf4037b04c22f8ace5c1ef16c7a28d8c3df92e91
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/250817
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-01-21 14:49:59 +00:00
Brian Osman
9dac0d8216 Particles: Better integration for ResourceProvider
This untangles some of the dirty state tracking and dynamic rebuilding
support (that's only needed for the GUI editor), so the core code is
more streamlined. It also paves the way for feeding the RP to bindings.

Change-Id: I208ec59622154fdb2845c3ae8f7efb070d1abfc7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257476
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-12-03 14:12:50 +00:00
Brian Osman
d12f2786e2 Use ResourceProvider in particles
Currently just for image drawable, but going to use this for
references to other kinds of data in bindings, too.

Change-Id: Ic6673530013337bbaadd2d3f1c040626ec24ffb8
Bug: skia:9513
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/256776
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2019-11-27 16:45:23 +00:00
Brian Osman
5b43113e75 Interpreter: Reflect all uniform variables in ByteCode
Gives enough information to locate variables by name (using the same
scheme as glGetUniformLocation), and provide hints about type and size.

Bug: skia:9513
Change-Id: I9444f1042471967a79c9f05167dcdb78eca41bad
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/244502
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-10-16 15:35:48 +00:00
Brian Osman
df18296f98 Add accessors to get/set SkParticleEffect fields
Simplify burst handling. Scripts should just add to burst (if
they want to handle programmatic bursting, as well).

Update most effects to handle dynamic updates to position better,
and add a sample effect meant to be used with mouse tracking.

Change-Id: Ia302e1d04e62e2b07974807c44067786cc10a8ad
Bug: skia:9513
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/248798
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-10-15 14:54:50 +00:00
Brian Osman
9b8b4558d2 Change ByteCode and ByteCodeFunction to classes
The lack of encapsulation was finally starting to bother me. Had to
change the Interpreter namespace to a struct so that it could be
friended, but otherwise this was a nice and simple cleanup.

Also updated the comments on the two run functions, and renamed
fInputSlots to fUniformSlots, to reflect recent clarification
around in vs. uniform.

Change-Id: I24bbc59778b3ab6448bffcf98133d5c149a060a9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/244883
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-30 18:02:24 +00:00
Brian Osman
559ffe4a23 Particles: Added particle flags for tracking state (one-time triggers, etc)
Also removed some older effects that weren't interesting, improved others,
cleaned up the unused functions in several, and renamed most of them to
reflect which feature they're demonstrating.

Change-Id: Ib44a00ec3d25e852a1d1661918137ba13d30c86b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/244119
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-25 15:58:09 +00:00
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
Brian Osman
d1846d85ad Update SkParticleEffect comments based on review feedback
Change-Id: I3436ee95c4cc13067b53b170515fd10c19b329b3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/242136
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2019-09-17 18:10:00 +00:00
Brian Osman
d46cb9729b Particle effect scripting update
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>
2019-09-16 17:48:04 +00:00
Brian Osman
61e17c51ad Particles: Change effect lifetime logic to work like particles
Change-Id: I9f71bfbd506b56eae4fe6a430b70f8f9a31d7009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238445
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-03 13:56:39 +00:00
Brian Osman
2aa85df8e7 Particle cleanup: split SkParticleBinding out of SkParticleEffect
Also simplify type registration.

Change-Id: Ia47febb2ae2cd5821476c3dd33a688b688aa6d6d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238359
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-08-30 15:32:38 +00:00
Brian Osman
3da607ec72 Finish and document particle public API
Added factories to create particle binding objects, which were the only
piece that couldn't be generated programmatically.

Commented most of the things that a user needs to know to create an
effect from within code. (Except for all the details of SkSL).

Change-Id: I4003e536e46c77e0c1c9e83486cf99f0c2cf54d1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230120
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-29 13:30:26 +00:00
Brian Osman
e59acb79b8 Particles: Merge spawn & update into one code string with two functions
Change-Id: If57fb79db8f8c5fd185fefaa202167c8082dd846
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229921
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-25 23:51:07 +00:00
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
Mike Klein
c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00
Brian Osman
d0c1bd43d9 Particle cleanup: IWYU
Bug: skia:
Change-Id: If9d8a22a770e4125391d0fbd263521f6bdb7725d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/198246
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-03-06 22:26:40 +00:00
Brian Osman
b77d502946 Particles: Cleanup and better UI
Remove SkAnimTimer from the module interface entirely.
Clean up some other SkParticleEffect methods. Simplify
VisitTypes to just visit all of them, it's easier for
the client to do any filtering.

In the slide, make the UI far nicer. Load all files in
a given directory, and allow editing (and saving) them
all at once, or adding a new entry. Support multiple
playing effects, with a draggable handle to set the
position.

Bug: skia:
Change-Id: I0bec4077f9135bc122569f1410bebc96d5439480
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/197243
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-03-06 18:42:11 +00:00
Kevin Lubick
269fe89950 [canvaskit] Add particles integration
Bug: skia:
Change-Id: I5bf08e8007b59b5e21005f5004d698e53b99ffe6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/197849
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-03-06 14:52:56 +00:00
Brian Osman
3d76d1bf46 Particles: Removed emitters, added more full-featured position affectors
Bug: skia:
Change-Id: Ie6485a11bb57fecef470d727dcf3b4fe5dff0b90
Reviewed-on: https://skia-review.googlesource.com/c/195582
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-02-28 21:16:02 +00:00
Brian Osman
125daa4d1a Refactor and further generalization of particle model
- Collapsed the per-particle data into a single struct, and
  use that to communicate with drawables, too. Let the drawables
  manage allocation of xforms, colors, etc. Helpful for non-atlas
  drawables, and just to keep the effect code simpler.
- Having all of the params in a single struct allows us to move
  the remaining animated behaviors into affectors (color/frame).
- Added SkColorCurve, which works like SkCurve for SkColor4f.
  Use that to create a color affector (rather than simple
  start/end colors in the effect params).
- Also put the stable random in SkParticleState. This is going
  to be necessary if/when we change affectors to operate on all
  particles (rather than one at a time). Still need to move t
  value into the particle struct (or eval it from the lifetime
  params on demand).

Change-Id: Icf39116acbfd5d6e8eb91e9affbd8898d106211d
Reviewed-on: https://skia-review.googlesource.com/c/193473
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-02-20 18:01:00 +00:00
Brian Osman
543d2e2f2e Moved image params out to SkParticleDrawable
Added a simpler circle drawable, moved drawing code out so that frame
calculation is handled by the drawable. Fixed all the sample effects,
including some size adjustments to better create the intended effect.

Bug: skia:
Change-Id: I60af9cd6262ff98352ca8ceaf6768aef9c7e164c
Reviewed-on: https://skia-review.googlesource.com/c/193029
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-02-15 20:07:43 +00:00
Brian Osman
8b6283fc98 New SkCurve type with multiple curve segments
- Converted all linear force stuff into a single affector,
  used at either spawn or update time appropriately.
  The new affector can either set or adjust velocity.
- Converted lifetime to a curve.
- Removed SkRangedFloat, initial velocity params, etc.

Looks like a large addition, but that's mostly down to the
JSON getting bigger. There's a net reduction in LoC.

Bug: skia:
Change-Id: Iac7417f15f96d0313efd08c4b26dc3250b80fa77
Reviewed-on: https://skia-review.googlesource.com/c/192102
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-02-15 14:10:39 +00:00
Brian Osman
5c1f8eb094 Various particle system improvements
Effects now have a duration, and can be played looped
or one-shot. Added a second list of affectors that are
applied at spawn vs. update.

Effects grab and store the SkRandom at construction,
so it no longer needs to be passed to update().

Bug: skia:
Change-Id: Ib54d60466e162e4d4b70fa64c1215fc01680d47a
Reviewed-on: https://skia-review.googlesource.com/c/191722
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-02-14 20:19:08 +00:00
Brian Osman
7c979f52c3 Experimental Particle System
This adds a new "Particles" slide to viewer, that allows
editing, loading, and saving particle effects. All of the
particle system code is in modules/particles.

There are many rough edges and some not-yet-finished changes
to generalize the model[1]. A rough overview:

- SkReflected.h implements a lightweight reflection system
  for classes derived from SkReflected. Adding a new class
  involves deriving from SkReflected, adding a macro to the
  class declaration, and implementing visitFields(), which
  simply calls a virtual on an SkFieldVisitor for each field.
  Currently, emitters and affectors use this mechanism.

- SkParticleSerialization.h demonstrates two useful field
  visitors - for serializing to and from JSON. The driver
  code that uses those is directly in ParticlesSlide.

- SkParticleData.h and SkCurve.h define a variety of helper
  types for talking about particles, both for parameterizing
  individual values, and communicating about the state of a
  particle among the effect, affectors, and emitters.

- SkParticleEffect.h defines the static data definition of
  an effect (SkParticleEffectParams), as well as a running
  instance of an effect (SkParticleEffect). The effect has
  simple update() and draw() methods.

- ParticlesSlide.cpp adds a third field visitor to generate
  GUIs for interactively editing the running effect.

---

1: The critical change I'd like to make is to remove all
special case behavior over time and at spawn (setting sprite
frames, size over time, color over time, etc...). Integration
is the only fixed function behavior. Everything else is driven
by two lists of affectors. One is applied at spawn time, using
the effect's lifetime to evaluate curves. This allows spawning
particles with different colors as the effect ages out, for
example. The second list is applied every frame to update
existing particles, and is driven by the particle's lifetime.
This allows particles to change color after being spawned, for
example.

With a small set of affectors using a single expressive curve
primitive (keyframed list of cubic curve segments), we can
have affectors that update color, size, velocity, position,
sprite frame, etc., and implement many complex behaviors.

Bug: skia:
Change-Id: Id9402bef22825d55d021c5a2f9e5e41791aabaf4
Reviewed-on: https://skia-review.googlesource.com/c/181404
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2019-02-12 18:53:41 +00:00