11import * as constants from './constants' ;
22
33/*
4- * Creates p5.strands filter shaders for cross-platform compatibility
4+ * Creates p5.strands filter shaders for cross-platform compatibility.
5+ *
6+ * NOTE: These work a little differently than p5.js web editor shaders work!
7+ * Firstly, it uses instance mode, so we have to explicitly pass in context
8+ * variables in an argument to your callback and as a second argument to `modify`.
9+ * Secondly, always manually specify uniform names, as variable names will change
10+ * in minified builds.
511 */
612export function makeFilterShader ( renderer , operation , p5 ) {
713 switch ( operation ) {
@@ -26,7 +32,7 @@ export function makeFilterShader(renderer, operation, p5) {
2632
2733 case constants . THRESHOLD :
2834 return renderer . baseFilterShader ( ) . modify ( ( { p5 } ) => {
29- const filterParameter = p5 . uniformFloat ( ) ;
35+ const filterParameter = p5 . uniformFloat ( 'filterParameter' ) ;
3036 p5 . getColor ( ( inputs , canvasContent ) => {
3137 const color = p5 . getTexture ( canvasContent , inputs . texCoord ) ;
3238 // weighted grayscale with luminance values
@@ -39,7 +45,7 @@ export function makeFilterShader(renderer, operation, p5) {
3945
4046 case constants . POSTERIZE :
4147 return renderer . baseFilterShader ( ) . modify ( ( { p5 } ) => {
42- const filterParameter = p5 . uniformFloat ( ) ;
48+ const filterParameter = p5 . uniformFloat ( 'filterParameter' ) ;
4349 const quantize = ( color , n ) => {
4450 // restrict values to N options/bins
4551 // and floor each channel to nearest value
@@ -61,8 +67,8 @@ export function makeFilterShader(renderer, operation, p5) {
6167
6268 case constants . BLUR :
6369 return renderer . baseFilterShader ( ) . modify ( ( { p5 } ) => {
64- const radius = p5 . uniformFloat ( ) ;
65- const direction = p5 . uniformVec2 ( ) ;
70+ const radius = p5 . uniformFloat ( 'radius' ) ;
71+ const direction = p5 . uniformVec2 ( 'direction' ) ;
6672
6773 // This isn't a real Gaussian weight, it's a quadratic weight
6874 const quadWeight = ( x , e ) => {
0 commit comments