Shader assets: graph-built shaders, the Shader tab and sprite rows from the graph (#62)
game-maker / suite (push) Failing after 3m59s
game-maker / suite (push) Failing after 3m59s
A shader is an asset carrying a node graph (Texture color, Output, Property, Color, Add/Subtract/Multiply/Divide, Mix, Luminance) that compiles to the GLSL fragment of a Pixi filter. The Shader tab reuses the Behavior canvas; a sprite wears a shader through its Shader picker, and the rows below it are the graph's Property nodes. Property schema, resolution and deviation take the project because a sprite's rows now live in another asset. The built-in registry of the prototype is gone; "Adjust colors" ships as a graph in the fixture and the three example games. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
6141d07d4f
commit
42cafa7543
62 files changed
+1682
-144
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import type { ShaderAsset } from '../core/model/Asset';
|
||||
import { findAssetOf, type Project } from '../core/model/Project';
|
||||
import { compileShader, type ShaderBuild } from '../core/shader/compile';
|
||||
import type { ShaderSource } from './shaders';
|
||||
|
||||
/**
|
||||
* Compiled shader graphs, one per asset, recompiled when the graph's content changes. A graph is
|
||||
* edited in place, so the cache keys on its serialized form rather than on its identity.
|
||||
*/
|
||||
export class ShaderLibrary {
|
||||
private readonly builds = new Map<string, { fingerprint: string; build: ShaderBuild }>();
|
||||
|
||||
buildFor(asset: ShaderAsset): ShaderBuild {
|
||||
const fingerprint = JSON.stringify(asset.graph);
|
||||
const cached = this.builds.get(asset.id);
|
||||
if (cached && cached.fingerprint === fingerprint) return cached.build;
|
||||
const build = compileShader(asset.graph);
|
||||
this.builds.set(asset.id, { fingerprint, build });
|
||||
return build;
|
||||
}
|
||||
|
||||
/** For one redraw: each asset is looked up and fingerprinted once, however many sprites wear it. */
|
||||
source(project: Project): ShaderSource {
|
||||
const seen = new Map<string, ShaderBuild | null>();
|
||||
return {
|
||||
compiled: (assetId) => {
|
||||
let build = seen.get(assetId);
|
||||
if (build === undefined) {
|
||||
const asset = findAssetOf(project, assetId, 'shader');
|
||||
build = asset ? this.buildFor(asset) : null;
|
||||
seen.set(assetId, build);
|
||||
}
|
||||
return build?.compiled ?? null;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const shaderLibrary = new ShaderLibrary();
|
||||
Reference in new issue
Block a user