Skip to content

Commit

Permalink
v0.10.3: Enhance applyEffects with support for FBO, graphics, image, …
Browse files Browse the repository at this point in the history
…and video inputs (graphics support added)
  • Loading branch information
nakednous committed Sep 12, 2024
1 parent 96874e7 commit 7560359
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function keyPressed() {
}
```

1. `applyEffects(source, effects, [uniforms = {}], [flip = true])`: Sequentially applies all effects (in the order they were added) to the source, which can be a [p5.Framebuffer](https://p5js.org/reference/p5/p5.Framebuffer), [p5.Image](https://p5js.org/reference/p5/p5.Image/), or [p5.MediaElement](https://p5js.org/reference/p5/p5.MediaElement/). The `uniforms` param maps shader `keys` to their respective uniform values, formatted as `{ uniform_1_name: value_1, ..., uniform_n_name: value_n }`, provided that a `sampler2D uniform blender` variable is declared in each shader effect as a common fbo layer. The `flip` boolean indicates whether the final image should be vertically flipped. This method processes each effect, applying its shader with the corresponding uniforms (using `applyShader`), and returns the final processed source, now modified by all effects.
1. `applyEffects(source, effects, [uniforms = {}], [flip = true])`: Sequentially applies all effects (in the order they were added) to the source, which can be a [p5.Framebuffer](https://p5js.org/reference/p5/p5.Framebuffer), [p5.Graphics](https://p5js.org/reference/p5/p5.Graphics/), [p5.Image](https://p5js.org/reference/p5/p5.Image/), or [p5.MediaElement](https://p5js.org/reference/p5/p5.MediaElement/). The `uniforms` param maps shader `keys` to their respective uniform values, formatted as `{ uniform_1_name: value_1, ..., uniform_n_name: value_n }`, provided that a `sampler2D uniform blender` variable is declared in each shader effect as a common fbo layer. The `flip` boolean indicates whether the final image should be vertically flipped. This method processes each effect, applying its shader with the corresponding uniforms (using `applyShader`), and returns the final processed source, now modified by all effects.
2. `createBlender(effects, [options={}])`: [Creates](https://p5js.org/reference/#/p5/createFramebuffer) and attaches an fbo layer with specified `options` to each shader in the `effects` array. If `createBlender` is not called, `applyEffects` automatically generates a blender layer for each shader, utilizing default options.
3. `removeBlender(effects)`: Removes the individual fbo layers associated with each shader in the `effects` array, freeing up resources by invoking [remove](https://p5js.org/reference/#/p5.Framebuffer/remove).

Expand Down
8 changes: 4 additions & 4 deletions p5.treegl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
var Tree = (function (ext) {
const INFO = {
LIBRARY: 'p5.treegl',
VERSION: '0.10.2',
VERSION: '0.10.3',
HOMEPAGE: 'https://github.com/VisualComputing/p5.treegl'
};
Object.freeze(INFO);
Expand Down Expand Up @@ -1251,7 +1251,7 @@ void main() {
let uniformsMapping = {};
let flip = true;
args.forEach(arg => {
if (arg instanceof p5.Framebuffer || arg instanceof p5.Image || arg instanceof p5.MediaElement) {
if (arg instanceof p5.Framebuffer || arg instanceof p5.Graphics || arg instanceof p5.Image || arg instanceof p5.MediaElement) {
source = arg;
} else if (Array.isArray(arg) && arg.every(e => e instanceof p5.Shader)) {
effects = arg;
Expand All @@ -1261,8 +1261,8 @@ void main() {
flip = arg;
}
});
if (!(source instanceof p5.Framebuffer || source instanceof p5.Image || source instanceof p5.MediaElement)) {
console.log('The source param should be either a p5.Framebuffer, p5.Image, or p5.MediaElement in applyEffects(source, effects).');
if (!(source instanceof p5.Framebuffer || source instanceof p5.Graphics || source instanceof p5.Image || source instanceof p5.MediaElement)) {
console.log('The source param should be either a p5.Framebuffer, p5.Graphics, p5.Image, or p5.MediaElement in applyEffects(source, effects).');
return source;
}
if (!Array.isArray(effects)) {
Expand Down

0 comments on commit 7560359

Please sign in to comment.