Files
feuerwerk/tools/lib/shaders.mjs
T
rootandClaude Fable 5.1 a32b7c6daa
game-maker / suite (push) Failing after 4m1s
Adjust colors: brightness adds instead of multiplying (#62)
The shipped shader graph gains a `brightness - 1` offset node, so 1 stays
neutral and brightness lifts every channel by the same amount; contrast keeps
multiplying, saturation keeps mixing with the luma. Fixture, seeds, unit and
e2e expectations follow (twelve nodes, 1.25 -> #80c0ff).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-12 22:58:50 +02:00

48 lines
2.2 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 - 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'),
],
},
};
}