Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 20 additions & 10 deletions src/webgl/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,17 @@ function material(p5, fn) {
* @beta
* @submodule p5.strands
* @param {Function} callback A function building a p5.strands shader.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The material shader
*/
/**
* @method buildFilterShader
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The material shader
*/
fn.buildFilterShader = function (callback) {
return this.baseFilterShader().modify(callback);
fn.buildFilterShader = function (callback, scope) {
return this.baseFilterShader().modify(callback, scope);
};

/**
Expand Down Expand Up @@ -1560,15 +1562,17 @@ function material(p5, fn) {
* @submodule p5.strands
* @beta
* @param {Function} callback A function building a p5.strands shader.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The material shader.
*/
/**
* @method buildMaterialShader
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The material shader.
*/
fn.buildMaterialShader = function (cb) {
return this.baseMaterialShader().modify(cb);
fn.buildMaterialShader = function (cb, scope) {
return this.baseMaterialShader().modify(cb, scope);
};

/**
Expand Down Expand Up @@ -1776,15 +1780,17 @@ function material(p5, fn) {
* @submodule p5.strands
* @beta
* @param {Function} callback A function building a p5.strands shader.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The normal shader.
*/
/**
* @method buildNormalShader
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The normal shader.
*/
fn.buildNormalShader = function (cb) {
return this.baseNormalShader().modify(cb);
fn.buildNormalShader = function (cb, scope) {
return this.baseNormalShader().modify(cb, scope);
};

/**
Expand Down Expand Up @@ -1940,15 +1946,17 @@ function material(p5, fn) {
* @submodule p5.strands
* @beta
* @param {Function} callback A function building a p5.strands shader.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The color shader.
*/
/**
* @method buildColorShader
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The color shader.
*/
fn.buildColorShader = function (cb) {
return this.baseColorShader().modify(cb);
fn.buildColorShader = function (cb, scope) {
return this.baseColorShader().modify(cb, scope);
};

/**
Expand Down Expand Up @@ -2195,15 +2203,17 @@ function material(p5, fn) {
* @submodule p5.strands
* @beta
* @param {Function} callback A function building a p5.strands shader.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The stroke shader.
*/
/**
* @method buildStrokeShader
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
* @param {Object} [scope] An optional scope object passed to .modify().
* @returns {p5.Shader} The stroke shader.
*/
fn.buildStrokeShader = function (cb) {
return this.baseStrokeShader().modify(cb);
fn.buildStrokeShader = function (cb, scope) {
return this.baseStrokeShader().modify(cb, scope);
};

/**
Expand Down
15 changes: 15 additions & 0 deletions test/unit/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,21 @@ suite('p5.Shader', function() {
}).not.toThrowError();
});

test('buildMaterialShader forwards scope to modify', () => {
myp5.createCanvas(5, 5, myp5.WEBGL);
expect(() => {
const myShader = myp5.buildMaterialShader(() => {
myp5.getPixelInputs(inputs => {
inputs.color = [1, 0, 0, 1];
return inputs;
});
}, { myp5 });
myp5.noStroke();
myp5.shader(myShader);
myp5.plane(myp5.width, myp5.height);
}).not.toThrowError();
});

test('returns numbers for builtin globals outside hooks and a strandNode when called inside hooks', () => {
myp5.createCanvas(5, 5, myp5.WEBGL);
myp5.baseMaterialShader().modify(() => {
Expand Down
Loading