Skip to content

Commit 9f7b632

Browse files
committed
add noise example for buildFilterShader
1 parent 62257f1 commit 9f7b632

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/webgl/material.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,39 @@ function material(p5, fn) {
684684
* }
685685
* ```
686686
*
687+
* We can use the `noise()` function built into strands to generate a color for each pixel. Again we'll animate by setting an announced uniform variable - time - with `setUniform()` each frame.
688+
*
689+
* ```js example
690+
* let myFilter;
691+
*
692+
* function setup() {
693+
* createCanvas(100, 100, WEBGL);
694+
* myFilter = buildFilterShader(noiseShaderCallback);
695+
* }
696+
*
697+
* function noiseShaderCallback() {
698+
* let time = uniformFloat();
699+
* filterColor.begin();
700+
* let coord = filterColor.texCoord;
701+
*
702+
* //generate a value roughly between 0 and 1
703+
* let noiseVal = noise(coord.x, coord.y, time / 2000);
704+
*
705+
* let result = mix(
706+
* [1, 0, 1, 1], // Magenta
707+
* [0, 1, 1, 1], // Cyan
708+
* noiseVal
709+
* );
710+
* filterColor.set(result);
711+
* filterColor.end();
712+
* }
713+
*
714+
* function draw() {
715+
* myFilter.setUniform("time", millis());
716+
* filter(myFilter);
717+
* }
718+
* ```
719+
*
687720
* Like the `modify()` method on shaders,
688721
* advanced users can also fill in `filterColor` using <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>
689722
* instead of JavaScript.

0 commit comments

Comments
 (0)