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 - 1; rgb = (rgb - 0.5) * contrast + 0.5; * rgb = mix(luma, rgb, saturation). Brightness adds (user decision, #62 follow-up), so 1 is +0. */ 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}-offset`, 'ShaderSubtract', 260, 160, { b: 1 }), node(`${id}-bright`, 'ShaderAdd', 520, 0), node(`${id}-shift`, 'ShaderSubtract', 780, 0, { b: 0.5 }), node(`${id}-scale`, 'ShaderMultiply', 1040, 0), node(`${id}-centre`, 'ShaderAdd', 1300, 0, { b: 0.5 }), node(`${id}-luma`, 'ShaderLuminance', 1560, 160), node(`${id}-mix`, 'ShaderMix', 1820, 0), node(`${id}-out`, 'ShaderOutput', 2080, 0), ], edges: [ edge(`${id}-e1`, `${id}-texel`, 'color', `${id}-bright`, 'a'), edge(`${id}-e2`, `${id}-brightness`, 'value', `${id}-offset`, 'a'), edge(`${id}-e12`, `${id}-offset`, 'result', `${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'), ], }, }; } /** * A blur in two passes as a shader graph (#301): a Blur across into a Pass at `resolution`, its * picture blurred down into the Output. Below full resolution an open Pass shrinks the picture * first, so both Blurs read pixels of that size and reach `radius` times 2 (half) or 4 (quarter). * `clocked` ties the radius to Time (times 0), which leaves the pixels alone but draws the Passes * again every frame – a still one is drawn once. */ export function twoPassBlurGraph(radius, resolution = 'full', clocked = false) { const shrunk = resolution !== 'full'; return { nodes: [ ...(shrunk ? [node('tp-shrink', 'ShaderPass', -260, 0, { resolution })] : []), ...(clocked ? [ node('tp-time', 'ShaderTime', 0, 200), node('tp-still', 'ShaderMultiply', 260, 200, { b: 0 }), node('tp-radius', 'ShaderAdd', 520, 200, { b: radius }), ] : []), node('tp-across', 'ShaderBlur', 0, 0, { radius, direction: 'horizontal' }), node('tp-pass', 'ShaderPass', 260, 0, { resolution }), node('tp-down', 'ShaderBlur', 520, 0, { radius, direction: 'vertical' }), node('tp-out', 'ShaderOutput', 780, 0), ], edges: [ ...(clocked ? [ edge('tp-e1', 'tp-time', 'value', 'tp-still', 'a'), edge('tp-e2', 'tp-still', 'result', 'tp-radius', 'a'), edge('tp-e3', 'tp-radius', 'result', 'tp-across', 'radius'), edge('tp-e4', 'tp-radius', 'result', 'tp-down', 'radius'), ] : []), ...(shrunk ? [edge('tp-e0', 'tp-shrink', 'picture', 'tp-across', 'picture')] : []), edge('tp-e5', 'tp-across', 'color', 'tp-pass', 'color'), edge('tp-e6', 'tp-across', 'alpha', 'tp-pass', 'alpha'), edge('tp-e7', 'tp-pass', 'picture', 'tp-down', 'picture'), edge('tp-e8', 'tp-down', 'color', 'tp-out', 'color'), edge('tp-e9', 'tp-down', 'alpha', 'tp-out', 'alpha'), ], }; }