Skip to content

Commit 057f727

Browse files
authored
Merge branch 'main' into instances-api
2 parents 30f95e2 + ea185ca commit 057f727

9 files changed

Lines changed: 53 additions & 23 deletions

File tree

src/strands/ir_builders.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -344,38 +344,24 @@ export function castToFloat(strandsContext, dep) {
344344
return createStrandsNode(id, dimension, strandsContext);
345345
}
346346

347-
export function structConstructorNode(strandsContext, structTypeInfo, rawUserArgs) {
347+
export function structConstructorNode(strandsContext, structTypeInfo, dependsOn) {
348348
const { cfg, dag } = strandsContext;
349-
const { identifer, properties } = structTypeInfo;
349+
const { properties } = structTypeInfo;
350350

351-
if (!(rawUserArgs.length === properties.length)) {
351+
if (dependsOn.length !== properties.length) {
352352
FES.userError('type error',
353-
`You've tried to construct a ${structTypeInfo.typeName} struct with ${rawUserArgs.length} properties, but it expects ${properties.length} properties.\n` +
353+
`You've tried to construct a ${structTypeInfo.typeName} struct with ${dependsOn.length} properties, but it expects ${properties.length} properties.\n` +
354354
`The properties it expects are:\n` +
355-
`${properties.map(prop => prop.name + ' ' + prop.DataType.baseType + prop.DataType.dimension)}`
355+
`${properties.map(prop => `${prop.name}: ${prop.dataType.baseType}${prop.dataType.dimension}`).join(', ')}`
356356
);
357357
}
358358

359-
const dependsOn = [];
360-
for (let i = 0; i < properties.length; i++) {
361-
const expectedProperty = properties[i];
362-
const { originalNodeID, mappedDependencies } = mapPrimitiveDepsToIDs(strandsContext, expectedProperty.dataType, rawUserArgs[i]);
363-
if (originalNodeID) {
364-
dependsOn.push(originalNodeID);
365-
}
366-
else {
367-
dependsOn.push(
368-
constructTypeFromIDs(strandsContext, expectedProperty.dataType, mappedDependencies)
369-
);
370-
}
371-
}
372-
373359
const nodeData = DAG.createNodeData({
374360
nodeType: NodeType.OPERATION,
375361
opCode: OpCode.Nary.CONSTRUCTOR,
376362
dimension: properties.length,
377-
baseType: structTypeInfo.typeName ,
378-
dependsOn
363+
baseType: structTypeInfo.typeName,
364+
dependsOn,
379365
});
380366
const id = DAG.getOrCreateNode(dag, nodeData);
381367
CFG.recordInBasicBlock(cfg, cfg.currentBlock, id);

src/webgl/strands_glslBackend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export const glslBackend = {
249249
}
250250
const dag = strandsContext.dag;
251251
const rootNode = getNodeDataFromID(dag, rootNodeID);
252-
if (isStructType(returnType)) {
252+
if (isStructType(returnType) && rootNode.identifier) {
253253
const structTypeInfo = returnType;
254254
for (let i = 0; i < structTypeInfo.properties.length; i++) {
255255
const prop = structTypeInfo.properties[i];

src/webgpu/strands_wgslBackend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export const wgslBackend = {
410410
}
411411
const dag = strandsContext.dag;
412412
const rootNode = getNodeDataFromID(dag, rootNodeID);
413-
if (isStructType(returnType)) {
413+
if (isStructType(returnType) && rootNode.identifier) {
414414
const structTypeInfo = returnType;
415415
for (let i = 0; i < structTypeInfo.properties.length; i++) {
416416
const prop = structTypeInfo.properties[i];

test/unit/visual/cases/webgl.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,25 @@ visualTest('randomGaussian() in a fragment loop averages to the mean', (p5, scre
15001500
p5.circle(0, 0, 30);
15011501
screenshot();
15021502
});
1503+
1504+
visualTest('hook returning a fresh struct (not the struct argument) applies modifications', (p5, screenshot) => {
1505+
p5.createCanvas(50, 50, p5.WEBGL);
1506+
const shader = p5.baseMaterialShader().modify(() => {
1507+
p5.worldInputs.begin();
1508+
p5.worldInputs.set({
1509+
position: p5.worldInputs.position.add([10, 0, 0]),
1510+
normal: p5.worldInputs.normal,
1511+
texCoord: p5.worldInputs.texCoord,
1512+
color: [1, 0, 0, 1],
1513+
});
1514+
p5.worldInputs.end();
1515+
}, { p5 });
1516+
p5.background(0);
1517+
p5.noStroke();
1518+
p5.shader(shader);
1519+
p5.plane(20, 20);
1520+
screenshot();
1521+
});
15031522
});
15041523

15051524
visualSuite('background()', function () {

test/unit/visual/cases/webgpu.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,25 @@ visualSuite("WebGPU", function () {
364364
p5.plane(50, 50);
365365
await screenshot();
366366
});
367+
368+
visualTest('hook returning a fresh struct (not the struct argument) applies modifications', async function(p5, screenshot) {
369+
await p5.createCanvas(50, 50, p5.WEBGPU);
370+
const shader = p5.baseMaterialShader().modify(() => {
371+
p5.worldInputs.begin();
372+
p5.worldInputs.set({
373+
position: p5.worldInputs.position.add([10, 0, 0]),
374+
normal: p5.worldInputs.normal,
375+
texCoord: p5.worldInputs.texCoord,
376+
color: [1, 0, 0, 1],
377+
});
378+
p5.worldInputs.end();
379+
}, { p5 });
380+
p5.background(0);
381+
p5.noStroke();
382+
p5.shader(shader);
383+
p5.plane(20, 20);
384+
await screenshot();
385+
}, { focus: true });
367386
});
368387

369388
visualTest('randomGaussian() colors a basic shader (WebGPU)', async function(p5, screenshot) {
263 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
263 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)