-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Erode, dilate, threshold shader filters match closer to CPU filters #6405
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should these values also be multiplied by pixel density?
Uh oh!
There was an error while loading. Please reload this page.
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.
This is a good question. I think ideally, we'd want to make the shader handle pixel density rather than the user calling the filter function so that it's easier to make density-agnostic sketches. That means the shader would likely want to know about both the width and the pixel density. I think right now this is possible by comparing
texelSize
andcanvasSize
, but wouldn't be possible if we also multiply by pixel density here. (Maybe it's worth addingpixelDensity
as a separate uniform so it doesn't always have to be calculated by dividing the other two? Not necessary in this PR though!)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.
I was thinking maybe all shader uniforms should account for pixel density, ie.
texelSize = 1 / (width * pixelDensity), 1 / (height * pixelDensity)
andcanvasSize = width * pixelDensity, height * pixelDensity
. That way they would all be doing work at the same level of resolution. Although havingcanvasSize != width, height
is probably not what the user expects.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.
I think the main reason why we might not want that for all uniforms is that if the pixel density is always premultiplied, then the shader can't distinguish between a canvas at 2x density and a canvas at 2x the size. That would mean that on the user's screen, a
filter(BLUR, 3)
on a 2x display might end up looking less blurry than on a 1x display, since the blur radius would be smaller relative to the physical size of the canvas. I think I naturally interpret the 3 infilter(BLUR, 3)
as being the same units the rest of p5 uses, pixels times pixel density, rather than real pixels.I think it's ok having most uniforms come with pixel density premultiplied as long as we also pass the density into the shader on its own too though.