Files
feuerwerk/tools/lib/shaders.mjs
T
rootandClaude Fable 5.1 42cafa7543
game-maker / suite (push) Failing after 3m59s
Shader assets: graph-built shaders, the Shader tab and sprite rows from the graph (#62)
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>
2026-09-12 22:41:14 +02:00

46 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { edge, node } from './builders.mjs';
/**
* The "Adjust colors" shader as an asset document: brightness, contrast and saturation, 1 neutral,
* on the straight colour – rgb *= brightness; rgb = (rgb - 0.5) * contrast + 0.5;
* rgb = mix(luma, rgb, saturation). The recipe the built-in prototype of #62 had, now eleven nodes.
*/
export function adjustColorsShader(id = 'adjust-colors', name = 'Adjust colors') {
const property = (nodeId, propertyName, x, y) =>
node(nodeId, 'ShaderProperty', x, y, { name: propertyName, default: 1, min: 0, max: 4 });
return {
id,
type: 'shader',
name,
props: {},
graph: {
nodes: [
node(`${id}-texel`, 'ShaderTextureColor', 0, 0),
property(`${id}-brightness`, 'brightness', 0, 160),
property(`${id}-contrast`, 'contrast', 0, 320),
property(`${id}-saturation`, 'saturation', 0, 480),
node(`${id}-bright`, 'ShaderMultiply', 300, 0),
node(`${id}-shift`, 'ShaderSubtract', 560, 0, { b: 0.5 }),
node(`${id}-scale`, 'ShaderMultiply', 820, 0),
node(`${id}-centre`, 'ShaderAdd', 1080, 0, { b: 0.5 }),
node(`${id}-luma`, 'ShaderLuminance', 1340, 160),
node(`${id}-mix`, 'ShaderMix', 1600, 0),
node(`${id}-out`, 'ShaderOutput', 1860, 0),
],
edges: [
edge(`${id}-e1`, `${id}-texel`, 'color', `${id}-bright`, 'a'),
edge(`${id}-e2`, `${id}-brightness`, 'value', `${id}-bright`, 'b'),
edge(`${id}-e3`, `${id}-bright`, 'result', `${id}-shift`, 'a'),
edge(`${id}-e4`, `${id}-shift`, 'result', `${id}-scale`, 'a'),
edge(`${id}-e5`, `${id}-contrast`, 'value', `${id}-scale`, 'b'),
edge(`${id}-e6`, `${id}-scale`, 'result', `${id}-centre`, 'a'),
edge(`${id}-e7`, `${id}-centre`, 'result', `${id}-luma`, 'color'),
edge(`${id}-e8`, `${id}-luma`, 'value', `${id}-mix`, 'a'),
edge(`${id}-e9`, `${id}-centre`, 'result', `${id}-mix`, 'b'),
edge(`${id}-e10`, `${id}-saturation`, 'value', `${id}-mix`, 't'),
edge(`${id}-e11`, `${id}-mix`, 'result', `${id}-out`, 'color'),
],
},
};
}