Skip to content

Adds createFilterShader() and custom shader support to the webGL filter() function #6237

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 50 commits into from
Aug 2, 2023
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
16def01
declare framebuffer usage
wong-justin Jun 23, 2023
c7abb8c
new properties for shader filters
wong-justin Jun 23, 2023
9dbe595
partial shader filter implementation instead of error
wong-justin Jun 23, 2023
a096914
add new filter() signature
wong-justin Jun 23, 2023
87f347a
branch filter() for either webgl mode or 2d mode, not just 2d
wong-justin Jun 23, 2023
e0126bf
revert to p5.Graphics instead of p5.Framebuffer, at least for now
wong-justin Jun 29, 2023
cb1979b
apply shader to secondary graphics, then draw onto main
wong-justin Jun 29, 2023
644e61a
Merge remote-tracking branch 'upstream/main' into shader-filters
wong-justin Jun 29, 2023
628fc18
add manual test for webgl filter()
wong-justin Jun 30, 2023
359d16b
add some automated webgl filter tests
wong-justin Jun 30, 2023
e857d5b
remove confused arguments
wong-justin Jun 30, 2023
a762869
create new shader bound to secondary graphics
wong-justin Jun 30, 2023
2eb64a0
add tests to check sizing
wong-justin Jun 30, 2023
0c5d0ff
docs for filter(shader)
wong-justin Jul 7, 2023
10d85ff
add resizing to secondary graphics
wong-justin Jul 7, 2023
f324437
only create secondary shader once
wong-justin Jul 7, 2023
7f39f69
leave out filter(CONSTANT) test until that feature is added
wong-justin Jul 7, 2023
fc50e52
remove resolution check because pixel density wont change
wong-justin Jul 7, 2023
f3a41e7
remove framebuffer test since framebuffer isnt used for now
wong-justin Jul 7, 2023
7888ad4
fill in empty tests
wong-justin Jul 7, 2023
b52a467
wip: copy uniforms to shader copy
wong-justin Jul 7, 2023
02113bb
add performance visual to filter test page
wong-justin Jul 13, 2023
be7c01c
Merge remote-tracking branch 'upstream/main' into shader-filters
wong-justin Jul 13, 2023
aa1f048
expose the built library
wong-justin Jul 13, 2023
5d50053
rebuild p5.min.js
wong-justin Jul 13, 2023
4e52976
add non-minified library too
wong-justin Jul 13, 2023
590d025
fix parent shader check
wong-justin Jul 13, 2023
f2e69ae
remove tabs and console.log
wong-justin Jul 14, 2023
6e4c04e
add createFilterShader that includes default vertex shader
wong-justin Jul 14, 2023
f23d072
update output lib
wong-justin Jul 14, 2023
034ebb5
clean whitespace
wong-justin Jul 14, 2023
7bfa2f2
stop tracking output libs
wong-justin Jul 14, 2023
f6fbdc2
test for createFilterShader()
wong-justin Jul 14, 2023
86cb79d
mark todos for next PR
wong-justin Jul 14, 2023
bf282f3
fix gitignore
wong-justin Jul 14, 2023
25424c7
document uniforms
wong-justin Jul 21, 2023
d1dd620
refine example fragment shaders
wong-justin Jul 21, 2023
fa178ba
default vertex shader
wong-justin Jul 21, 2023
68ad8ae
rest of createFilterShader docs
wong-justin Jul 21, 2023
c039991
adjust test shaders to match default filter shaders
wong-justin Jul 21, 2023
c476759
add test comparing default vertex shader to a supplied one
wong-justin Jul 21, 2023
4b1e56e
revert pre-flipping the y in the vertex shader
wong-justin Jul 28, 2023
ec76701
add test for edge case of filter shader on graphics context
wong-justin Jul 28, 2023
8220071
move uniform documentation to setUniform
wong-justin Jul 28, 2023
44ad94f
add disclaimers to createFilterShader docs
wong-justin Jul 28, 2023
a532146
Merge remote-tracking branch 'upstream/main' into shader-filters
wong-justin Jul 28, 2023
479aca3
go back to flipping the y
wong-justin Jul 29, 2023
4250399
fix filter() not working on a secondary p5.Graphics
wong-justin Jul 29, 2023
5abd47d
small wording changes in createFilterShader docs
wong-justin Jul 29, 2023
51aa874
remove unused commented code from test
wong-justin Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions src/webgl/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,53 @@ p5.prototype.createShader = function(vertSrc, fragSrc) {
* <div modernizr='webgl'>
* <code>
* function setup() {
* let frag = `precision mediump float;
* varying mediump vec2 vTexCoord;
* let fragSrc = `precision highp float;
* void main() {
* gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
* }`;
*
* uniform sampler2D tex0;
* createCanvas(100, 100, WEBGL);
* let s = createFilterShader(fragSrc);
* filter(s);
* describe('a yellow square');
* }
* </code>
* </div>
*
* float luma(vec3 color) {
* return dot(color, vec3(0.299, 0.587, 0.114));
* }
* <div modernizr='webgl'>
* <code>
* let img, s;
* function preload() {
* img = loadImage('assets/bricks.jpg');
* }
* function setup() {
* let fragSrc = `precision highp float;
*
* // x,y coordinates, given from the vertex shader
* varying vec2 vTexCoord;
*
* // the canvas contents, given from filter()
* uniform sampler2D tex0;
* // a custom variable from the sketch
* uniform float darkness;
*
* void main() {
* vec2 uv = vTexCoord;
* // gets flipped vertically
* uv.y = 1.0 - uv.y;
* vec4 sampledColor = texture2D(tex0, uv);
* float gray = luma(sampledColor.rgb);
* gl_FragColor = vec4(gray, gray, gray, 1.0);
* // get the color at current pixel
* vec4 color = texture2D(tex0, vTexCoord);
* // set the output color
* color.b = 1.0;
* color *= darkness;
* gl_FragColor = vec4(color.rgb, 1.0);
* }`;
*
* createCanvas(100, 100, WEBGL);
* let s = createFilterShader(frag);
* background('RED');
* s = createFilterShader(fragSrc);
* }
* function draw() {
* image(img, -50, -50);
* s.setUniform('darkness', 0.5);
* filter(s);
* describe('a plain gray canvas');
* describe('a image of bricks tinted dark blue');
* }
* </code>
* </div>
Expand Down