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
1,482 changes: 1,437 additions & 45 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shaderfrog/core",
"version": "3.2.0",
"version": "4.0.0",
"description": "Shaderfrog core",
"type": "module",
"files": [
Expand Down Expand Up @@ -37,8 +37,10 @@
"@shaderfrog/glsl-parser": "^7.0.1",
"@swc/core": "^1.6.7",
"@types/lodash.groupby": "^4.6.7",
"@types/node": "^20.1.2",
"@types/three": "^0.169.0",
"babylonjs": "^6.2.0",
"playcanvas": "^1.65.3",
"prettier": "^3.3.2",
"three": "^0.169.0",
"typescript": "^5.5.3",
Expand Down
38 changes: 16 additions & 22 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ export type PhongNodeConstructor = (
name: string,
position: NodePosition,
uniforms: UniformDataType[],
stage: ShaderStage | undefined
stage: ShaderStage | undefined,
) => CodeNode;

export type PhysicalNodeConstructor = (
id: string,
name: string,
position: NodePosition,
uniforms: UniformDataType[],
stage: ShaderStage | undefined
stage: ShaderStage | undefined,
) => CodeNode;

export type ToonNodeConstructor = (
id: string,
name: string,
position: NodePosition,
uniforms: UniformDataType[],
stage: ShaderStage | undefined
stage: ShaderStage | undefined,
) => CodeNode;

export interface Engine {
Expand Down Expand Up @@ -90,18 +90,12 @@ export type EngineContext<T = any> = {
engine: string;
nodes: Record<string, NodeContext>;
runtime: T;
debuggingNonsense: {
vertexSource?: string;
vertexPreprocessed?: string;
fragmentPreprocessed?: string;
fragmentSource?: string;
};
};

export const extendNodeContext = (
context: EngineContext,
nodeId: string,
nodeContext: Partial<NodeContext>
nodeContext: Partial<NodeContext>,
) => ({
...context,
nodes: {
Expand All @@ -114,7 +108,7 @@ export const extendNodeContext = (
});
export const extendNodesContext = (
context: EngineContext,
nodesContext: NodeContexts
nodesContext: NodeContexts,
) => ({
...context,
nodes: {
Expand All @@ -128,7 +122,7 @@ export type EngineImporter = {
ast: Program,
options?: Record<string, unknown> & {
type?: ShaderStage;
}
},
): void;
nodeInputMap: Partial<Record<EngineNodeType, Record<string, string | null>>>;
edgeMap: { [oldInput: string]: string };
Expand All @@ -143,7 +137,7 @@ export type EngineImporters = {

export const convertNode = (
node: SourceNode,
converter: EngineImporter
converter: EngineImporter,
): SourceNode => {
log(`Converting ${node.name} (${node.id})`);
const preprocessed = preprocess(node.source, {
Expand All @@ -166,12 +160,12 @@ export const convertNode = (
export const convertToEngine = (
oldEngine: Engine,
newEngine: Engine,
graph: Graph
graph: Graph,
): Graph => {
const converter = newEngine.importers[oldEngine.name];
if (!converter) {
throw new Error(
`The engine ${newEngine.name} has no importer for ${oldEngine.name}`
`The engine ${newEngine.name} has no importer for ${oldEngine.name}`,
);
}

Expand All @@ -194,12 +188,12 @@ export const convertToEngine = (
source.name,
source.position,
source.config.uniforms,
source.stage
source.stage,
);
// Bail if no conversion
} else {
throw new Error(
`Can't convert ${oldEngine.name} to ${newEngine.name} because ${newEngine.name} does not have a "${node.type}" constructor`
`Can't convert ${oldEngine.name} to ${newEngine.name} because ${newEngine.name} does not have a "${node.type}" constructor`,
);
}
} else if (NodeType.SOURCE === node.type) {
Expand All @@ -224,7 +218,7 @@ export const convertToEngine = (
edge.input,
'as there is no edge mapping in the',
newEngine.name,
'importer'
'importer',
);
edgeUpdates[edge.id] = null;
}
Expand Down Expand Up @@ -277,7 +271,7 @@ export type DefaultPropertySetter = (p: NodeProperty) => any;
export const collectInitialEvaluatedGraphProperties = (
engine: Engine,
graph: Graph,
defaultPropertySetting: DefaultPropertySetter
defaultPropertySetting: DefaultPropertySetter,
) => {
const graphProperties: Record<string, any> = {};

Expand All @@ -294,7 +288,7 @@ export const collectInitialEvaluatedGraphProperties = (
// predicate search enforces
const input = i as NodeInput & { property: string };
const edge = graph.edges.find(
({ to, input: i }) => to === node.id && i === input.id
({ to, input: i }) => to === node.id && i === input.id,
);
// In the case where a node has been deleted from the graph,
// dataInputs won't have been udpated until a recompile completes
Expand All @@ -306,7 +300,7 @@ export const collectInitialEvaluatedGraphProperties = (
// Find the corresponding property on the node and get the default
// setting
const property = (node.config.properties || []).find(
(p) => p.property === input.property
(p) => p.property === input.property,
);
if (property) {
graphProperties[input.property] = defaultPropertySetting(property);
Expand All @@ -320,7 +314,7 @@ export const collectInitialEvaluatedGraphProperties = (
graphProperties[input.property] = evaluateNode(
engine,
graph,
fromNode
fromNode,
);
} catch (err) {
console.error('Tried to evaluate a non-data node!', {
Expand Down
7 changes: 0 additions & 7 deletions src/graph/graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};

const result = await compileSource(graph, engine, engineContext);
Expand Down Expand Up @@ -236,7 +235,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};

const result = await compileSource(graph, engine, engineContext);
Expand Down Expand Up @@ -313,7 +311,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};
const preserver = { ...engine, preserve: new Set<string>(['vUv']) };

Expand Down Expand Up @@ -388,7 +385,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};

const result = await compileSource(graph, engine, engineContext);
Expand Down Expand Up @@ -449,7 +445,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};

const result = await compileSource(graph, engine, engineContext);
Expand Down Expand Up @@ -503,7 +498,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};

const result = await compileSource(graph, engine, engineContext);
Expand Down Expand Up @@ -546,7 +540,6 @@ void main() {
engine: 'three',
nodes: {},
runtime: {},
debuggingNonsense: {},
};

const result = await compileSource(graph, engine, engineContext);
Expand Down
Loading
Loading