Skip to content

Commit 5c5184a

Browse files
committed
Merge branch 'dev-2.0' into dependencies-update
2 parents 0af140e + 615684b commit 5c5184a

28 files changed

Lines changed: 1254 additions & 350 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test/**/*.js": "eslint",
2121
"utils/**/*.{js,mjs}": "eslint"
2222
},
23-
"version": "2.2.0-rc.3",
23+
"version": "2.2.0",
2424
"dependencies": {
2525
"@davepagurek/bezier-path": "^0.0.7",
2626
"@japont/unicode-range": "^1.0.0",

src/core/filterShaders.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import * as constants from './constants';
22

33
/*
4-
* Creates p5.strands filter shaders for cross-platform compatibility
4+
* Creates p5.strands filter shaders for cross-platform compatibility.
5+
*
6+
* NOTE: These work a little differently than p5.js web editor shaders work!
7+
* Firstly, it uses instance mode, so we have to explicitly pass in context
8+
* variables in an argument to your callback and as a second argument to `modify`.
9+
* Secondly, always manually specify uniform names, as variable names will change
10+
* in minified builds.
511
*/
612
export function makeFilterShader(renderer, operation, p5) {
713
switch (operation) {
814
case constants.GRAY:
9-
return renderer.baseFilterShader().modify(() => {
15+
return renderer.baseFilterShader().modify(({ p5 }) => {
1016
p5.getColor((inputs, canvasContent) => {
1117
const tex = p5.getTexture(canvasContent, inputs.texCoord);
1218
// weighted grayscale with luminance values
@@ -16,7 +22,7 @@ export function makeFilterShader(renderer, operation, p5) {
1622
}, { p5 });
1723

1824
case constants.INVERT:
19-
return renderer.baseFilterShader().modify(() => {
25+
return renderer.baseFilterShader().modify(({ p5 }) => {
2026
p5.getColor((inputs, canvasContent) => {
2127
const color = p5.getTexture(canvasContent, inputs.texCoord);
2228
const invertedColor = p5.vec3(1.0) - color.rgb;
@@ -25,8 +31,8 @@ export function makeFilterShader(renderer, operation, p5) {
2531
}, { p5 });
2632

2733
case constants.THRESHOLD:
28-
return renderer.baseFilterShader().modify(() => {
29-
const filterParameter = p5.uniformFloat();
34+
return renderer.baseFilterShader().modify(({ p5 }) => {
35+
const filterParameter = p5.uniformFloat('filterParameter');
3036
p5.getColor((inputs, canvasContent) => {
3137
const color = p5.getTexture(canvasContent, inputs.texCoord);
3238
// weighted grayscale with luminance values
@@ -38,8 +44,8 @@ export function makeFilterShader(renderer, operation, p5) {
3844
}, { p5 });
3945

4046
case constants.POSTERIZE:
41-
return renderer.baseFilterShader().modify(() => {
42-
const filterParameter = p5.uniformFloat();
47+
return renderer.baseFilterShader().modify(({ p5 }) => {
48+
const filterParameter = p5.uniformFloat('filterParameter');
4349
const quantize = (color, n) => {
4450
// restrict values to N options/bins
4551
// and floor each channel to nearest value
@@ -60,9 +66,9 @@ export function makeFilterShader(renderer, operation, p5) {
6066
}, { p5 });
6167

6268
case constants.BLUR:
63-
return renderer.baseFilterShader().modify(() => {
64-
const radius = p5.uniformFloat();
65-
const direction = p5.uniformVec2();
69+
return renderer.baseFilterShader().modify(({ p5 }) => {
70+
const radius = p5.uniformFloat('radius');
71+
const direction = p5.uniformVec2('direction');
6672

6773
// This isn't a real Gaussian weight, it's a quadratic weight
6874
const quadWeight = (x, e) => {
@@ -120,7 +126,7 @@ export function makeFilterShader(renderer, operation, p5) {
120126
}, { p5 });
121127

122128
case constants.ERODE:
123-
return renderer.baseFilterShader().modify(() => {
129+
return renderer.baseFilterShader().modify(({ p5 }) => {
124130
const luma = (color) => {
125131
return p5.dot(color.rgb, p5.vec3(0.2126, 0.7152, 0.0722));
126132
};
@@ -150,7 +156,7 @@ export function makeFilterShader(renderer, operation, p5) {
150156
}, { p5 });
151157

152158
case constants.DILATE:
153-
return renderer.baseFilterShader().modify(() => {
159+
return renderer.baseFilterShader().modify(({ p5 }) => {
154160
const luma = (color) => {
155161
return p5.dot(color.rgb, p5.vec3(0.2126, 0.7152, 0.0722));
156162
};
@@ -180,7 +186,7 @@ export function makeFilterShader(renderer, operation, p5) {
180186
}, { p5 });
181187

182188
case constants.OPAQUE:
183-
return renderer.baseFilterShader().modify(() => {
189+
return renderer.baseFilterShader().modify(({ p5 }) => {
184190
p5.getColor((inputs, canvasContent) => {
185191
const color = p5.getTexture(canvasContent, inputs.texCoord);
186192
return p5.vec4(color.rgb, 1.0);

0 commit comments

Comments
 (0)