980 Commits

Author SHA1 Message Date
Christopher Willis-Ford
1040189e27 Move shader management to new ShaderManager class 2016-06-08 13:38:49 -07:00
Christopher Willis-Ford
74deedba1b Add .editorconfig 2016-06-08 09:27:01 -07: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
6b0f3379bf Allow overriding the candidates for picking
This can be used to implement the "touching {mouse-pointer}?" block.
2016-06-03 09:21:36 -07:00
Christopher Willis-Ford
eb7e87730c Move RenderWebGL class into its own file
The `index.js` file now handles module-level exports only.
2016-06-03 08:47:50 -07:00
Christopher Willis-Ford
4d04ef5de7 Use Buffer instead of Uint8Array (lint fix)
Also suppress lint warning about unused alpha in color4ubToID since
that's intentional (for now).
2016-06-02 15:42:55 -07:00
Christopher Willis-Ford
bdf65d4284 Add isTouchingColor(drawableID, color3ub)
Also eliminate the ability to specify background alpha, since that can
affect page-level compositing in undesirable ways.
Also avoid some redundant GL state calls.
2016-06-02 15:09:02 -07:00
Christopher Willis-Ford
25d8148ec4 Add more flexibility to draw-time object filtering
The `_drawThese` call now takes both a list of Drawable IDs for positive
filtering and a filter function for negative filtering.
2016-06-01 16:17:56 -07:00
Christopher Willis-Ford
137e4a642e Skin loading improvements
Fixed timing errors related to calling `setSkin()` a second time before
the first callback chain completes.
Fixed a typo causing problems when more than one Drawable is registered.
2016-06-01 15:28:08 -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
f6b78b2216 Picking improvements
- Increased canvas border in demo.html to make it more obvious if future
  code forgets to compensate for the border.
- Fixed picking code to compensate for a border around the canvas.
- Completed support for picking with a touch larger than a single point.
2016-05-31 14:00:39 -07:00
Christopher Willis-Ford
c02d2a1f5b Add picking test to demo.html
It appears that picking is 1 pixel off in each dimension
2016-05-27 16:18: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
d9a89fdd06 Support setting the stage background color 2016-05-19 12:00:19 -07:00
Christopher Willis-Ford
7f020787fd Generate shader for each effect combo on demand
The combination of effects is encoded bitwise as an index into the
shader cache array. The `getShader` function fetches the relevant index
if it's present, or calls `_buildShader()` to compile a new shader. The
effects are enabled by prepending lines like `#define ENABLE_whirl` at
the beginning of the vertex and fragment shader texts.
2016-05-19 11:36:55 -07:00
Christopher Willis-Ford
798981812d Provide an interface for bulk-updating a Drawable
The renderer can now update any combination of a Drawable's position,
direction, scale, and effect values through a single function call. The
effect values will be adjusted according to per-effect conversion
functions to prepare the values for use inside the shader.
2016-05-18 16:21:26 -07:00
Christopher Willis-Ford
db69b23a0e Support rendering SVGs 2016-05-18 12:35:08 -07:00
Christopher Willis-Ford
06f7d46613 Keep skin until new one loads 2016-05-17 15:24:14 -07:00
Christopher Willis-Ford
f30629ebba Document all methods 2016-05-17 15:12:37 -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
60931611d4 Move build products and demo.html into subdir 2016-05-13 11:42:40 -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