p5 2.2.3 → 2.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accessibility/color_namer.js +9 -11
- package/dist/accessibility/describe.js +0 -1
- package/dist/accessibility/gridOutput.js +0 -1
- package/dist/accessibility/index.js +9 -10
- package/dist/accessibility/outputs.js +0 -1
- package/dist/accessibility/textOutput.js +0 -1
- package/dist/app.js +11 -10
- package/dist/app.node.js +122 -0
- package/dist/color/color_conversion.js +9 -11
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +25 -12
- package/dist/{constants-BdTiYOQI.js → constants-0wkVUfqa.js} +2 -2
- package/dist/core/States.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +28 -29
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +9 -8
- package/dist/core/friendly_errors/file_errors.js +1 -2
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +737 -640
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/friendly_errors/stacktrace.js +0 -1
- package/dist/core/helpers.js +3 -4
- package/dist/core/init.js +24 -21
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +9 -11
- package/dist/core/main.js +9 -10
- package/dist/core/p5.Graphics.js +5 -5
- package/dist/core/p5.Renderer.js +3 -3
- package/dist/core/p5.Renderer2D.js +9 -10
- package/dist/core/p5.Renderer3D.js +5 -5
- package/dist/core/rendering.js +5 -5
- package/dist/core/structure.js +0 -1
- package/dist/core/transform.js +7 -16
- package/dist/{creating_reading-C7hu6sg1.js → creating_reading-DLkHH80h.js} +11 -8
- package/dist/data/local_storage.js +0 -1
- package/dist/dom/dom.js +2 -3
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +2 -2
- package/dist/dom/p5.MediaElement.js +2 -2
- package/dist/events/acceleration.js +5 -3
- package/dist/events/keyboard.js +0 -1
- package/dist/events/pointer.js +0 -2
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +19 -12
- package/dist/image/image.js +5 -5
- package/dist/image/index.js +5 -5
- package/dist/image/loading_displaying.js +5 -5
- package/dist/image/p5.Image.js +3 -3
- package/dist/image/pixels.js +0 -1
- package/dist/io/files.js +5 -5
- package/dist/io/index.js +5 -5
- package/dist/io/p5.Table.js +0 -1
- package/dist/io/p5.TableRow.js +0 -1
- package/dist/io/p5.XML.js +0 -1
- package/dist/{ir_builders-Cd6rU9Vm.js → ir_builders-C2ebb6Lu.js} +234 -1
- package/dist/{main-H_nu4eDs.js → main-D2kqeMXM.js} +107 -136
- package/dist/math/Matrices/Matrix.js +1 -1
- package/dist/math/Matrices/MatrixNumjs.js +1 -1
- package/dist/math/calculation.js +0 -1
- package/dist/math/index.js +3 -1
- package/dist/math/math.js +3 -17
- package/dist/math/noise.js +0 -1
- package/dist/math/p5.Matrix.js +1 -2
- package/dist/math/p5.Vector.js +237 -279
- package/dist/math/patch-vector.js +75 -0
- package/dist/math/random.js +0 -1
- package/dist/math/trigonometry.js +3 -4
- package/dist/{p5.Renderer-BmD2P6Wv.js → p5.Renderer-CQI8PO1F.js} +31 -24
- package/dist/{rendering-CC8JNTwG.js → rendering-ltTIxpF2.js} +732 -44
- package/dist/shape/2d_primitives.js +1 -4
- package/dist/shape/attributes.js +43 -8
- package/dist/shape/curves.js +0 -1
- package/dist/shape/custom_shapes.js +260 -5
- package/dist/shape/index.js +2 -2
- package/dist/shape/vertex.js +0 -2
- package/dist/strands/ir_builders.js +1 -1
- package/dist/strands/ir_types.js +5 -1
- package/dist/strands/p5.strands.js +286 -31
- package/dist/strands/strands_api.js +179 -8
- package/dist/strands/strands_codegen.js +26 -8
- package/dist/strands/strands_conditionals.js +1 -1
- package/dist/strands/strands_for.js +1 -1
- package/dist/strands/strands_node.js +1 -1
- package/dist/strands/strands_ternary.js +56 -0
- package/dist/strands/strands_transpiler.js +416 -251
- package/dist/strands_glslBackend-i-ReKgZo.js +423 -0
- package/dist/type/index.js +3 -3
- package/dist/type/lib/Typr.js +1 -1
- package/dist/type/p5.Font.js +3 -3
- package/dist/type/textCore.js +31 -24
- package/dist/utilities/conversion.js +0 -1
- package/dist/utilities/time_date.js +0 -1
- package/dist/utilities/utility_functions.js +0 -1
- package/dist/webgl/3d_primitives.js +5 -5
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +26 -1
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +8 -9
- package/dist/webgl/interaction.js +8 -4
- package/dist/webgl/light.js +5 -5
- package/dist/webgl/loading.js +60 -21
- package/dist/webgl/material.js +5 -5
- package/dist/webgl/p5.Camera.js +5 -5
- package/dist/webgl/p5.Framebuffer.js +5 -5
- package/dist/webgl/p5.Geometry.js +3 -5
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +17 -21
- package/dist/webgl/p5.Shader.js +129 -36
- package/dist/webgl/p5.Texture.js +5 -5
- package/dist/webgl/strands_glslBackend.js +5 -386
- package/dist/webgl/text.js +5 -5
- package/dist/webgl/utils.js +5 -5
- package/dist/webgl2Compatibility-DA7DLMuq.js +7 -0
- package/dist/webgpu/index.js +7 -3
- package/dist/webgpu/p5.RendererWebGPU.js +1146 -180
- package/dist/webgpu/shaders/color.js +1 -1
- package/dist/webgpu/shaders/compute.js +32 -0
- package/dist/webgpu/shaders/functions/randomComputeWGSL.js +31 -0
- package/dist/webgpu/shaders/functions/randomVertWGSL.js +30 -0
- package/dist/webgpu/shaders/functions/randomWGSL.js +30 -0
- package/dist/webgpu/shaders/line.js +1 -1
- package/dist/webgpu/shaders/material.js +3 -3
- package/dist/webgpu/strands_wgslBackend.js +137 -15
- package/lib/p5.esm.js +4092 -1950
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +4092 -1950
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +1748 -306
- package/lib/p5.webgpu.js +1747 -305
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +6 -1
- package/types/global.d.ts +4182 -2441
- package/types/p5.d.ts +2776 -1675
- package/dist/noise3DGLSL-Bwrdi4gi.js +0 -9
|
@@ -1,388 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
export { g as glslBackend } from '../strands_glslBackend-i-ReKgZo.js';
|
|
2
|
+
import '../strands/ir_types.js';
|
|
3
|
+
import '../strands/ir_dag.js';
|
|
4
|
+
import '../strands/strands_FES.js';
|
|
5
|
+
import '../ir_builders-C2ebb6Lu.js';
|
|
5
6
|
import '../strands/ir_cfg.js';
|
|
6
7
|
import '../strands/strands_builtins.js';
|
|
7
|
-
|
|
8
|
-
function shouldCreateTemp(dag, nodeID) {
|
|
9
|
-
const nodeType = dag.nodeTypes[nodeID];
|
|
10
|
-
if (nodeType !== NodeType.OPERATION) return false;
|
|
11
|
-
if (dag.baseTypes[nodeID] === BaseType.SAMPLER2D) return false;
|
|
12
|
-
const uses = dag.usedBy[nodeID] || [];
|
|
13
|
-
return uses.length > 1;
|
|
14
|
-
}
|
|
15
|
-
const TypeNames = {
|
|
16
|
-
'float1': 'float',
|
|
17
|
-
'float2': 'vec2',
|
|
18
|
-
'float3': 'vec3',
|
|
19
|
-
'float4': 'vec4',
|
|
20
|
-
'int1': 'int',
|
|
21
|
-
'int2': 'ivec2',
|
|
22
|
-
'int3': 'ivec3',
|
|
23
|
-
'int4': 'ivec4',
|
|
24
|
-
'bool1': 'bool',
|
|
25
|
-
'bool2': 'bvec2',
|
|
26
|
-
'bool3': 'bvec3',
|
|
27
|
-
'bool4': 'bvec4',
|
|
28
|
-
'mat2': 'mat2x2',
|
|
29
|
-
'mat3': 'mat3x3',
|
|
30
|
-
'mat4': 'mat4x4',
|
|
31
|
-
};
|
|
32
|
-
const cfgHandlers = {
|
|
33
|
-
[BlockType.DEFAULT]: (blockID, strandsContext, generationContext) => {
|
|
34
|
-
const { dag, cfg } = strandsContext;
|
|
35
|
-
const instructions = cfg.blockInstructions[blockID] || [];
|
|
36
|
-
for (const nodeID of instructions) {
|
|
37
|
-
const nodeType = dag.nodeTypes[nodeID];
|
|
38
|
-
if (shouldCreateTemp(dag, nodeID)) {
|
|
39
|
-
const declaration = glslBackend.generateDeclaration(generationContext, dag, nodeID);
|
|
40
|
-
generationContext.write(declaration);
|
|
41
|
-
}
|
|
42
|
-
if (nodeType === NodeType.STATEMENT) {
|
|
43
|
-
glslBackend.generateStatement(generationContext, dag, nodeID);
|
|
44
|
-
}
|
|
45
|
-
if (nodeType === NodeType.ASSIGNMENT) {
|
|
46
|
-
glslBackend.generateAssignment(generationContext, dag, nodeID);
|
|
47
|
-
generationContext.visitedNodes.add(nodeID);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
[BlockType.BRANCH](blockID, strandsContext, generationContext) {
|
|
52
|
-
const { dag, cfg } = strandsContext;
|
|
53
|
-
// Find all phi nodes in this branch block and declare them
|
|
54
|
-
const blockInstructions = cfg.blockInstructions[blockID] || [];
|
|
55
|
-
for (const nodeID of blockInstructions) {
|
|
56
|
-
const node = getNodeDataFromID(dag, nodeID);
|
|
57
|
-
if (node.nodeType === NodeType.PHI) {
|
|
58
|
-
// Check if the phi node's first dependency already has a temp name
|
|
59
|
-
const dependsOn = node.dependsOn || [];
|
|
60
|
-
if (dependsOn.length > 0) {
|
|
61
|
-
const firstDependency = dependsOn[0];
|
|
62
|
-
const existingTempName = generationContext.tempNames[firstDependency];
|
|
63
|
-
if (existingTempName) {
|
|
64
|
-
// Reuse the existing temp name instead of creating a new one
|
|
65
|
-
generationContext.tempNames[nodeID] = existingTempName;
|
|
66
|
-
continue; // Skip declaration, just alias to existing variable
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Otherwise, create a new temp variable for the phi node
|
|
71
|
-
const tmp = `T${generationContext.nextTempID++}`;
|
|
72
|
-
generationContext.tempNames[nodeID] = tmp;
|
|
73
|
-
const T = extractNodeTypeInfo(dag, nodeID);
|
|
74
|
-
const typeName = glslBackend.getTypeName(T.baseType, T.dimension);
|
|
75
|
-
generationContext.write(`${typeName} ${tmp};`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
this[BlockType.DEFAULT](blockID, strandsContext, generationContext);
|
|
79
|
-
},
|
|
80
|
-
[BlockType.IF_COND](blockID, strandsContext, generationContext) {
|
|
81
|
-
const { dag, cfg } = strandsContext;
|
|
82
|
-
const conditionID = cfg.blockConditions[blockID];
|
|
83
|
-
const condExpr = glslBackend.generateExpression(generationContext, dag, conditionID);
|
|
84
|
-
generationContext.write(`if (${condExpr})`);
|
|
85
|
-
this[BlockType.DEFAULT](blockID, strandsContext, generationContext);
|
|
86
|
-
},
|
|
87
|
-
[BlockType.ELSE_COND](blockID, strandsContext, generationContext) {
|
|
88
|
-
generationContext.write(`else`);
|
|
89
|
-
this[BlockType.DEFAULT](blockID, strandsContext, generationContext);
|
|
90
|
-
},
|
|
91
|
-
[BlockType.IF_BODY](blockID, strandsContext, generationContext) {
|
|
92
|
-
this[BlockType.DEFAULT](blockID, strandsContext, generationContext);
|
|
93
|
-
this.assignPhiNodeValues(blockID, strandsContext, generationContext);
|
|
94
|
-
},
|
|
95
|
-
[BlockType.SCOPE_START](blockID, strandsContext, generationContext) {
|
|
96
|
-
generationContext.write(`{`);
|
|
97
|
-
generationContext.indent++;
|
|
98
|
-
},
|
|
99
|
-
[BlockType.SCOPE_END](blockID, strandsContext, generationContext) {
|
|
100
|
-
generationContext.indent--;
|
|
101
|
-
generationContext.write(`}`);
|
|
102
|
-
},
|
|
103
|
-
[BlockType.MERGE](blockID, strandsContext, generationContext) {
|
|
104
|
-
this[BlockType.DEFAULT](blockID, strandsContext, generationContext);
|
|
105
|
-
},
|
|
106
|
-
[BlockType.FUNCTION](blockID, strandsContext, generationContext) {
|
|
107
|
-
this[BlockType.DEFAULT](blockID, strandsContext, generationContext);
|
|
108
|
-
},
|
|
109
|
-
[BlockType.FOR](blockID, strandsContext, generationContext) {
|
|
110
|
-
const { dag, cfg } = strandsContext;
|
|
111
|
-
const instructions = cfg.blockInstructions[blockID] || [];
|
|
112
|
-
|
|
113
|
-
generationContext.write(`for (`);
|
|
114
|
-
|
|
115
|
-
// Set flag to suppress semicolon on the last statement
|
|
116
|
-
const originalSuppressSemicolon = generationContext.suppressSemicolon;
|
|
117
|
-
|
|
118
|
-
for (let i = 0; i < instructions.length; i++) {
|
|
119
|
-
const nodeID = instructions[i];
|
|
120
|
-
const node = getNodeDataFromID(dag, nodeID);
|
|
121
|
-
const isLast = i === instructions.length - 1;
|
|
122
|
-
|
|
123
|
-
// Suppress semicolon on the last statement
|
|
124
|
-
generationContext.suppressSemicolon = isLast;
|
|
125
|
-
|
|
126
|
-
if (shouldCreateTemp(dag, nodeID)) {
|
|
127
|
-
const declaration = glslBackend.generateDeclaration(generationContext, dag, nodeID);
|
|
128
|
-
generationContext.write(declaration);
|
|
129
|
-
}
|
|
130
|
-
if (node.nodeType === NodeType.STATEMENT) {
|
|
131
|
-
glslBackend.generateStatement(generationContext, dag, nodeID);
|
|
132
|
-
}
|
|
133
|
-
if (node.nodeType === NodeType.ASSIGNMENT) {
|
|
134
|
-
glslBackend.generateAssignment(generationContext, dag, nodeID);
|
|
135
|
-
generationContext.visitedNodes.add(nodeID);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Restore original flag
|
|
140
|
-
generationContext.suppressSemicolon = originalSuppressSemicolon;
|
|
141
|
-
|
|
142
|
-
generationContext.write(`)`);
|
|
143
|
-
},
|
|
144
|
-
assignPhiNodeValues(blockID, strandsContext, generationContext) {
|
|
145
|
-
const { dag, cfg } = strandsContext;
|
|
146
|
-
// Find all phi nodes that this block feeds into
|
|
147
|
-
const successors = cfg.outgoingEdges[blockID] || [];
|
|
148
|
-
for (const successorBlockID of successors) {
|
|
149
|
-
const instructions = cfg.blockInstructions[successorBlockID] || [];
|
|
150
|
-
for (const nodeID of instructions) {
|
|
151
|
-
const node = getNodeDataFromID(dag, nodeID);
|
|
152
|
-
if (node.nodeType === NodeType.PHI) {
|
|
153
|
-
// Find which input of this phi node corresponds to our block
|
|
154
|
-
const branchIndex = node.phiBlocks?.indexOf(blockID);
|
|
155
|
-
if (branchIndex !== -1 && branchIndex < node.dependsOn.length) {
|
|
156
|
-
const sourceNodeID = node.dependsOn[branchIndex];
|
|
157
|
-
const tempName = generationContext.tempNames[nodeID];
|
|
158
|
-
if (tempName && sourceNodeID !== null) {
|
|
159
|
-
const sourceExpr = glslBackend.generateExpression(generationContext, dag, sourceNodeID);
|
|
160
|
-
generationContext.write(`${tempName} = ${sourceExpr};`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
const glslBackend = {
|
|
169
|
-
hookEntry(hookType) {
|
|
170
|
-
const firstLine = `(${hookType.parameters.flatMap((param) => {
|
|
171
|
-
return `${param.qualifiers?.length ? param.qualifiers.join(' ') : ''}${param.type.typeName} ${param.name}`;
|
|
172
|
-
}).join(', ')}) {`;
|
|
173
|
-
return firstLine;
|
|
174
|
-
},
|
|
175
|
-
getTypeName(baseType, dimension) {
|
|
176
|
-
const primitiveTypeName = TypeNames[baseType + dimension];
|
|
177
|
-
if (!primitiveTypeName) {
|
|
178
|
-
return baseType;
|
|
179
|
-
}
|
|
180
|
-
return primitiveTypeName;
|
|
181
|
-
},
|
|
182
|
-
generateHookUniformKey(name, typeInfo) {
|
|
183
|
-
return `${this.getTypeName(typeInfo.baseType, typeInfo.dimension)} ${name}`;
|
|
184
|
-
},
|
|
185
|
-
generateVaryingVariable(varName, typeInfo) {
|
|
186
|
-
return `${typeInfo.fnName} ${varName}`;
|
|
187
|
-
},
|
|
188
|
-
generateLocalDeclaration(varName, typeInfo) {
|
|
189
|
-
const typeName = typeInfo.fnName;
|
|
190
|
-
return `${typeName} ${varName};`;
|
|
191
|
-
},
|
|
192
|
-
generateStatement(generationContext, dag, nodeID) {
|
|
193
|
-
const node = getNodeDataFromID(dag, nodeID);
|
|
194
|
-
// Generate the expression followed by semicolon (unless suppressed)
|
|
195
|
-
const semicolon = generationContext.suppressSemicolon ? '' : ';';
|
|
196
|
-
if (node.statementType === StatementType.DISCARD) {
|
|
197
|
-
generationContext.write(`discard${semicolon}`);
|
|
198
|
-
} else if (node.statementType === StatementType.BREAK) {
|
|
199
|
-
generationContext.write(`break${semicolon}`);
|
|
200
|
-
} else if (node.statementType === StatementType.EXPRESSION) {
|
|
201
|
-
const exprNodeID = node.dependsOn[0];
|
|
202
|
-
const expr = this.generateExpression(generationContext, dag, exprNodeID);
|
|
203
|
-
generationContext.write(`${expr}${semicolon}`);
|
|
204
|
-
} else if (node.statementType === StatementType.EMPTY) {
|
|
205
|
-
generationContext.write(semicolon);
|
|
206
|
-
} else if (node.statementType === StatementType.EARLY_RETURN) {
|
|
207
|
-
const exprNodeID = node.dependsOn[0];
|
|
208
|
-
const expr = this.generateExpression(generationContext, dag, exprNodeID);
|
|
209
|
-
generationContext.write(`return ${expr}${semicolon}`);
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
generateAssignment(generationContext, dag, nodeID) {
|
|
213
|
-
const node = getNodeDataFromID(dag, nodeID);
|
|
214
|
-
// dependsOn[0] = targetNodeID, dependsOn[1] = sourceNodeID
|
|
215
|
-
const targetNodeID = node.dependsOn[0];
|
|
216
|
-
const sourceNodeID = node.dependsOn[1];
|
|
217
|
-
|
|
218
|
-
// Generate the target expression (could be variable or swizzle)
|
|
219
|
-
const targetExpr = this.generateExpression(generationContext, dag, targetNodeID);
|
|
220
|
-
const sourceExpr = this.generateExpression(generationContext, dag, sourceNodeID);
|
|
221
|
-
const semicolon = generationContext.suppressSemicolon ? '' : ';';
|
|
222
|
-
|
|
223
|
-
// Generate assignment if we have both target and source
|
|
224
|
-
if (targetExpr && sourceExpr && targetExpr !== sourceExpr) {
|
|
225
|
-
generationContext.write(`${targetExpr} = ${sourceExpr}${semicolon}`);
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
generateDeclaration(generationContext, dag, nodeID) {
|
|
229
|
-
const expr = this.generateExpression(generationContext, dag, nodeID);
|
|
230
|
-
const tmp = `T${generationContext.nextTempID++}`;
|
|
231
|
-
generationContext.tempNames[nodeID] = tmp;
|
|
232
|
-
const T = extractNodeTypeInfo(dag, nodeID);
|
|
233
|
-
const typeName = this.getTypeName(T.baseType, T.dimension);
|
|
234
|
-
return `${typeName} ${tmp} = ${expr};`;
|
|
235
|
-
},
|
|
236
|
-
generateReturnStatement(strandsContext, generationContext, rootNodeID, returnType) {
|
|
237
|
-
const dag = strandsContext.dag;
|
|
238
|
-
const rootNode = getNodeDataFromID(dag, rootNodeID);
|
|
239
|
-
if (isStructType(returnType)) {
|
|
240
|
-
const structTypeInfo = returnType;
|
|
241
|
-
for (let i = 0; i < structTypeInfo.properties.length; i++) {
|
|
242
|
-
const prop = structTypeInfo.properties[i];
|
|
243
|
-
const val = this.generateExpression(generationContext, dag, rootNode.dependsOn[i]);
|
|
244
|
-
if (prop.name !== val) {
|
|
245
|
-
generationContext.write(
|
|
246
|
-
`${rootNode.identifier}.${prop.name} = ${val};`
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
generationContext.write(`return ${this.generateExpression(generationContext, dag, rootNodeID)};`);
|
|
252
|
-
},
|
|
253
|
-
generateExpression(generationContext, dag, nodeID) {
|
|
254
|
-
const node = getNodeDataFromID(dag, nodeID);
|
|
255
|
-
if (generationContext.tempNames?.[nodeID]) {
|
|
256
|
-
return generationContext.tempNames[nodeID];
|
|
257
|
-
}
|
|
258
|
-
switch (node.nodeType) {
|
|
259
|
-
case NodeType.LITERAL:
|
|
260
|
-
if (node.baseType === BaseType.FLOAT) {
|
|
261
|
-
return node.value.toFixed(4);
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
return node.value;
|
|
265
|
-
}
|
|
266
|
-
case NodeType.VARIABLE:
|
|
267
|
-
// Track shared variable usage context
|
|
268
|
-
if (generationContext.shaderContext && generationContext.strandsContext?.sharedVariables?.has(node.identifier)) {
|
|
269
|
-
const sharedVar = generationContext.strandsContext.sharedVariables.get(node.identifier);
|
|
270
|
-
if (generationContext.shaderContext === 'vertex') {
|
|
271
|
-
sharedVar.usedInVertex = true;
|
|
272
|
-
} else if (generationContext.shaderContext === 'fragment') {
|
|
273
|
-
sharedVar.usedInFragment = true;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return node.identifier;
|
|
277
|
-
case NodeType.OPERATION:
|
|
278
|
-
const useParantheses = node.usedBy.length > 0;
|
|
279
|
-
if (node.opCode === OpCode.Nary.CONSTRUCTOR) {
|
|
280
|
-
// TODO: differentiate casts and constructors for more efficient codegen.
|
|
281
|
-
// if (node.dependsOn.length === 1 && node.dimension === 1) {
|
|
282
|
-
// return this.generateExpression(generationContext, dag, node.dependsOn[0]);
|
|
283
|
-
// }
|
|
284
|
-
if (node.baseType === BaseType.SAMPLER2D) {
|
|
285
|
-
return this.generateExpression(generationContext, dag, node.dependsOn[0]);
|
|
286
|
-
}
|
|
287
|
-
const T = this.getTypeName(node.baseType, node.dimension);
|
|
288
|
-
const deps = node.dependsOn.map((dep) => this.generateExpression(generationContext, dag, dep));
|
|
289
|
-
return `${T}(${deps.join(', ')})`;
|
|
290
|
-
}
|
|
291
|
-
if (node.opCode === OpCode.Nary.FUNCTION_CALL) {
|
|
292
|
-
const functionArgs = node.dependsOn.map(arg =>this.generateExpression(generationContext, dag, arg));
|
|
293
|
-
return `${node.identifier}(${functionArgs.join(', ')})`;
|
|
294
|
-
}
|
|
295
|
-
if (node.opCode === OpCode.Binary.MEMBER_ACCESS) {
|
|
296
|
-
const [lID, rID] = node.dependsOn;
|
|
297
|
-
const lName = this.generateExpression(generationContext, dag, lID);
|
|
298
|
-
const rName = this.generateExpression(generationContext, dag, rID);
|
|
299
|
-
return `${lName}.${rName}`;
|
|
300
|
-
}
|
|
301
|
-
if (node.opCode === OpCode.Unary.SWIZZLE) {
|
|
302
|
-
const parentID = node.dependsOn[0];
|
|
303
|
-
const parentExpr = this.generateExpression(generationContext, dag, parentID);
|
|
304
|
-
return `${parentExpr}.${node.swizzle}`;
|
|
305
|
-
}
|
|
306
|
-
if (node.dependsOn.length === 2) {
|
|
307
|
-
const [lID, rID] = node.dependsOn;
|
|
308
|
-
const left = this.generateExpression(generationContext, dag, lID);
|
|
309
|
-
const right = this.generateExpression(generationContext, dag, rID);
|
|
310
|
-
|
|
311
|
-
// Special case for modulo: use mod() function for floats in GLSL
|
|
312
|
-
if (node.opCode === OpCode.Binary.MODULO) {
|
|
313
|
-
const leftNode = getNodeDataFromID(dag, lID);
|
|
314
|
-
const rightNode = getNodeDataFromID(dag, rID);
|
|
315
|
-
// If either operand is float, use mod() function
|
|
316
|
-
if (leftNode.baseType === BaseType.FLOAT || rightNode.baseType === BaseType.FLOAT) {
|
|
317
|
-
return `mod(${left}, ${right})`;
|
|
318
|
-
}
|
|
319
|
-
// For integers, use % operator
|
|
320
|
-
return `(${left} % ${right})`;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const opSym = OpCodeToSymbol[node.opCode];
|
|
324
|
-
if (useParantheses) {
|
|
325
|
-
return `(${left} ${opSym} ${right})`;
|
|
326
|
-
} else {
|
|
327
|
-
return `${left} ${opSym} ${right}`;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (node.opCode === OpCode.Unary.LOGICAL_NOT
|
|
331
|
-
|| node.opCode === OpCode.Unary.NEGATE
|
|
332
|
-
|| node.opCode === OpCode.Unary.PLUS
|
|
333
|
-
) {
|
|
334
|
-
const [i] = node.dependsOn;
|
|
335
|
-
const val = this.generateExpression(generationContext, dag, i);
|
|
336
|
-
const sym = OpCodeToSymbol[node.opCode];
|
|
337
|
-
return `${sym}${val}`;
|
|
338
|
-
}
|
|
339
|
-
case NodeType.PHI:
|
|
340
|
-
// Phi nodes represent conditional merging of values
|
|
341
|
-
// If this phi node has an identifier (like varying variables), use that
|
|
342
|
-
if (node.identifier) {
|
|
343
|
-
return node.identifier;
|
|
344
|
-
}
|
|
345
|
-
// Otherwise, they should have been declared as temporary variables
|
|
346
|
-
// and assigned in the appropriate branches
|
|
347
|
-
if (generationContext.tempNames?.[nodeID]) {
|
|
348
|
-
return generationContext.tempNames[nodeID];
|
|
349
|
-
} else {
|
|
350
|
-
// If no temp was created, this phi node only has one input
|
|
351
|
-
// so we can just use that directly
|
|
352
|
-
const validInputs = node.dependsOn.filter(id => id !== null);
|
|
353
|
-
if (validInputs.length > 0) {
|
|
354
|
-
return this.generateExpression(generationContext, dag, validInputs[0]);
|
|
355
|
-
} else {
|
|
356
|
-
throw new Error(`No valid inputs for node`)
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
case NodeType.ASSIGNMENT:
|
|
360
|
-
internalError(`ASSIGNMENT nodes should not be used as expressions`);
|
|
361
|
-
default:
|
|
362
|
-
internalError(`${NodeTypeToName[node.nodeType]} code generation not implemented yet`);
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
generateBlock(blockID, strandsContext, generationContext) {
|
|
366
|
-
const type = strandsContext.cfg.blockTypes[blockID];
|
|
367
|
-
const handler = cfgHandlers[type] || cfgHandlers[BlockType.DEFAULT];
|
|
368
|
-
handler.call(cfgHandlers, blockID, strandsContext, generationContext);
|
|
369
|
-
},
|
|
370
|
-
|
|
371
|
-
createGetTextureCall(strandsContext, args) {
|
|
372
|
-
// In GLSL, getTexture is straightforward - just pass through the args
|
|
373
|
-
// First argument should be a texture (sampler2D), second should be coordinates
|
|
374
|
-
const { id, dimension } = functionCallNode(strandsContext, 'getTexture', args, {
|
|
375
|
-
overloads: [{
|
|
376
|
-
params: [DataType.sampler2D, DataType.float2],
|
|
377
|
-
returnType: DataType.float4
|
|
378
|
-
}]
|
|
379
|
-
});
|
|
380
|
-
return { id, dimension };
|
|
381
|
-
},
|
|
382
|
-
|
|
383
|
-
instanceIdReference() {
|
|
384
|
-
return 'gl_InstanceID';
|
|
385
|
-
},
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
export { glslBackend };
|
package/dist/webgl/text.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { R as Renderer3D } from '../rendering-
|
|
1
|
+
import { a7 as TEXTURE, c as TRIANGLES } from '../constants-0wkVUfqa.js';
|
|
2
|
+
import { R as Renderer3D } from '../rendering-ltTIxpF2.js';
|
|
3
3
|
import { Vector } from '../math/p5.Vector.js';
|
|
4
4
|
import { Geometry } from './p5.Geometry.js';
|
|
5
5
|
import { Font, arrayCommandsToObjects } from '../type/p5.Font.js';
|
|
6
|
-
import '../creating_reading-
|
|
6
|
+
import '../creating_reading-DLkHH80h.js';
|
|
7
7
|
import 'colorjs.io/fn';
|
|
8
8
|
import '../color/color_spaces/hsb.js';
|
|
9
|
+
import '../strands/ir_types.js';
|
|
9
10
|
import '../dom/p5.Element.js';
|
|
10
11
|
import '../dom/p5.File.js';
|
|
11
12
|
import '../io/p5.XML.js';
|
|
12
|
-
import '../p5.Renderer-
|
|
13
|
+
import '../p5.Renderer-CQI8PO1F.js';
|
|
13
14
|
import '../image/filters.js';
|
|
14
15
|
import '../shape/custom_shapes.js';
|
|
15
16
|
import '../core/States.js';
|
|
@@ -23,7 +24,6 @@ import '../shape/vertex.js';
|
|
|
23
24
|
import '../color/setting.js';
|
|
24
25
|
import 'omggif';
|
|
25
26
|
import '../io/csv.js';
|
|
26
|
-
import 'gifenc';
|
|
27
27
|
import '../image/pixels.js';
|
|
28
28
|
import '../core/transform.js';
|
|
29
29
|
import './GeometryBuilder.js';
|
package/dist/webgl/utils.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import '../constants-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import '../constants-0wkVUfqa.js';
|
|
2
|
+
import '../strands/ir_types.js';
|
|
3
|
+
export { u as checkWebGLCapabilities, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, j as populateGLSLHooks, o as readPixelWebGL, q as readPixelsWebGL, e as setWebGLTextureParams, s as setWebGLUniformValue } from '../rendering-ltTIxpF2.js';
|
|
4
|
+
import '../creating_reading-DLkHH80h.js';
|
|
4
5
|
import 'colorjs.io/fn';
|
|
5
6
|
import '../color/color_spaces/hsb.js';
|
|
6
7
|
import '../dom/p5.Element.js';
|
|
7
8
|
import '../dom/p5.File.js';
|
|
8
9
|
import '../io/p5.XML.js';
|
|
9
|
-
import '../p5.Renderer-
|
|
10
|
+
import '../p5.Renderer-CQI8PO1F.js';
|
|
10
11
|
import '../image/filters.js';
|
|
11
12
|
import '../math/p5.Vector.js';
|
|
12
13
|
import '../shape/custom_shapes.js';
|
|
@@ -21,7 +22,6 @@ import '../shape/vertex.js';
|
|
|
21
22
|
import '../color/setting.js';
|
|
22
23
|
import 'omggif';
|
|
23
24
|
import '../io/csv.js';
|
|
24
|
-
import 'gifenc';
|
|
25
25
|
import '../image/pixels.js';
|
|
26
26
|
import '../core/transform.js';
|
|
27
27
|
import './GeometryBuilder.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var filterBaseFrag = "precision highp float;\n\nuniform sampler2D tex0;\nuniform vec2 canvasSize;\nuniform vec2 texelSize;\n\nIN vec2 vTexCoord;\n\nstruct FilterInputs {\n vec2 texCoord;\n vec2 canvasSize;\n vec2 texelSize;\n};\n\nvoid main(void) {\n FilterInputs inputs;\n inputs.texCoord = vTexCoord;\n inputs.canvasSize = canvasSize;\n inputs.texelSize = texelSize;\n OUT_COLOR = HOOK_getColor(inputs, tex0);\n OUT_COLOR.rgb *= outColor.a;\n}\n";
|
|
2
|
+
|
|
3
|
+
var filterBaseVert = "precision highp int;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nIN vec3 aPosition;\nIN vec2 aTexCoord;\nOUT vec2 vTexCoord;\n\nvoid main() {\n // transferring texcoords for the frag shader\n vTexCoord = aTexCoord;\n\n // copy position with a fourth coordinate for projection (1.0 is normal)\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // project to 3D space\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n}\n";
|
|
4
|
+
|
|
5
|
+
var webgl2CompatibilityShader = "#ifdef WEBGL2\n\n#define IN in\n#define OUT out\n\n#ifdef FRAGMENT_SHADER\nout vec4 outColor;\n#define OUT_COLOR outColor\n#endif\n#define TEXTURE texture\n\n#else\n\n#ifdef FRAGMENT_SHADER\n#define IN varying\n#else\n#define IN attribute\n#endif\n#define OUT varying\n#define TEXTURE texture2D\n\n#ifdef FRAGMENT_SHADER\n#define OUT_COLOR gl_FragColor\n#endif\n\n#endif\n\nvec4 getTexture(in sampler2D content, vec2 coord) {\n vec4 color = TEXTURE(content, coord);\n if (color.a > 0.) color.rgb /= color.a;\n return color;\n}\n";
|
|
6
|
+
|
|
7
|
+
export { filterBaseFrag as a, filterBaseVert as f, webgl2CompatibilityShader as w };
|
package/dist/webgpu/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import rendererWebGPU from './p5.RendererWebGPU.js';
|
|
2
|
-
import '../constants-
|
|
2
|
+
import '../constants-0wkVUfqa.js';
|
|
3
3
|
import '../webgl/enums.js';
|
|
4
4
|
import '../strands/ir_types.js';
|
|
5
5
|
import './shaders/color.js';
|
|
@@ -8,14 +8,18 @@ import './shaders/material.js';
|
|
|
8
8
|
import './shaders/font.js';
|
|
9
9
|
import './shaders/blit.js';
|
|
10
10
|
import './strands_wgslBackend.js';
|
|
11
|
+
import './shaders/functions/noise3DWGSL.js';
|
|
12
|
+
import './shaders/functions/randomWGSL.js';
|
|
13
|
+
import './shaders/functions/randomVertWGSL.js';
|
|
14
|
+
import './shaders/functions/randomComputeWGSL.js';
|
|
11
15
|
import '../strands/ir_dag.js';
|
|
12
16
|
import '../strands/strands_FES.js';
|
|
13
|
-
import '../ir_builders-
|
|
17
|
+
import '../ir_builders-C2ebb6Lu.js';
|
|
14
18
|
import '../strands/ir_cfg.js';
|
|
15
19
|
import '../strands/strands_builtins.js';
|
|
16
|
-
import './shaders/functions/noise3DWGSL.js';
|
|
17
20
|
import './shaders/filters/base.js';
|
|
18
21
|
import './shaders/imageLight.js';
|
|
22
|
+
import './shaders/compute.js';
|
|
19
23
|
|
|
20
24
|
function index(p5){
|
|
21
25
|
p5.registerAddon(rendererWebGPU);
|