@oeave/bakery3 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/bake/index.d.ts +3 -3
- package/dist/bake/index.js +4 -4
- package/dist/{bake-DaOlenyx.d.ts → bake-DZ-CJR6f.d.ts} +8 -1
- package/dist/catalog/index.d.ts +5 -5
- package/dist/catalog/index.js +3 -3
- package/dist/{chunk-TGFNQBKC.js → chunk-3T3FJOSD.js} +5 -5
- package/dist/chunk-3T3FJOSD.js.map +1 -0
- package/dist/{chunk-V3QINEEG.js → chunk-62M6XXNX.js} +58 -3
- package/dist/chunk-62M6XXNX.js.map +1 -0
- package/dist/{chunk-ARMTTZXZ.js → chunk-6FAMQZXB.js} +8 -8
- package/dist/chunk-6FAMQZXB.js.map +1 -0
- package/dist/{chunk-54WJDN5R.js → chunk-CSSJRP5W.js} +9 -6
- package/dist/chunk-CSSJRP5W.js.map +1 -0
- package/dist/{chunk-W6WQ5UP7.js → chunk-EN4ROBYQ.js} +32 -5
- package/dist/chunk-EN4ROBYQ.js.map +1 -0
- package/dist/chunk-KZLVTSBI.js +191 -0
- package/dist/chunk-KZLVTSBI.js.map +1 -0
- package/dist/{chunk-MD2U6S4N.js → chunk-LAKXC4WR.js} +218 -142
- package/dist/chunk-LAKXC4WR.js.map +1 -0
- package/dist/{chunk-HQTUFVMM.js → chunk-NEK5TBEH.js} +3 -3
- package/dist/chunk-NEK5TBEH.js.map +1 -0
- package/dist/chunk-OPM2L63B.js +253 -0
- package/dist/chunk-OPM2L63B.js.map +1 -0
- package/dist/{chunk-APBOWWSV.js → chunk-R5IUPOWI.js} +3 -3
- package/dist/chunk-R5IUPOWI.js.map +1 -0
- package/dist/{chunk-6YVQANMW.js → chunk-STRK4SZN.js} +262 -16
- package/dist/chunk-STRK4SZN.js.map +1 -0
- package/dist/{chunk-CX4WTVGH.js → chunk-WLEFNUOH.js} +411 -371
- package/dist/chunk-WLEFNUOH.js.map +1 -0
- package/dist/{chunk-25ZXSVQ3.js → chunk-X6GW43EX.js} +3 -3
- package/dist/{chunk-25ZXSVQ3.js.map → chunk-X6GW43EX.js.map} +1 -1
- package/dist/{chunk-WBIAFIHV.js → chunk-XK35ANPJ.js} +3 -3
- package/dist/{chunk-WBIAFIHV.js.map → chunk-XK35ANPJ.js.map} +1 -1
- package/dist/devtools/index.d.ts +3 -3
- package/dist/devtools/index.js +10 -9
- package/dist/hotspots/index.d.ts +237 -31
- package/dist/hotspots/index.js +1013 -118
- package/dist/hotspots/index.js.map +1 -1
- package/dist/index.d.ts +39 -8
- package/dist/index.js +11 -10
- package/dist/node/index.cjs +266 -141
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +152 -87
- package/dist/node/index.d.ts +27 -6
- package/dist/node/index.js +52 -3
- package/dist/node/index.js.map +1 -1
- package/dist/{prepare-C5qVvaw4.d.ts → prepare-BtjY4G3q.d.ts} +1 -1
- package/dist/presets/index.d.ts +37 -1
- package/dist/presets/index.js +4 -4
- package/dist/presets/index.js.map +1 -1
- package/dist/r3f/index.d.ts +4 -4
- package/dist/r3f/index.js +13 -12
- package/dist/r3f/index.js.map +1 -1
- package/dist/{room-S5TLCK4F.js → room-BM7Z7NKG.js} +6 -6
- package/dist/{room-S5TLCK4F.js.map → room-BM7Z7NKG.js.map} +1 -1
- package/dist/{rooms.gen-vhj6sFW5.d.ts → rooms.gen-DItzBR9k.d.ts} +112 -84
- package/dist/session-NPVBESWA.js +9 -0
- package/dist/{session-YCQS4MRH.js.map → session-NPVBESWA.js.map} +1 -1
- package/dist/{testRun-BIPXaVPb.d.ts → testRun-20OARnQr.d.ts} +12 -3
- package/dist/tsl/index.d.ts +14 -1
- package/dist/tsl/index.js +8 -2
- package/dist/tsl/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-54WJDN5R.js.map +0 -1
- package/dist/chunk-6YVQANMW.js.map +0 -1
- package/dist/chunk-AF5BIELI.js +0 -70
- package/dist/chunk-AF5BIELI.js.map +0 -1
- package/dist/chunk-APBOWWSV.js.map +0 -1
- package/dist/chunk-ARMTTZXZ.js.map +0 -1
- package/dist/chunk-CX4WTVGH.js.map +0 -1
- package/dist/chunk-HQTUFVMM.js.map +0 -1
- package/dist/chunk-MD2U6S4N.js.map +0 -1
- package/dist/chunk-TGFNQBKC.js.map +0 -1
- package/dist/chunk-V3QINEEG.js.map +0 -1
- package/dist/chunk-W6WQ5UP7.js.map +0 -1
- package/dist/session-YCQS4MRH.js +0 -9
package/dist/tsl/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerBuiltin, registerNodeObject, BAKERY_NODE_MARKER } from '../chunk-S4AJTLLN.js';
|
|
2
|
-
import { time, deltaTime, float, positionWorld, positionLocal, positionView, normalWorld, normalView, positionViewDirection, cameraPosition, mx_fractal_noise_float, sqrt, mx_worley_noise_float, sin, clamp, fract, smoothstep, mx_cell_noise_float, vec3, dot, pow, mix, vec4 } from 'three/tsl';
|
|
2
|
+
import { time, deltaTime, float, positionWorld, positionLocal, positionView, normalWorld, normalView, positionViewDirection, cameraPosition, mx_fractal_noise_float, sqrt, mx_worley_noise_float, sin, clamp, fract, smoothstep, mx_cell_noise_float, vec3, materialReference, dot, pow, mix, vec4 } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
var asNode = (value) => ({
|
|
5
5
|
uuid: value?.uuid
|
|
@@ -217,6 +217,12 @@ function bakeryWireframe(options = {}) {
|
|
|
217
217
|
})
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
+
function bakeryEmissiveIntensity() {
|
|
221
|
+
return mark(materialReference("emissiveIntensity", "float"), {
|
|
222
|
+
op: "const",
|
|
223
|
+
params: { value: 1, type: "float" }
|
|
224
|
+
});
|
|
225
|
+
}
|
|
220
226
|
function bakeryFresnel(ior = 1.45) {
|
|
221
227
|
const f0 = ((1 - ior) / (1 + ior)) ** 2;
|
|
222
228
|
const facing = clamp(dot(normalView, positionViewDirection), 0, 1);
|
|
@@ -305,6 +311,6 @@ function bakeryHueSaturation(color, options = {}) {
|
|
|
305
311
|
});
|
|
306
312
|
}
|
|
307
313
|
|
|
308
|
-
export { bakeryAmbientOcclusion, bakeryBevel, bakeryBlackbody, bakeryBrickTexture, bakeryBrightnessContrast, bakeryColorRamp, bakeryFresnel, bakeryGamma, bakeryGradientTexture, bakeryHueSaturation, bakeryLayerWeight, bakeryMagicTexture, bakeryNoiseTexture, bakeryPointiness, bakeryVoronoiTexture, bakeryWaveTexture, bakeryWhiteNoise, bakeryWireframe };
|
|
314
|
+
export { bakeryAmbientOcclusion, bakeryBevel, bakeryBlackbody, bakeryBrickTexture, bakeryBrightnessContrast, bakeryColorRamp, bakeryEmissiveIntensity, bakeryFresnel, bakeryGamma, bakeryGradientTexture, bakeryHueSaturation, bakeryLayerWeight, bakeryMagicTexture, bakeryNoiseTexture, bakeryPointiness, bakeryVoronoiTexture, bakeryWaveTexture, bakeryWhiteNoise, bakeryWireframe };
|
|
309
315
|
//# sourceMappingURL=index.js.map
|
|
310
316
|
//# sourceMappingURL=index.js.map
|
package/dist/tsl/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tsl/index.ts"],"names":[],"mappings":";;;AA6DA,IAAM,MAAA,GAAS,CAAC,KAAA,MAAoB;AAAA,EAClC,MAAO,KAAA,EAA6B;AACtC,CAAA,CAAA;AAEA,eAAA,CAAgB,MAAA,CAAO,aAAa,CAAA,EAAG;AAAA,EACrC,EAAA,EAAI,UAAA;AAAA,EACJ,MAAA,EAAQ,OAAO,EAAE,KAAA,EAAO,OAAA,EAAQ;AAClC,CAAC,CAAA;AACD,eAAA,CAAgB,MAAA,CAAO,aAAa,CAAA,EAAG;AAAA,EACrC,EAAA,EAAI,UAAA;AAAA,EACJ,MAAA,EAAQ,OAAO,EAAE,KAAA,EAAO,OAAA,EAAQ;AAClC,CAAC,CAAA;AACD,eAAA,CAAgB,MAAA,C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aAAa,QAAA,GAAW,GAAA;AAClC,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI,CAAC,EAAE,GAAA,CAAI,CAAC,CAAA,EAAG,CAAA,EAAG,GAAG,CAAA;AACjD,EAAA,OAAO,KAAe,OAAA,EAAS;AAAA,IAC7B,EAAA,EAAI,wBAAA;AAAA,IACJ,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAA,CAAM,UAAU,CAAA,EAAG,KAAA,CAAM,QAAQ,CAAC;AAAA,GACnD,CAAA;AACH;AAIO,SAAS,mBAAA,CACd,KAAA,EACA,OAAA,GAKI,EAAC,EACK;AACV,EAAA,MAAM,EAAE,MAAM,GAAA,EAAK,UAAA,GAAa,GAAG,KAAA,GAAQ,CAAA,EAAG,GAAA,GAAM,CAAA,EAAE,GAAI,OAAA;AAC1D,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,GAAA,CAAI,KAAK,CAAA;AAC9B,EAAA,MAAM,OAAO,GAAA,CAAI,MAAA,EAAQ,KAAK,MAAA,EAAQ,MAAA,EAAQ,MAAM,CAAC,CAAA;AACrD,EAAA,MAAM,QAAA,GAAW,IAAI,IAAA,CAAK,IAAA,EAAM,MAAM,IAAI,CAAA,EAAG,QAAQ,UAAU,CAAA;AAC/D,EAAA,MAAM,OAAA,GAAU,GAAA,CAAI,KAAA,EAAO,QAAA,EAAU,GAAG,CAAA;AACxC,EAAA,OAAO,KAAe,OAAA,EAAS;AAAA,IAC7B,EAAA,EAAI,QAAA;AAAA,IACJ,MAAA,EAAQ,CAAC,KAAK,CAAA;AAAA,IACd,QAAQ,MAAA,CAAO,EAAE,KAAK,UAAA,EAAY,KAAA,EAAO,KAAK;AAAA,GAC/C,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * @oeave/bakery3/tsl: the renderer's shading vocabulary, usable from TSL.\n *\n * Two things happen here, and importing this module is what turns both on:\n *\n * 1. Registration. TSL's anonymous singletons (`positionWorld`, `time`,\n * `cameraPosition`) carry no recognizable structure, so the extractor can\n * only know them by being introduced. This module imports them from\n * `three/tsl` and registers them by uuid. It is its own entry point\n * because it needs three r170 (one of the nodes it imports is not\n * exported before that); the core SDK keeps working for anyone older.\n *\n * 2. Renderer-only nodes. The renderer has procedural textures and shading\n * inputs a browser cannot compute: traced ambient occlusion, shade-time\n * bevel, pointiness, the classic noise textures. Each function below\n * returns a real TSL node that draws an approximation in the WebGPU\n * viewport and carries a marker the extractor serializes exactly for the\n * render. The viewport is the sketch; the render is the real one.\n * `check()` reports their use as info, never as an error.\n *\n * Everything accepts plain numbers for its dials, and a TSL expression for\n * its coordinate input. Dials are baked into the manifest, so a dial driven\n * by another node is not accepted, rather than accepted and ignored.\n */\n\nimport {\n clamp,\n dot,\n float,\n fract,\n mix,\n mx_cell_noise_float,\n mx_fractal_noise_float,\n mx_worley_noise_float,\n normalView,\n normalWorld,\n positionLocal,\n positionView,\n positionViewDirection,\n positionWorld,\n cameraPosition,\n pow,\n sin,\n smoothstep,\n sqrt,\n time,\n deltaTime,\n vec3,\n vec4,\n} from 'three/tsl';\nimport {\n BAKERY_NODE_MARKER,\n registerBuiltin,\n registerNodeObject,\n type BakeryNodeMarker,\n} from '../shader/registry.js';\n\n// ---------------------------------------------------------------------------\n// Registration, on import\n// ---------------------------------------------------------------------------\n\nconst asNode = (value: unknown) => ({\n uuid: (value as { uuid?: string })?.uuid,\n});\n\nregisterBuiltin(asNode(positionWorld), {\n op: 'position',\n params: () => ({ space: 'world' }),\n});\nregisterBuiltin(asNode(positionLocal), {\n op: 'position',\n params: () => ({ space: 'local' }),\n});\nregisterBuiltin(asNode(positionView), {\n op: 'position',\n params: () => ({ space: 'view' }),\n});\nregisterBuiltin(asNode(normalWorld), {\n op: 'normal',\n params: () => ({ space: 'world' }),\n});\nregisterBuiltin(asNode(normalView), {\n op: 'normal',\n params: () => ({ space: 'view' }),\n});\nregisterBuiltin(asNode(positionViewDirection), { op: 'view_direction' });\nregisterBuiltin(asNode(cameraPosition), { op: 'camera_position' });\n// Time is a uniform like any other: baked to the moment of capture. Reading\n// `.value` lazily matters: import time is not capture time.\nregisterBuiltin(asNode(time), {\n op: 'uniform',\n params: () => ({\n value: (time as { value?: number }).value ?? 0,\n type: 'float',\n name: 'time',\n }),\n});\nregisterBuiltin(asNode(deltaTime), {\n op: 'uniform',\n params: () => ({\n value: (deltaTime as { value?: number }).value ?? 0,\n type: 'float',\n name: 'deltaTime',\n }),\n});\n\nregisterNodeObject((value) => {\n // `float()` runs plain numbers through TSL's own const-node machinery,\n // which is exactly what Fn expansion needs; nodes pass through untouched.\n return typeof value === 'number' ? float(value) : value;\n});\n\n// ---------------------------------------------------------------------------\n// The marker\n// ---------------------------------------------------------------------------\n\n// Every type here is derived from a `three/tsl` export, so the published\n// declarations name no file inside three's own source tree. Those paths are\n// one @types/three release's layout: a declaration that imported them would\n// fail to compile under `skipLibCheck: false` against any other. Derived\n// this way, a node type is whatever the developer's own @types/three says\n// `float()` and `vec3()` return.\ntype TSLExpr = ReturnType<typeof float>;\ntype Coord = TSLExpr | null | undefined;\n/** A float node: a mask, a factor, a texture's fac output. */\ntype FloatNode = ReturnType<typeof float>;\n/** A three-component node: a color or a normal. */\ntype Vec3Node = ReturnType<typeof vec3>;\n/** A color with alpha. */\ntype Vec4Node = ReturnType<typeof vec4>;\n\nfunction mark<T>(node: unknown, marker: BakeryNodeMarker): T {\n (node as Record<string, unknown>)[BAKERY_NODE_MARKER] = marker;\n return node as T;\n}\n\n/** The renderer's procedural textures default to object-space coordinates;\n * object-space position is the closest thing a live three scene has. */\nconst defaultCoord = () => positionLocal;\n\nconst params = (\n entries: Record<string, number | string | boolean | number[] | undefined>,\n): Record<string, number | string | boolean | number[]> => {\n const out: Record<string, number | string | boolean | number[]> = {};\n for (const [key, value] of Object.entries(entries)) {\n if (value !== undefined) out[key] = value;\n }\n return out;\n};\n\n// ---------------------------------------------------------------------------\n// Procedural textures\n// ---------------------------------------------------------------------------\n\nexport type NoiseTextureOptions = {\n scale?: number;\n detail?: number;\n roughness?: number;\n lacunarity?: number;\n distortion?: number;\n dimensions?: 2 | 3 | 4;\n};\n\n/**\n * The renderer's fractal noise texture. Preview: MaterialX fractal noise,\n * the same character on a different lattice.\n */\nexport function bakeryNoiseTexture(\n coord?: Coord,\n options: NoiseTextureOptions = {},\n): FloatNode {\n const {\n scale = 5,\n detail = 2,\n roughness = 0.5,\n lacunarity = 2,\n distortion = 0,\n } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const preview = mx_fractal_noise_float(\n p,\n Math.max(1, Math.round(detail)),\n lacunarity,\n roughness,\n )\n .mul(0.5)\n .add(0.5);\n return mark<FloatNode>(preview, {\n op: 'bk_noise_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n scale,\n detail,\n roughness,\n lacunarity,\n distortion,\n dimensions: options.dimensions ?? 3,\n }),\n });\n}\n\nexport type VoronoiTextureOptions = {\n scale?: number;\n randomness?: number;\n feature?: 'F1' | 'F2' | 'SMOOTH_F1' | 'DISTANCE_TO_EDGE';\n metric?: 'EUCLIDEAN' | 'MANHATTAN' | 'CHEBYCHEV';\n dimensions?: 2 | 3 | 4;\n};\n\n/** The renderer's Voronoi texture (distance output). Preview: MaterialX Worley. */\nexport function bakeryVoronoiTexture(\n coord?: Coord,\n options: VoronoiTextureOptions = {},\n): FloatNode {\n const { scale = 5, randomness = 1 } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n // three's Worley is the SQUARED distance; the renderer's Voronoi is the\n // distance itself.\n const preview = sqrt(mx_worley_noise_float(p, float(randomness)));\n return mark<FloatNode>(preview, {\n op: 'bk_voronoi_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n scale,\n randomness,\n feature: options.feature ?? 'F1',\n metric: options.metric ?? 'EUCLIDEAN',\n dimensions: options.dimensions ?? 3,\n }),\n });\n}\n\nexport type WaveTextureOptions = {\n scale?: number;\n distortion?: number;\n detail?: number;\n detailScale?: number;\n detailRoughness?: number;\n phase?: number;\n type?: 'BANDS' | 'RINGS';\n direction?: 'X' | 'Y' | 'Z' | 'DIAGONAL';\n profile?: 'SIN' | 'SAW' | 'TRI';\n};\n\n/** The renderer's wave texture. Preview: a sine along the chosen axis. */\nexport function bakeryWaveTexture(\n coord?: Coord,\n options: WaveTextureOptions = {},\n): FloatNode {\n const { scale = 5, phase = 0, direction = 'X' } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const axis =\n direction === 'Y'\n ? p.y\n : direction === 'Z'\n ? p.z\n : direction === 'DIAGONAL'\n ? p.x.add(p.y).add(p.z)\n : p.x;\n const preview = sin(axis.add(phase)).mul(0.5).add(0.5);\n return mark<FloatNode>(preview, {\n op: 'bk_wave_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n scale,\n distortion: options.distortion ?? 0,\n detail: options.detail ?? 2,\n detail_scale: options.detailScale ?? 1,\n detail_roughness: options.detailRoughness ?? 0.5,\n phase,\n type: options.type ?? 'BANDS',\n direction,\n profile: options.profile ?? 'SIN',\n }),\n });\n}\n\nexport type MagicTextureOptions = {\n scale?: number;\n distortion?: number;\n depth?: number;\n};\n\n/** The renderer's interference \"magic\" texture. Preview: interfering sines,\n * the flavor and not the math. */\nexport function bakeryMagicTexture(\n coord?: Coord,\n options: MagicTextureOptions = {},\n): FloatNode {\n const { scale = 5, distortion = 1 } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const preview = sin(p.x.add(sin(p.y.mul(distortion))))\n .mul(0.5)\n .add(0.5);\n return mark<FloatNode>(preview, {\n op: 'bk_magic_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({ scale, distortion, depth: options.depth ?? 2 }),\n });\n}\n\nexport type GradientType =\n | 'LINEAR'\n | 'QUADRATIC'\n | 'EASING'\n | 'DIAGONAL'\n | 'SPHERICAL'\n | 'QUADRATIC_SPHERE'\n | 'RADIAL';\n\nexport type GradientTextureOptions = { type?: GradientType };\n\n/** The renderer's gradient texture. Preview: the linear ramp. */\nexport function bakeryGradientTexture(\n coord?: Coord,\n options: GradientTextureOptions = {},\n): FloatNode {\n const p = coord ?? defaultCoord();\n const preview = clamp(p.x, 0, 1);\n return mark<FloatNode>(preview, {\n op: 'bk_gradient_texture',\n inputs: [p],\n params: params({ gradient_type: options.type ?? 'LINEAR' }),\n });\n}\n\nexport type BrickTextureOptions = {\n offset?: number;\n offsetFrequency?: number;\n squash?: number;\n squashFrequency?: number;\n scale?: number;\n mortarSize?: number;\n mortarSmooth?: number;\n bias?: number;\n brickWidth?: number;\n rowHeight?: number;\n};\n\n/** The renderer's brick texture (fac output, the mortar mask). Preview: a grid. */\nexport function bakeryBrickTexture(\n coord?: Coord,\n options: BrickTextureOptions = {},\n): FloatNode {\n const {\n scale = 5,\n mortarSize = 0.02,\n rowHeight = 0.25,\n brickWidth = 0.5,\n } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const gx = fract(p.x.div(brickWidth));\n const gy = fract(p.y.div(rowHeight));\n const edge = float(1).sub(\n smoothstep(\n 0,\n mortarSize * 4,\n gx.min(float(1).sub(gx)).min(gy.min(float(1).sub(gy))),\n ),\n );\n return mark<FloatNode>(edge, {\n op: 'bk_brick_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n offset: options.offset ?? 0.5,\n offset_frequency: options.offsetFrequency ?? 2,\n squash: options.squash ?? 1,\n squash_frequency: options.squashFrequency ?? 2,\n scale,\n mortar_size: mortarSize,\n mortar_smooth: options.mortarSmooth ?? 0.1,\n bias: options.bias ?? 0,\n brick_width: brickWidth,\n row_height: rowHeight,\n }),\n });\n}\n\n/** White noise, a hash of the coordinate. Preview: cell noise. */\nexport function bakeryWhiteNoise(\n coord?: Coord,\n options: { dimensions?: 2 | 3 | 4 } = {},\n): FloatNode {\n const p = coord ?? defaultCoord();\n const preview = mx_cell_noise_float(p.mul(1024));\n return mark<FloatNode>(preview, {\n op: 'bk_white_noise',\n inputs: [p],\n params: params({ dimensions: options.dimensions ?? 3 }),\n });\n}\n\n// ---------------------------------------------------------------------------\n// Shading inputs the browser cannot compute\n// ---------------------------------------------------------------------------\n\n/**\n * Traced ambient occlusion. The browser has no rays, so the preview is plain\n * white, which is exactly what an unoccluded surface reads as. The render\n * traces the real thing.\n */\nexport function bakeryAmbientOcclusion(\n options: { distance?: number; samples?: number; onlyLocal?: boolean } = {},\n): FloatNode {\n const preview = float(1);\n return mark<FloatNode>(preview, {\n op: 'bk_ambient_occlusion',\n params: params({\n distance: options.distance ?? 1,\n samples: options.samples ?? 16,\n only_local: options.onlyLocal ?? false,\n }),\n });\n}\n\n/**\n * Shade-time edge rounding. Preview: the unrounded normal, so geometry looks\n * crisp in the viewport and gets the worn edge in the render.\n */\nexport function bakeryBevel(\n options: { radius?: number; samples?: number } = {},\n): Vec3Node {\n const preview = normalWorld;\n return mark<Vec3Node>(vec3(preview), {\n op: 'bk_bevel',\n params: params({\n radius: options.radius ?? 0.05,\n samples: options.samples ?? 4,\n }),\n });\n}\n\n/** Surface curvature: concave 0, flat 0.5, convex 1. Preview: flat 0.5. */\nexport function bakeryPointiness(): FloatNode {\n return mark<FloatNode>(float(0.5), { op: 'bk_pointiness' });\n}\n\n/** 1 on triangle edges. Preview: 0, no wires in the viewport. */\nexport function bakeryWireframe(\n options: { size?: number; pixelSize?: boolean } = {},\n): FloatNode {\n return mark<FloatNode>(float(0), {\n op: 'bk_wireframe',\n params: params({\n size: options.size ?? 0.01,\n pixel_size: options.pixelSize ?? false,\n }),\n });\n}\n\n/** Physically correct fresnel. Preview: Schlick's approximation, close enough\n * that the viewport and the render agree on where the rim light lives. */\nexport function bakeryFresnel(ior: number = 1.45): FloatNode {\n const f0 = ((1 - ior) / (1 + ior)) ** 2;\n const facing = clamp(dot(normalView, positionViewDirection), 0, 1);\n const preview = float(f0).add(\n float(1 - f0).mul(pow(float(1).sub(facing), 5)),\n );\n return mark<FloatNode>(preview, { op: 'bk_fresnel', inputs: [float(ior)] });\n}\n\n/** A facing/fresnel layer weight. Preview: the facing term it is built from. */\nexport function bakeryLayerWeight(\n blend: number = 0.5,\n options: { output?: 'FRESNEL' | 'FACING' } = {},\n): FloatNode {\n const facing = float(1).sub(\n clamp(dot(normalView, positionViewDirection), 0, 1),\n );\n return mark<FloatNode>(facing, {\n op: 'bk_layer_weight',\n inputs: [float(blend)],\n params: params({ output: options.output ?? 'FACING' }),\n });\n}\n\n// ---------------------------------------------------------------------------\n// Color tools\n// ---------------------------------------------------------------------------\n\nexport type ColorRampStop = {\n position: number;\n color: [number, number, number] | [number, number, number, number];\n};\n\n/**\n * A color ramp. Preview: the same ramp, rebuilt from mix chains; for LINEAR\n * and CONSTANT interpolation the viewport matches the render.\n */\nexport function bakeryColorRamp(\n fac: TSLExpr,\n stops: ColorRampStop[],\n options: { interpolation?: 'LINEAR' | 'CONSTANT' } = {},\n): Vec4Node {\n if (stops.length < 1)\n throw new Error('bakeryColorRamp needs at least one stop.');\n const sorted = [...stops].sort((a, b) => a.position - b.position);\n const rgba = (stop: ColorRampStop) =>\n vec4(stop.color[0], stop.color[1], stop.color[2], stop.color[3] ?? 1);\n\n let preview = rgba(sorted[0]!) as unknown as ReturnType<typeof mix>;\n for (let i = 1; i < sorted.length; i++) {\n const previous = sorted[i - 1]!;\n const current = sorted[i]!;\n const span = Math.max(current.position - previous.position, 1e-5);\n const t =\n (options.interpolation ?? 'LINEAR') === 'CONSTANT'\n ? smoothstep(current.position - 1e-5, current.position, fac)\n : clamp(fac.sub(previous.position).div(span), 0, 1);\n preview = mix(preview, rgba(current), t);\n }\n\n const flat: number[] = [];\n for (const stop of sorted) {\n flat.push(\n stop.position,\n stop.color[0],\n stop.color[1],\n stop.color[2],\n stop.color[3] ?? 1,\n );\n }\n return mark<Vec4Node>(preview, {\n op: 'bk_color_ramp',\n inputs: [fac],\n params: params({\n interpolation: options.interpolation ?? 'LINEAR',\n stops: flat,\n }),\n });\n}\n\n/** Blackbody temperature to color. Preview: a two-anchor tint, warm below\n * and cool above. */\nexport function bakeryBlackbody(kelvin: number = 5000): Vec3Node {\n const t = smoothstep(2000, 10000, float(kelvin));\n const preview = mix(vec3(1.0, 0.58, 0.27), vec3(0.78, 0.85, 1.0), t);\n return mark<Vec3Node>(preview, {\n op: 'bk_blackbody',\n inputs: [float(kelvin)],\n });\n}\n\n/** A gamma curve. The preview is the same math. */\nexport function bakeryGamma(color: TSLExpr, gamma: number = 1): Vec3Node {\n const preview = pow(color, vec3(gamma, gamma, gamma));\n return mark<Vec3Node>(preview, {\n op: 'bk_gamma',\n inputs: [color, float(gamma)],\n });\n}\n\n/** Brightness/contrast. Preview: the same formula the render uses. */\nexport function bakeryBrightnessContrast(\n color: TSLExpr,\n options: { brightness?: number; contrast?: number } = {},\n): Vec3Node {\n const { brightness = 0, contrast = 0 } = options;\n const a = 1 + contrast;\n const b = brightness - contrast * 0.5;\n const preview = clamp(color.mul(a).add(b), 0, 1e6);\n return mark<Vec3Node>(preview, {\n op: 'bk_brightness_contrast',\n inputs: [color, float(brightness), float(contrast)],\n });\n}\n\n/** Hue/saturation/value. Preview: value and saturation only; a hue rotation\n * in the viewport is not worth a hand-rolled HSV conversion. */\nexport function bakeryHueSaturation(\n color: TSLExpr,\n options: {\n hue?: number;\n saturation?: number;\n value?: number;\n fac?: number;\n } = {},\n): Vec3Node {\n const { hue = 0.5, saturation = 1, value = 1, fac = 1 } = options;\n const scaled = color.mul(value);\n const gray = dot(scaled, vec3(0.2126, 0.7152, 0.0722));\n const adjusted = mix(vec3(gray, gray, gray), scaled, saturation);\n const preview = mix(color, adjusted, fac);\n return mark<Vec3Node>(preview, {\n op: 'bk_hsv',\n inputs: [color],\n params: params({ hue, saturation, value, fac }),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/tsl/index.ts"],"names":[],"mappings":";;;AA8DA,IAAM,MAAA,GAAS,CAAC,KAAA,MAAoB;AAAA,EAClC,MAAO,KAAA,EAA6B;AACtC,CAAA,CAAA;AAEA,eAAA,CAAgB,MAAA,CAAO,aAAa,CAAA,EAAG;AAAA,EACrC,EAAA,EAAI,UAAA;AAAA,E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AAM,MAAM,IAAI,CAAA,EAAG,QAAQ,UAAU,CAAA;AAC/D,EAAA,MAAM,OAAA,GAAU,GAAA,CAAI,KAAA,EAAO,QAAA,EAAU,GAAG,CAAA;AACxC,EAAA,OAAO,KAAe,OAAA,EAAS;AAAA,IAC7B,EAAA,EAAI,QAAA;AAAA,IACJ,MAAA,EAAQ,CAAC,KAAK,CAAA;AAAA,IACd,QAAQ,MAAA,CAAO,EAAE,KAAK,UAAA,EAAY,KAAA,EAAO,KAAK;AAAA,GAC/C,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * @oeave/bakery3/tsl: the renderer's shading vocabulary, usable from TSL.\n *\n * Two things happen here, and importing this module is what turns both on:\n *\n * 1. Registration. TSL's anonymous singletons (`positionWorld`, `time`,\n * `cameraPosition`) carry no recognizable structure, so the extractor can\n * only know them by being introduced. This module imports them from\n * `three/tsl` and registers them by uuid. It is its own entry point\n * because it needs three r170 (one of the nodes it imports is not\n * exported before that); the core SDK keeps working for anyone older.\n *\n * 2. Renderer-only nodes. The renderer has procedural textures and shading\n * inputs a browser cannot compute: traced ambient occlusion, shade-time\n * bevel, pointiness, the classic noise textures. Each function below\n * returns a real TSL node that draws an approximation in the WebGPU\n * viewport and carries a marker the extractor serializes exactly for the\n * render. The viewport is the sketch; the render is the real one.\n * `check()` reports their use as info, never as an error.\n *\n * Everything accepts plain numbers for its dials, and a TSL expression for\n * its coordinate input. Dials are baked into the manifest, so a dial driven\n * by another node is not accepted, rather than accepted and ignored.\n */\n\nimport {\n clamp,\n dot,\n float,\n fract,\n materialReference,\n mix,\n mx_cell_noise_float,\n mx_fractal_noise_float,\n mx_worley_noise_float,\n normalView,\n normalWorld,\n positionLocal,\n positionView,\n positionViewDirection,\n positionWorld,\n cameraPosition,\n pow,\n sin,\n smoothstep,\n sqrt,\n time,\n deltaTime,\n vec3,\n vec4,\n} from 'three/tsl';\nimport {\n BAKERY_NODE_MARKER,\n registerBuiltin,\n registerNodeObject,\n type BakeryNodeMarker,\n} from '../shader/registry.js';\n\n// ---------------------------------------------------------------------------\n// Registration, on import\n// ---------------------------------------------------------------------------\n\nconst asNode = (value: unknown) => ({\n uuid: (value as { uuid?: string })?.uuid,\n});\n\nregisterBuiltin(asNode(positionWorld), {\n op: 'position',\n params: () => ({ space: 'world' }),\n});\nregisterBuiltin(asNode(positionLocal), {\n op: 'position',\n params: () => ({ space: 'local' }),\n});\nregisterBuiltin(asNode(positionView), {\n op: 'position',\n params: () => ({ space: 'view' }),\n});\nregisterBuiltin(asNode(normalWorld), {\n op: 'normal',\n params: () => ({ space: 'world' }),\n});\nregisterBuiltin(asNode(normalView), {\n op: 'normal',\n params: () => ({ space: 'view' }),\n});\nregisterBuiltin(asNode(positionViewDirection), { op: 'view_direction' });\nregisterBuiltin(asNode(cameraPosition), { op: 'camera_position' });\n// Time is a uniform like any other: baked to the moment of capture. Reading\n// `.value` lazily matters: import time is not capture time.\nregisterBuiltin(asNode(time), {\n op: 'uniform',\n params: () => ({\n value: (time as { value?: number }).value ?? 0,\n type: 'float',\n name: 'time',\n }),\n});\nregisterBuiltin(asNode(deltaTime), {\n op: 'uniform',\n params: () => ({\n value: (deltaTime as { value?: number }).value ?? 0,\n type: 'float',\n name: 'deltaTime',\n }),\n});\n\nregisterNodeObject((value) => {\n // `float()` runs plain numbers through TSL's own const-node machinery,\n // which is exactly what Fn expansion needs; nodes pass through untouched.\n return typeof value === 'number' ? float(value) : value;\n});\n\n// ---------------------------------------------------------------------------\n// The marker\n// ---------------------------------------------------------------------------\n\n// Every type here is derived from a `three/tsl` export, so the published\n// declarations name no file inside three's own source tree. Those paths are\n// one @types/three release's layout: a declaration that imported them would\n// fail to compile under `skipLibCheck: false` against any other. Derived\n// this way, a node type is whatever the developer's own @types/three says\n// `float()` and `vec3()` return.\ntype TSLExpr = ReturnType<typeof float>;\ntype Coord = TSLExpr | null | undefined;\n/** A float node: a mask, a factor, a texture's fac output. */\ntype FloatNode = ReturnType<typeof float>;\n/** A three-component node: a color or a normal. */\ntype Vec3Node = ReturnType<typeof vec3>;\n/** A color with alpha. */\ntype Vec4Node = ReturnType<typeof vec4>;\n\nfunction mark<T>(node: unknown, marker: BakeryNodeMarker): T {\n (node as Record<string, unknown>)[BAKERY_NODE_MARKER] = marker;\n return node as T;\n}\n\n/** The renderer's procedural textures default to object-space coordinates;\n * object-space position is the closest thing a live three scene has. */\nconst defaultCoord = () => positionLocal;\n\nconst params = (\n entries: Record<string, number | string | boolean | number[] | undefined>,\n): Record<string, number | string | boolean | number[]> => {\n const out: Record<string, number | string | boolean | number[]> = {};\n for (const [key, value] of Object.entries(entries)) {\n if (value !== undefined) out[key] = value;\n }\n return out;\n};\n\n// ---------------------------------------------------------------------------\n// Procedural textures\n// ---------------------------------------------------------------------------\n\nexport type NoiseTextureOptions = {\n scale?: number;\n detail?: number;\n roughness?: number;\n lacunarity?: number;\n distortion?: number;\n dimensions?: 2 | 3 | 4;\n};\n\n/**\n * The renderer's fractal noise texture. Preview: MaterialX fractal noise,\n * the same character on a different lattice.\n */\nexport function bakeryNoiseTexture(\n coord?: Coord,\n options: NoiseTextureOptions = {},\n): FloatNode {\n const {\n scale = 5,\n detail = 2,\n roughness = 0.5,\n lacunarity = 2,\n distortion = 0,\n } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const preview = mx_fractal_noise_float(\n p,\n Math.max(1, Math.round(detail)),\n lacunarity,\n roughness,\n )\n .mul(0.5)\n .add(0.5);\n return mark<FloatNode>(preview, {\n op: 'bk_noise_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n scale,\n detail,\n roughness,\n lacunarity,\n distortion,\n dimensions: options.dimensions ?? 3,\n }),\n });\n}\n\nexport type VoronoiTextureOptions = {\n scale?: number;\n randomness?: number;\n feature?: 'F1' | 'F2' | 'SMOOTH_F1' | 'DISTANCE_TO_EDGE';\n metric?: 'EUCLIDEAN' | 'MANHATTAN' | 'CHEBYCHEV';\n dimensions?: 2 | 3 | 4;\n};\n\n/** The renderer's Voronoi texture (distance output). Preview: MaterialX Worley. */\nexport function bakeryVoronoiTexture(\n coord?: Coord,\n options: VoronoiTextureOptions = {},\n): FloatNode {\n const { scale = 5, randomness = 1 } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n // three's Worley is the SQUARED distance; the renderer's Voronoi is the\n // distance itself.\n const preview = sqrt(mx_worley_noise_float(p, float(randomness)));\n return mark<FloatNode>(preview, {\n op: 'bk_voronoi_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n scale,\n randomness,\n feature: options.feature ?? 'F1',\n metric: options.metric ?? 'EUCLIDEAN',\n dimensions: options.dimensions ?? 3,\n }),\n });\n}\n\nexport type WaveTextureOptions = {\n scale?: number;\n distortion?: number;\n detail?: number;\n detailScale?: number;\n detailRoughness?: number;\n phase?: number;\n type?: 'BANDS' | 'RINGS';\n direction?: 'X' | 'Y' | 'Z' | 'DIAGONAL';\n profile?: 'SIN' | 'SAW' | 'TRI';\n};\n\n/** The renderer's wave texture. Preview: a sine along the chosen axis. */\nexport function bakeryWaveTexture(\n coord?: Coord,\n options: WaveTextureOptions = {},\n): FloatNode {\n const { scale = 5, phase = 0, direction = 'X' } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const axis =\n direction === 'Y'\n ? p.y\n : direction === 'Z'\n ? p.z\n : direction === 'DIAGONAL'\n ? p.x.add(p.y).add(p.z)\n : p.x;\n const preview = sin(axis.add(phase)).mul(0.5).add(0.5);\n return mark<FloatNode>(preview, {\n op: 'bk_wave_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n scale,\n distortion: options.distortion ?? 0,\n detail: options.detail ?? 2,\n detail_scale: options.detailScale ?? 1,\n detail_roughness: options.detailRoughness ?? 0.5,\n phase,\n type: options.type ?? 'BANDS',\n direction,\n profile: options.profile ?? 'SIN',\n }),\n });\n}\n\nexport type MagicTextureOptions = {\n scale?: number;\n distortion?: number;\n depth?: number;\n};\n\n/** The renderer's interference \"magic\" texture. Preview: interfering sines,\n * the flavor and not the math. */\nexport function bakeryMagicTexture(\n coord?: Coord,\n options: MagicTextureOptions = {},\n): FloatNode {\n const { scale = 5, distortion = 1 } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const preview = sin(p.x.add(sin(p.y.mul(distortion))))\n .mul(0.5)\n .add(0.5);\n return mark<FloatNode>(preview, {\n op: 'bk_magic_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({ scale, distortion, depth: options.depth ?? 2 }),\n });\n}\n\nexport type GradientType =\n | 'LINEAR'\n | 'QUADRATIC'\n | 'EASING'\n | 'DIAGONAL'\n | 'SPHERICAL'\n | 'QUADRATIC_SPHERE'\n | 'RADIAL';\n\nexport type GradientTextureOptions = { type?: GradientType };\n\n/** The renderer's gradient texture. Preview: the linear ramp. */\nexport function bakeryGradientTexture(\n coord?: Coord,\n options: GradientTextureOptions = {},\n): FloatNode {\n const p = coord ?? defaultCoord();\n const preview = clamp(p.x, 0, 1);\n return mark<FloatNode>(preview, {\n op: 'bk_gradient_texture',\n inputs: [p],\n params: params({ gradient_type: options.type ?? 'LINEAR' }),\n });\n}\n\nexport type BrickTextureOptions = {\n offset?: number;\n offsetFrequency?: number;\n squash?: number;\n squashFrequency?: number;\n scale?: number;\n mortarSize?: number;\n mortarSmooth?: number;\n bias?: number;\n brickWidth?: number;\n rowHeight?: number;\n};\n\n/** The renderer's brick texture (fac output, the mortar mask). Preview: a grid. */\nexport function bakeryBrickTexture(\n coord?: Coord,\n options: BrickTextureOptions = {},\n): FloatNode {\n const {\n scale = 5,\n mortarSize = 0.02,\n rowHeight = 0.25,\n brickWidth = 0.5,\n } = options;\n const p = (coord ?? defaultCoord()).mul(scale);\n const gx = fract(p.x.div(brickWidth));\n const gy = fract(p.y.div(rowHeight));\n const edge = float(1).sub(\n smoothstep(\n 0,\n mortarSize * 4,\n gx.min(float(1).sub(gx)).min(gy.min(float(1).sub(gy))),\n ),\n );\n return mark<FloatNode>(edge, {\n op: 'bk_brick_texture',\n inputs: [coord ?? defaultCoord()],\n params: params({\n offset: options.offset ?? 0.5,\n offset_frequency: options.offsetFrequency ?? 2,\n squash: options.squash ?? 1,\n squash_frequency: options.squashFrequency ?? 2,\n scale,\n mortar_size: mortarSize,\n mortar_smooth: options.mortarSmooth ?? 0.1,\n bias: options.bias ?? 0,\n brick_width: brickWidth,\n row_height: rowHeight,\n }),\n });\n}\n\n/** White noise, a hash of the coordinate. Preview: cell noise. */\nexport function bakeryWhiteNoise(\n coord?: Coord,\n options: { dimensions?: 2 | 3 | 4 } = {},\n): FloatNode {\n const p = coord ?? defaultCoord();\n const preview = mx_cell_noise_float(p.mul(1024));\n return mark<FloatNode>(preview, {\n op: 'bk_white_noise',\n inputs: [p],\n params: params({ dimensions: options.dimensions ?? 3 }),\n });\n}\n\n// ---------------------------------------------------------------------------\n// Shading inputs the browser cannot compute\n// ---------------------------------------------------------------------------\n\n/**\n * Traced ambient occlusion. The browser has no rays, so the preview is plain\n * white, which is exactly what an unoccluded surface reads as. The render\n * traces the real thing.\n */\nexport function bakeryAmbientOcclusion(\n options: { distance?: number; samples?: number; onlyLocal?: boolean } = {},\n): FloatNode {\n const preview = float(1);\n return mark<FloatNode>(preview, {\n op: 'bk_ambient_occlusion',\n params: params({\n distance: options.distance ?? 1,\n samples: options.samples ?? 16,\n only_local: options.onlyLocal ?? false,\n }),\n });\n}\n\n/**\n * Shade-time edge rounding. Preview: the unrounded normal, so geometry looks\n * crisp in the viewport and gets the worn edge in the render.\n */\nexport function bakeryBevel(\n options: { radius?: number; samples?: number } = {},\n): Vec3Node {\n const preview = normalWorld;\n return mark<Vec3Node>(vec3(preview), {\n op: 'bk_bevel',\n params: params({\n radius: options.radius ?? 0.05,\n samples: options.samples ?? 4,\n }),\n });\n}\n\n/** Surface curvature: concave 0, flat 0.5, convex 1. Preview: flat 0.5. */\nexport function bakeryPointiness(): FloatNode {\n return mark<FloatNode>(float(0.5), { op: 'bk_pointiness' });\n}\n\n/** 1 on triangle edges. Preview: 0, no wires in the viewport. */\nexport function bakeryWireframe(\n options: { size?: number; pixelSize?: boolean } = {},\n): FloatNode {\n return mark<FloatNode>(float(0), {\n op: 'bk_wireframe',\n params: params({\n size: options.size ?? 0.01,\n pixel_size: options.pixelSize ?? false,\n }),\n });\n}\n\n/**\n * The material's own `emissiveIntensity`, for an `emissiveNode` to multiply.\n *\n * three ignores `emissiveIntensity` once a node material has an\n * `emissiveNode`; the renderer does not, because it puts the intensity on\n * the emission's strength. So an animated intensity (a timeline track, a\n * hotspot opening) dims the render and leaves the viewport alone. Multiply by\n * this and the two agree: in the viewport it reads the material's value every\n * frame, in the render it is 1, since the strength already carries it.\n *\n * material.emissiveNode = myGlow.mul(bakeryEmissiveIntensity());\n */\nexport function bakeryEmissiveIntensity(): FloatNode {\n return mark<FloatNode>(materialReference('emissiveIntensity', 'float'), {\n op: 'const',\n params: { value: 1, type: 'float' },\n });\n}\n\n/** Physically correct fresnel. Preview: Schlick's approximation, close enough\n * that the viewport and the render agree on where the rim light lives. */\nexport function bakeryFresnel(ior: number = 1.45): FloatNode {\n const f0 = ((1 - ior) / (1 + ior)) ** 2;\n const facing = clamp(dot(normalView, positionViewDirection), 0, 1);\n const preview = float(f0).add(\n float(1 - f0).mul(pow(float(1).sub(facing), 5)),\n );\n return mark<FloatNode>(preview, { op: 'bk_fresnel', inputs: [float(ior)] });\n}\n\n/** A facing/fresnel layer weight. Preview: the facing term it is built from. */\nexport function bakeryLayerWeight(\n blend: number = 0.5,\n options: { output?: 'FRESNEL' | 'FACING' } = {},\n): FloatNode {\n const facing = float(1).sub(\n clamp(dot(normalView, positionViewDirection), 0, 1),\n );\n return mark<FloatNode>(facing, {\n op: 'bk_layer_weight',\n inputs: [float(blend)],\n params: params({ output: options.output ?? 'FACING' }),\n });\n}\n\n// ---------------------------------------------------------------------------\n// Color tools\n// ---------------------------------------------------------------------------\n\nexport type ColorRampStop = {\n position: number;\n color: [number, number, number] | [number, number, number, number];\n};\n\n/**\n * A color ramp. Preview: the same ramp, rebuilt from mix chains; for LINEAR\n * and CONSTANT interpolation the viewport matches the render.\n */\nexport function bakeryColorRamp(\n fac: TSLExpr,\n stops: ColorRampStop[],\n options: { interpolation?: 'LINEAR' | 'CONSTANT' } = {},\n): Vec4Node {\n if (stops.length < 1)\n throw new Error('bakeryColorRamp needs at least one stop.');\n const sorted = [...stops].sort((a, b) => a.position - b.position);\n const rgba = (stop: ColorRampStop) =>\n vec4(stop.color[0], stop.color[1], stop.color[2], stop.color[3] ?? 1);\n\n let preview = rgba(sorted[0]!) as unknown as ReturnType<typeof mix>;\n for (let i = 1; i < sorted.length; i++) {\n const previous = sorted[i - 1]!;\n const current = sorted[i]!;\n const span = Math.max(current.position - previous.position, 1e-5);\n const t =\n (options.interpolation ?? 'LINEAR') === 'CONSTANT'\n ? smoothstep(current.position - 1e-5, current.position, fac)\n : clamp(fac.sub(previous.position).div(span), 0, 1);\n preview = mix(preview, rgba(current), t);\n }\n\n const flat: number[] = [];\n for (const stop of sorted) {\n flat.push(\n stop.position,\n stop.color[0],\n stop.color[1],\n stop.color[2],\n stop.color[3] ?? 1,\n );\n }\n return mark<Vec4Node>(preview, {\n op: 'bk_color_ramp',\n inputs: [fac],\n params: params({\n interpolation: options.interpolation ?? 'LINEAR',\n stops: flat,\n }),\n });\n}\n\n/** Blackbody temperature to color. Preview: a two-anchor tint, warm below\n * and cool above. */\nexport function bakeryBlackbody(kelvin: number = 5000): Vec3Node {\n const t = smoothstep(2000, 10000, float(kelvin));\n const preview = mix(vec3(1.0, 0.58, 0.27), vec3(0.78, 0.85, 1.0), t);\n return mark<Vec3Node>(preview, {\n op: 'bk_blackbody',\n inputs: [float(kelvin)],\n });\n}\n\n/** A gamma curve. The preview is the same math. */\nexport function bakeryGamma(color: TSLExpr, gamma: number = 1): Vec3Node {\n const preview = pow(color, vec3(gamma, gamma, gamma));\n return mark<Vec3Node>(preview, {\n op: 'bk_gamma',\n inputs: [color, float(gamma)],\n });\n}\n\n/** Brightness/contrast. Preview: the same formula the render uses. */\nexport function bakeryBrightnessContrast(\n color: TSLExpr,\n options: { brightness?: number; contrast?: number } = {},\n): Vec3Node {\n const { brightness = 0, contrast = 0 } = options;\n const a = 1 + contrast;\n const b = brightness - contrast * 0.5;\n const preview = clamp(color.mul(a).add(b), 0, 1e6);\n return mark<Vec3Node>(preview, {\n op: 'bk_brightness_contrast',\n inputs: [color, float(brightness), float(contrast)],\n });\n}\n\n/** Hue/saturation/value. Preview: value and saturation only; a hue rotation\n * in the viewport is not worth a hand-rolled HSV conversion. */\nexport function bakeryHueSaturation(\n color: TSLExpr,\n options: {\n hue?: number;\n saturation?: number;\n value?: number;\n fac?: number;\n } = {},\n): Vec3Node {\n const { hue = 0.5, saturation = 1, value = 1, fac = 1 } = options;\n const scaled = color.mul(value);\n const gray = dot(scaled, vec3(0.2126, 0.7152, 0.0722));\n const adjusted = mix(vec3(gray, gray, gray), scaled, saturation);\n const preview = mix(color, adjusted, fac);\n return mark<Vec3Node>(preview, {\n op: 'bk_hsv',\n inputs: [color],\n params: params({ hue, saturation, value, fac }),\n });\n}\n"]}
|