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
Add shaders for filter() constants, and use them by default in P2D #6324
Merged
+705
−137
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
568c4ec
mark structure for loading new shader files
wong-justin 9f15a50
destructure args passed to p5.RendererGL.filter
wong-justin e2f123d
change public filter() signature
wong-justin bd8dab4
comment overloaded function parameters for clarity
wong-justin 9a02645
whitespace
wong-justin 5bbb980
start adding shaders for filter constants (GRAY)
wong-justin c1bfee4
fix by creating shaders on secondary graphics layer
wong-justin ef397a1
use old luminance constants for GRAY
wong-justin 197c905
add texelSize as a default uniform
wong-justin 1e34031
add ERODE
wong-justin 4bf2565
add DILATE
wong-justin ed40a78
fix comments explaining what DILATE/ERODE do
wong-justin fc4181e
add BLUR
wong-justin a94936e
add partial POSTERIZE
wong-justin 586e933
fix filterParameter by moving setUniform after pg.shader() call
wong-justin 1e02d7f
adjust some examples for filter() docs
wong-justin e0deeeb
adjust wording for filter() docs
wong-justin 5dc1056
fix POSTERIZE to match old output
wong-justin 72f7895
simpler sketch for manual testing
wong-justin 10e0cac
wip, start using shader filters in background of P2D
wong-justin 9ae66c5
add OPAQUE
wong-justin 7b71bc3
add INVERT
wong-justin 2897670
add THRESHOLD
wong-justin aa1a7e0
add default filter params
wong-justin 4f1b62c
add extra uniform for canvas size
wong-justin e734106
Merge remote-tracking branch 'upstream/main' into shader-filters
wong-justin 88830eb
keep opacity in THRESHOLD instead of changing it
wong-justin cb6af67
remove default from inside BLUR shader
wong-justin 89aa499
document new default filter parameters
wong-justin 23c3db5
use min/max() instead of luma() for determining brightness
wong-justin 92c7244
simplify example shader in filter()
wong-justin 41cf4ba
document new uniforms, and slight rephrasing in createFilterShader
wong-justin 6c2e9ce
add some tests
wong-justin 9dc8887
store shaders for filters BLUR, INVERT, etc
wong-justin b1a76ec
more tests
wong-justin bafee00
fix feedback effect
wong-justin 3c4afc5
clarify comments
wong-justin 02d187b
support webgl2 fragment shader in createFilterShader()
wong-justin b5d533c
fix whitespace
wong-justin ec41c1f
replace single-pass blur with two-pass
wong-justin 8ccfe59
adjust initial blur two-pass by using uniform(tex0, this)
wong-justin 347401b
add variable to reverse flipping effect of previous commit
wong-justin 39def40
remaining steps for blur, including removing extra shader calls
wong-justin 0e6a95b
revise default vertex shader to deal with depth issue #6367
wong-justin be09142
fix rect() calls
wong-justin 3e22945
update other default vertex shader as well
wong-justin eca2c76
switch to using main and secondary renderers for blur passes
wong-justin b0ef928
prevent error when in webgl mode and attempting to use cpu filters
547578b
testing different manual examples
44d8f2c
Move blur loop into the shader and use a second temp buffer for rende…
b7454db
remove unused code
wong-justin f04ddf8
Merge remote-tracking branch 'ferriss/shader-filters' into shader-fil…
wong-justin d0a2fe9
fix clear()ing at the right time
wong-justin b3583f7
remove unused uniform
wong-justin 1bfe9c7
add tests for filter parameters
wong-justin 121137f
Update pixels.js
aferriss File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Increase the bright areas in an image | ||
|
||
precision highp float; | ||
|
||
varying vec2 vTexCoord; | ||
|
||
uniform sampler2D tex0; | ||
uniform vec2 texelSize; | ||
|
||
float luma(vec3 color) { | ||
// based on constants 77, 151, 28 from ERODE in filters.js, | ||
// even though that's different than the luminance constants used in GRAY | ||
return dot(color, vec3(0.3008, 0.5898, 0.1094)); | ||
} | ||
|
||
void main() { | ||
vec4 curColor = texture2D(tex0, vTexCoord); | ||
float curLuminance = luma(curColor.rgb); | ||
|
||
// set current color as the neighbor color with lowest luminance | ||
|
||
vec4 neighbors[4]; | ||
neighbors[0] = texture2D(tex0, vTexCoord + vec2( texelSize.x, 0.0)); | ||
neighbors[1] = texture2D(tex0, vTexCoord + vec2(-texelSize.x, 0.0)); | ||
neighbors[2] = texture2D(tex0, vTexCoord + vec2(0.0, texelSize.y)); | ||
neighbors[3] = texture2D(tex0, vTexCoord + vec2(0.0, -texelSize.y)); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
vec4 color = neighbors[i]; | ||
float lum = luma(color.rgb); | ||
if (lum < curLuminance) { | ||
curColor = color; | ||
curLuminance = lum; | ||
} | ||
} | ||
|
||
gl_FragColor = curColor; | ||
} |
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.
Not sure if the
if
statement should be replaced by some sort ofstep
logic. I know it's good to avoid branching if statements in shaders for speed. But a simpleif
statement seems easier to read and maintain