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
9 changes: 7 additions & 2 deletions src/strands/strands_transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,13 @@ const ASTCallbacks = {
// Only inject the variable name if the first argument isn't already a string
if (
node.init.arguments.length === 0 ||
node.init.arguments[0].type !== 'Literal' ||
typeof node.init.arguments[0].value !== 'string'
!(
(
node.init.arguments[0].type === 'Literal' &&
typeof node.init.arguments[0].value === 'string'
) ||
node.init.arguments[0].type === 'TemplateLiteral'
)
) {
const uniformName = getOrCreateInternalShaderName(
state.shaderNameMap,
Expand Down
25 changes: 25 additions & 0 deletions test/unit/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,31 @@ suite('p5.Shader', function () {
assert.approximately(pixelColor[2], 204, 5);
});

test('handle custom uniform names with template strings', () => {
myp5.createCanvas(50, 50, myp5.WEBGL);
const testShader = myp5.baseMaterialShader().modify(
() => {
// Variable name is 'brightness' but uniform name is 'customBrightness'
const brightness = myp5.uniformFloat(`customBrightness`, () => 0.8);
myp5.getPixelInputs(inputs => {
inputs.color = [brightness, brightness, brightness, 1.0];
return inputs;
});
},
{ myp5 }
);

myp5.noStroke();
myp5.shader(testShader);
myp5.plane(myp5.width, myp5.height);

// Check that the shader uses the automatic value (0.8)
const pixelColor = myp5.get(25, 25);
assert.approximately(pixelColor[0], 204, 5); // 0.8 * 255 = 204
assert.approximately(pixelColor[1], 204, 5);
assert.approximately(pixelColor[2], 204, 5);
});

test('handle custom uniform names with manual setUniform', () => {
myp5.createCanvas(50, 50, myp5.WEBGL);
const testShader = myp5.baseMaterialShader().modify(
Expand Down
Loading