-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Adding framebuffer support for filter() + CreateFilterShader for 2D mode #6559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
198e456
8b71469
0ec719e
96bc262
72cd97b
6f0b715
2789e2a
2df0b03
f42da57
cefc285
9a86b19
75b0042
ae37304
e807740
1af2155
7fa39f6
683ed18
c250531
e4291cd
b073664
a353711
4a9bef9
2a330bf
6d04ec6
b1ec441
c01235f
8df7437
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1008,6 +1008,18 @@ p5.RendererGL = class RendererGL extends p5.Renderer { | |
} | ||
return this.filterGraphicsLayerTemp; | ||
} | ||
matchSize(fboToMatch, target) { | ||
if ( | ||
fboToMatch.width !== target.width || | ||
fboToMatch.height !== target.height | ||
) { | ||
fboToMatch.resizeCanvas(target.width, target.height); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this needs to just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay @davepagurek There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
if (fboToMatch.pixelDensity() !== target._pInst.pixelDensity()) { | ||
fboToMatch.pixelDensity(target._pInst.pixelDensity()); | ||
} | ||
} | ||
filter(...args) { | ||
|
||
let fbo = this.getFilterLayer(); | ||
|
@@ -1048,21 +1060,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer { | |
const target = this.activeFramebuffer() || this; | ||
|
||
// Resize the framebuffer 'fbo' and adjust its pixel density if it doesn't match the target. | ||
this.matchSize(fbo, target); | ||
|
||
if ( | ||
fbo.width !== this.width || | ||
fbo.height !== this.height | ||
) { | ||
// Resize fbo | ||
fbo.resizeCanvas(this.width, this.height); | ||
} | ||
if ( | ||
fbo.pixelDensity() !== this._pInst.pixelDensity() | ||
) { | ||
fbo.pixelDensity(this._pInst.pixelDensity()); | ||
} | ||
|
||
// Set the yScale of the filterCamera for framebuffers. | ||
// Set filterCamera for framebuffers. | ||
if (target !== this) { | ||
this.filterCamera = this.getFilterLayer().createCamera(); | ||
} | ||
|
@@ -1073,10 +1073,12 @@ p5.RendererGL = class RendererGL extends p5.Renderer { | |
1 / (target.height * target.pixelDensity()) | ||
]; | ||
|
||
// apply blur shader with multiple passes | ||
// apply blur shader with multiple passes. | ||
if (operation === constants.BLUR) { | ||
// Treating 'tmp' as a framebuffer. | ||
const tmp = this.getFilterLayerTemp(); | ||
// Resize the framebuffer 'tmp' and adjust its pixel density if it doesn't match the target. | ||
this.matchSize(tmp, target); | ||
tmp.draw(() => this._pInst.clear()); // prevent feedback effects here too | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think we don't need either this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was thinking that too. But in the previous code i found the same thing...I also thought to remove but as it was already written I did the same way for framebuffers. Okay gonna remove it. |
||
|
||
// setup | ||
|
@@ -1130,7 +1132,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer { | |
}); | ||
|
||
} | ||
// draw fbo contents onto main renderer | ||
// draw fbo contents onto main renderer. | ||
this._pInst.push(); | ||
this._pInst.noStroke(); | ||
this.clear(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this, we might want to do a similar size matching to what we do in RendererGL with its framebuffer so that we ensure
this.filterGraphicsLayer
matches width, height, and pixel density tothis._pInst
. Right now filters on 2D mode don't seem to work when resizing: https://editor.p5js.org/davepagurek/sketches/OOKkLOINpMaybe we can also copy and paste the current unit test that checks that the framebuffer gets resized in WebGL mode, and adapt it to check the size of
filterGraphicsLayer
in 2D mode? It would definitely be helpful to leave behind as many tests as we can so that we don't have to rely so much on thinking of new things to test the next time we make changes to this system.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, i will do the changes asap.