24 Commits

Author SHA1 Message Date
peabrainiac
996a1d6cf7
Update sprite.frag 2019-03-03 17:55:55 +01:00
Christopher Willis-Ford
355a8c5395 Change brightness effect to match Scratch 2.0 in 2D mode 2019-01-15 19:45:45 -08:00
Michael "Z" Goddard
14813e590c
replace hsl color handling with hsv (#355)
Scratch 2 color and brightness effects in HSV color space.
2018-10-23 15:13:54 -04:00
Michael "Z" Goddard
4c8bc5d806
Framebuffer PenSkin (#319)
* draw pen skin lines and stamps to a framebuffer

* skip reading pixels and draw stamp to framebuffer

* update silhouette with readPixels

* draw pen canvas to buffer when its dirty

Composite lines and stamps on browser preferred side (cpu/gpu) until
the export texture is needed. Then blend the canvas with the current
buffer contents.

Updating this way invalidates useProgram optimization and the renderer
currently does not have a way to know this.

* draw lines on framebuffer through fragment shader

* optimize draw regions and pen skin matrix creation

* control draw regions

* mobile gpus need high precision floats for line drawing

* optimize cpu pen line math

* sampled pen line caps

* sampleless pen skin lines, lint, document pen skin buffer ops

* add PenSkin._canvasDirty to constructor

* remove DRAW_MODE_line

* comment PenSkin reused memory, use memory in drawRectangle

* turn draw region id's into optional method handlers

A region ID object may have an enter and exit method on it that are
used by default when entering and exiting that region.

* remove old DRAW_MODE_line precision setting

* standardize vert lines on 4 spaces

* fixup! turn draw region id's into optional method handlers

* do not draw when updating pen skin silhouette

* do not premultiply stamp colors by alpha

* fixup! do not draw when updating pen skin silhouette

* do not premultiply line color

* add a small rim around the line for aliasing

* variable pen line alias amount

* reverse offset pen line on y axis by relative alias amount

Reverse the offset to keep small line overlap to a minimum.

* fixup! reverse offset pen line on y axis by relative alias amount

* medium precision gpu floats
2018-08-08 14:30:51 -04:00
Paul Kaplan
bd8ca26bb7 Fix color inversion bug on mobile 2018-04-30 15:54:13 -04:00
Christopher Willis-Ford
61c75172d0 Remember: no Hungarian 2017-12-06 15:28:41 -08:00
Christopher Willis-Ford
408b259055 Simplify & document RGB->HSL conversion 2017-12-05 11:01:12 -08:00
Christopher Willis-Ford
e83673ffb8 Increase epsilon for RGB2HCV to fix mobile NaN
Some mobile GPUs end up dividing by "zero" with the previous epsilon
value. The larger epsilon doesn't cause any problems on systems which
didn't exhibit the bug (like my main dev machine).
2017-12-04 15:31:18 -08:00
Michael "Z" Goddard
08e4523324
Change the fisheye shader so it does not need a conditional 2017-11-15 14:05:26 -05:00
Michael "Z" Goddard
1c9f148923
Change whirl shader so it does not need a conditional 2017-11-15 14:05:25 -05:00
Tim Mickel
14018f5ff6 Apply ghost effect after discard (#44) 2016-10-11 17:37:28 -04:00
Christopher Willis-Ford
9f59b42901 Implement color-touching-color
The `isTouchingColor` function now takes an optional mask parameter. If
provided, only the parts of the Drawable which match the mask color will
be used for the test. For example:
```
  isTouchingColor(4, red, blue);
```
This means "are there any parts of Drawable #4 which are blue and are
touching a red pixel on some other Drawable?"
2016-06-06 16:21:24 -07:00
Christopher Willis-Ford
e03e9a0929 Drop lightness threshold for color effect
HSL's lightness is, in this case, basically the same as half of HSV's
value, so this change halves the threshold value used by the color
effect to make it similar in appearance to the HSV implementation.
2016-06-01 14:23:13 -07:00
Christopher Willis-Ford
94cbe8999d Implement pick(x,y) -> Drawable ID 2016-05-27 16:10:22 -07:00
Christopher Willis-Ford
36439bf665 Multiply projection and model matrices in shader
This will allow rendering the primary view, picking view, and "touching
color" view with different projection matrices without needing to
recalculate the model matrix for every Drawable every time.
2016-05-27 11:55:15 -07:00
Christopher Willis-Ford
c24cfaaf4c Fix pixelate "pixel" size
Pixelate still needs a bit more work: at certain scales the edges of the
"pixels" are ragged. This happens in Scratch 2.0 as well, but for me it
seems slightly worse in this implementation.
2016-05-26 09:53:22 -07:00
Christopher Willis-Ford
03107781ab Use HSL instead of HSV for brightness effect 2016-05-25 14:21:40 -07:00
Christopher Willis-Ford
dcedd0c3cf Fix brightness and ghost effects
The renderer now uses premultiplied alpha in the frame buffer, though
textures are still stored without premultiplied alpha. This makes it
easier to get the desired results from the browser's canvas compositing
step, and might be nicer for mobile hardware depending on which parts of
the Internet you believe.
2016-05-20 15:36:02 -07:00
Christopher Willis-Ford
920271d076 Fix pixelate effect
This implementation of the pixel effect is now very similar to the
PixelBender implementation in Scratch 2.0

I also added a slider to demo.html as a debugging aid: it manipulates a
value that is passed into the shader and used in whatever way helps.
2016-05-20 14:17:44 -07:00
Christopher Willis-Ford
41d3d6f6ba First pass at implementing all effects
Some of the math is wrong but I believe all the structure is now in place.
2016-05-19 15:46:37 -07:00
Christopher Willis-Ford
8b461e0651 Tweak whirl, color effects for #ifdef-based shader
Also fixed a typo in effect value conversion
2016-05-19 13:25:01 -07:00
Christopher Willis-Ford
4fc42ca00a Added a TODO regarding a texturing issue
The current fragment chader contains non-uniform control flow for
determining the texture coordinates to use with `texture2D()`. The spec
says that this can cause undefined behavior; in my case I see a
"sparkle" of wrong pixels near primitive edges.
See:
https://www.opengl.org/wiki/Sampler_%28GLSL%29#Non-uniform_flow_control
2016-05-17 14:10:51 -07:00
Christopher Willis-Ford
dbe3f1370b Draw a squirrel
This change introduces the Drawable class, which corresponds to a
Scratch sprite or clone. It supports setting its "skin" (corresponding
to a Scratch costume) by md5+extension, but currently only supports
bitmap skins. Drawables can be created, destroyed, and otherwise
manipulated by ID through the renderer.
2016-05-17 13:52:37 -07:00
Christopher Willis-Ford
51e17c57a9 Establish initial structure, create demo.html
So far this does nothing but clear the screen to magenta, but it's a
start.
2016-05-13 11:29:51 -07:00