🐛 webgl output fixed when passing in offscreencanvas

This commit is contained in:
2019-02-05 10:49:36 +01:00
parent c9ce5846d1
commit 3c1bfbee7e
2 changed files with 15 additions and 2 deletions

View File

@@ -25,6 +25,13 @@ export default class Channels extends WebGL {
min: 0, min: 0,
max: 1, max: 1,
step: 0.1, step: 0.1,
},
amount: {
type: 'Number',
default: 0,
min: 0,
max: 1,
step: 0.1,
} }
}) })
} }
@@ -40,18 +47,24 @@ export default class Channels extends WebGL {
varying vec2 v_texCoord; varying vec2 v_texCoord;
uniform vec3 u_weights; uniform vec3 u_weights;
uniform float u_strength;
void main() { void main() {
vec4 pixelColor = texture2D(u_image, v_texCoord).rgba; vec4 pixelColor = texture2D(u_image, v_texCoord).rgba;
vec3 weights = u_weights / max((u_weights.r + u_weights.g + u_weights.b), 1.0); vec3 weights = u_weights / max((u_weights.r + u_weights.g + u_weights.b), 1.0);
float grey = dot(pixelColor.rgb, weights); float grey = dot(pixelColor.rgb, weights);
gl_FragColor = vec4(grey, grey, grey, pixelColor.a); gl_FragColor = vec4(
mix(pixelColor.r, grey, u_strength),
mix(pixelColor.g, grey, u_strength),
mix(pixelColor.b, grey, u_strength),
pixelColor.a);
} }
` `
} }
_setParams(gl, program) { _setParams(gl, program) {
gl.uniform3f(gl.getUniformLocation(program, "u_weights"), this.in.red.value, this.in.green.value, this.in.blue.value); gl.uniform3f(gl.getUniformLocation(program, "u_weights"), this.in.red.value, this.in.green.value, this.in.blue.value);
gl.uniform1f(gl.getUniformLocation(program, 'u_strength'), this.in.amount.value);
} }
} }

View File

@@ -180,7 +180,7 @@ export default class WebGL extends Node {
if (this.image) { if (this.image) {
// Upload the image into the texture. // Upload the image into the texture.
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this.image); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, await createImageBitmap(this.image));
} }