feat: add render graph driven renderer architecture

Amp-Thread-ID: https://ampcode.com/threads/T-019f9d91-77c1-7206-a60f-ed6554ce92ab

Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
Amp
2026-07-27 02:53:44 +00:00
co-authored by heaust
parent 8a8369706b
commit d4e8634f67
290 changed files with 48804 additions and 1995 deletions
@@ -0,0 +1,127 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const colorRampNode = [
"fxnode.shader.color-ramp",
{
version: 2,
title: "Color Ramp",
behavior: "standard",
style: "shader",
parameters: {
ramp: {
type: "json",
codec: "color-ramp/v1",
default: {
kind: "json",
value: {
colorMode: "rgb",
interpolation: "linear",
hueInterpolation: "near",
stops: [
{
id: "stop-0",
position: 0,
color: [0, 0, 0, 1],
},
{
id: "stop-1",
position: 1,
color: [1, 1, 1, 1],
},
],
},
},
},
},
sockets: {
factor: {
title: "Factor",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0.5,
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
color: {
title: "Color",
direction: "output",
type: "color",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
alpha: {
title: "Alpha",
direction: "output",
type: "float",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "socket",
socket: "color",
},
{
kind: "socket",
socket: "alpha",
},
{
kind: "widget",
widget: "color-ramp",
parameter: "ramp",
title: "",
},
{
kind: "socket",
socket: "factor",
},
],
muteBypass: [],
migrations: [
{
fromVersion: 1,
toVersion: 2,
steps: [
{
kind: "materialize-missing",
target: "parameter",
key: "ramp",
},
{
kind: "materialize-missing",
target: "socket",
key: "factor",
},
{
kind: "materialize-missing",
target: "socket",
key: "color",
},
{
kind: "materialize-missing",
target: "socket",
key: "alpha",
},
{
kind: "migrate-parameter",
parameter: "ramp",
codec: "color-ramp/legacy-stops",
},
],
},
],
},
] as const satisfies readonly [string, FxNodeDefinition];
+44
View File
@@ -0,0 +1,44 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const colorNode = [
"fxnode.shader.color",
{
version: 1,
title: "Color",
behavior: "standard",
style: "shader",
parameters: {
color: {
type: "color",
default: {
kind: "color",
value: [0.8, 0.8, 0.8, 1],
},
minimum: 0,
maximum: 1,
},
},
sockets: {
color: {
title: "Color",
direction: "output",
type: "color",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "parameter",
parameter: "color",
},
{
kind: "socket",
socket: "color",
},
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
@@ -0,0 +1,157 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const imageTextureNode = [
"fxnode.shader.image-texture",
{
version: 1,
title: "Image Texture",
behavior: "standard",
style: "input",
parameters: {
image: {
type: "string",
default: {
kind: "string",
value: "",
},
},
interpolation: {
type: "string",
default: {
kind: "string",
value: "Linear",
},
enum: ["Linear", "Closest", "Cubic", "Smart"],
},
projection: {
type: "string",
default: {
kind: "string",
value: "Flat",
},
enum: ["Flat", "Box", "Sphere", "Tube"],
},
blend: {
type: "number",
default: {
kind: "number",
value: 0,
},
minimum: 0,
maximum: 1,
},
extension: {
type: "string",
default: {
kind: "string",
value: "Repeat",
},
enum: ["Repeat", "Extend", "Clip", "Mirror"],
},
colorSpace: {
type: "string",
default: {
kind: "string",
value: "sRGB",
},
enum: ["sRGB", "Linear", "Non-Color"],
},
alphaMode: {
type: "string",
default: {
kind: "string",
value: "Straight",
},
enum: ["Straight", "Premultiplied", "Channel Packed", "None"],
},
},
sockets: {
vector: {
title: "Vector",
direction: "input",
type: "vector",
maxIncomingLinks: 1,
visible: true,
value: {
type: "vector",
default: {
kind: "vector",
value: [0, 0, 0],
},
},
showValue: false,
},
color: {
title: "Color",
direction: "output",
type: "color",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
alpha: {
title: "Alpha",
direction: "output",
type: "float",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "resource",
resource: "legacyImage",
parameter: "image",
title: "Image",
openTitle: "Open",
},
{
kind: "parameter",
parameter: "interpolation",
},
{
kind: "parameter",
parameter: "projection",
},
{
kind: "parameter",
parameter: "blend",
title: "Blend",
visibleWhen: {
parameter: "projection",
equals: "Box",
},
},
{
kind: "parameter",
parameter: "extension",
},
{
kind: "parameter",
parameter: "colorSpace",
title: "Color Space",
},
{
kind: "parameter",
parameter: "alphaMode",
title: "Alpha Mode",
},
{
kind: "socket",
socket: "vector",
},
{
kind: "socket",
socket: "color",
},
{
kind: "socket",
socket: "alpha",
},
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
@@ -0,0 +1,62 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const materialOutputNode = [
"fxnode.shader.material-output",
{
version: 1,
title: "Material Output",
behavior: "standard",
style: "output",
parameters: {},
sockets: {
surface: {
title: "Surface",
direction: "input",
type: "shader",
maxIncomingLinks: 1,
visible: true,
value: null,
showValue: false,
},
volume: {
title: "Volume",
direction: "input",
type: "shader",
maxIncomingLinks: 1,
visible: true,
value: null,
showValue: false,
},
displacement: {
title: "Displacement",
direction: "input",
type: "vector",
maxIncomingLinks: 1,
visible: true,
value: {
type: "vector",
default: {
kind: "vector",
value: [0, 0, 0],
},
},
showValue: true,
},
},
ui: [
{
kind: "socket",
socket: "surface",
},
{
kind: "socket",
socket: "volume",
},
{
kind: "socket",
socket: "displacement",
},
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
+92
View File
@@ -0,0 +1,92 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const mathNode = [
"fxnode.shader.math",
{
version: 1,
title: "Math",
behavior: "standard",
style: "converter",
parameters: {
operation: {
type: "string",
default: {
kind: "string",
value: "add",
},
enum: ["add", "subtract", "multiply", "divide", "power", "minimum", "maximum"],
},
clamp: {
type: "boolean",
default: {
kind: "boolean",
value: false,
},
},
},
sockets: {
a: {
title: "A",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
},
showValue: true,
},
b: {
title: "B",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
},
showValue: true,
},
value: {
title: "Value",
direction: "output",
type: "float",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "parameter",
parameter: "operation",
},
{
kind: "parameter",
parameter: "clamp",
},
{
kind: "socket",
socket: "a",
},
{
kind: "socket",
socket: "b",
},
{
kind: "socket",
socket: "value",
},
],
muteBypass: [["a", "value"]],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
+117
View File
@@ -0,0 +1,117 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const mixNode = [
"fxnode.shader.mix",
{
version: 1,
title: "Mix",
behavior: "standard",
style: "shader",
parameters: {
blend: {
type: "string",
default: {
kind: "string",
value: "mix",
},
enum: ["mix", "add", "multiply", "screen", "overlay"],
},
clamp: {
type: "boolean",
default: {
kind: "boolean",
value: false,
},
},
},
sockets: {
factor: {
title: "Factor",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0.5,
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
a: {
title: "A",
direction: "input",
type: "color",
maxIncomingLinks: 1,
visible: true,
value: {
type: "color",
default: {
kind: "color",
value: [0.8, 0.8, 0.8, 1],
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
b: {
title: "B",
direction: "input",
type: "color",
maxIncomingLinks: 1,
visible: true,
value: {
type: "color",
default: {
kind: "color",
value: [0.8, 0.8, 0.8, 1],
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
result: {
title: "Result",
direction: "output",
type: "color",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "parameter",
parameter: "blend",
},
{
kind: "parameter",
parameter: "clamp",
},
{
kind: "socket",
socket: "factor",
},
{
kind: "socket",
socket: "a",
},
{
kind: "socket",
socket: "b",
},
{
kind: "socket",
socket: "result",
},
],
muteBypass: [["a", "result"]],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
@@ -0,0 +1,364 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const noiseTextureNode = [
"fxnode.shader.noise-texture",
{
version: 2,
title: "Noise Texture",
behavior: "standard",
style: "texture",
parameters: {
dimensions: {
type: "string",
default: {
kind: "string",
value: "3d",
},
enum: ["1d", "2d", "3d", "4d"],
},
noiseType: {
type: "string",
default: {
kind: "string",
value: "fbm",
},
enum: ["fbm", "multifractal", "hybrid-multifractal", "ridged-multifractal", "hetero-terrain"],
},
normalize: {
type: "boolean",
default: {
kind: "boolean",
value: false,
},
},
},
sockets: {
vector: {
title: "Vector",
direction: "input",
type: "vector",
maxIncomingLinks: 1,
visible: true,
value: {
type: "vector",
default: {
kind: "vector",
value: [0, 0, 0],
},
},
showValue: false,
},
w: {
title: "W",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
},
showValue: true,
},
scale: {
title: "Scale",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 5,
},
minimum: -1000,
maximum: 1000,
},
showValue: true,
},
detail: {
title: "Detail",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 2,
},
minimum: 0,
maximum: 15,
},
showValue: true,
},
roughness: {
title: "Roughness",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0.5,
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
lacunarity: {
title: "Lacunarity",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 2,
},
minimum: 0,
maximum: 1000,
},
showValue: true,
},
offset: {
title: "Offset",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
minimum: -1000,
maximum: 1000,
},
showValue: true,
},
gain: {
title: "Gain",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 1,
},
minimum: 0,
maximum: 1000,
},
showValue: true,
},
distortion: {
title: "Distortion",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
minimum: -1000,
maximum: 1000,
},
showValue: true,
},
factor: {
title: "Factor",
direction: "output",
type: "float",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
color: {
title: "Color",
direction: "output",
type: "color",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "parameter",
parameter: "dimensions",
title: "Dimensions",
},
{
kind: "parameter",
parameter: "noiseType",
title: "Type",
},
{
kind: "parameter",
parameter: "normalize",
title: "Normalize",
visibleWhen: {
parameter: "noiseType",
equals: "fbm",
},
},
{
kind: "socket",
socket: "vector",
visibleWhen: {
parameter: "dimensions",
in: ["2d", "3d", "4d"],
},
},
{
kind: "socket",
socket: "w",
visibleWhen: {
parameter: "dimensions",
in: ["1d", "4d"],
},
},
{
kind: "socket",
socket: "scale",
},
{
kind: "socket",
socket: "detail",
},
{
kind: "socket",
socket: "roughness",
},
{
kind: "socket",
socket: "lacunarity",
},
{
kind: "socket",
socket: "offset",
visibleWhen: {
parameter: "noiseType",
in: ["hybrid-multifractal", "ridged-multifractal", "hetero-terrain"],
},
},
{
kind: "socket",
socket: "gain",
visibleWhen: {
parameter: "noiseType",
in: ["hybrid-multifractal", "ridged-multifractal"],
},
},
{
kind: "socket",
socket: "distortion",
},
{
kind: "socket",
socket: "factor",
},
{
kind: "socket",
socket: "color",
},
],
muteBypass: [],
migrations: [
{
fromVersion: 1,
toVersion: 2,
steps: [
{
kind: "materialize-missing",
target: "parameter",
key: "dimensions",
},
{
kind: "materialize-missing",
target: "parameter",
key: "noiseType",
},
{
kind: "materialize-missing",
target: "parameter",
key: "normalize",
},
{
kind: "materialize-missing",
target: "socket",
key: "vector",
},
{
kind: "materialize-missing",
target: "socket",
key: "w",
},
{
kind: "materialize-missing",
target: "socket",
key: "scale",
},
{
kind: "materialize-missing",
target: "socket",
key: "detail",
},
{
kind: "materialize-missing",
target: "socket",
key: "roughness",
},
{
kind: "materialize-missing",
target: "socket",
key: "lacunarity",
},
{
kind: "materialize-missing",
target: "socket",
key: "offset",
},
{
kind: "materialize-missing",
target: "socket",
key: "gain",
},
{
kind: "materialize-missing",
target: "socket",
key: "distortion",
},
{
kind: "materialize-missing",
target: "socket",
key: "factor",
},
{
kind: "materialize-missing",
target: "socket",
key: "color",
},
],
},
],
},
] as const satisfies readonly [string, FxNodeDefinition];
@@ -0,0 +1,154 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const principledBsdfNode = [
"fxnode.shader.principled-bsdf",
{
version: 1,
title: "Principled BSDF",
behavior: "standard",
style: "shader",
parameters: {},
sockets: {
"base-color": {
title: "Base Color",
direction: "input",
type: "color",
maxIncomingLinks: 1,
visible: true,
value: {
type: "color",
default: {
kind: "color",
value: [0.8, 0.8, 0.8, 1],
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
metallic: {
title: "Metallic",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
roughness: {
title: "Roughness",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 0.5,
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
ior: {
title: "IOR",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 1.5,
},
minimum: 1,
maximum: 1000,
},
showValue: true,
},
alpha: {
title: "Alpha",
direction: "input",
type: "float",
maxIncomingLinks: 1,
visible: true,
value: {
type: "number",
default: {
kind: "number",
value: 1,
},
minimum: 0,
maximum: 1,
},
showValue: true,
},
normal: {
title: "Normal",
direction: "input",
type: "vector",
maxIncomingLinks: 1,
visible: true,
value: {
type: "vector",
default: {
kind: "vector",
value: [0, 0, 0],
},
},
showValue: false,
},
bsdf: {
title: "BSDF",
direction: "output",
type: "shader",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "socket",
socket: "base-color",
},
{
kind: "socket",
socket: "metallic",
},
{
kind: "socket",
socket: "roughness",
},
{
kind: "socket",
socket: "ior",
},
{
kind: "socket",
socket: "alpha",
},
{
kind: "socket",
socket: "normal",
},
{
kind: "socket",
socket: "bsdf",
},
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
@@ -0,0 +1,69 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const textureCoordinateNode = [
"fxnode.shader.texture-coordinate",
{
version: 1,
title: "Texture Coordinate",
behavior: "standard",
style: "shader",
parameters: {},
sockets: {
generated: {
title: "Generated",
direction: "output",
type: "vector",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
normal: {
title: "Normal",
direction: "output",
type: "vector",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
uv: {
title: "UV",
direction: "output",
type: "vector",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
object: {
title: "Object",
direction: "output",
type: "vector",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "socket",
socket: "generated",
},
{
kind: "socket",
socket: "normal",
},
{
kind: "socket",
socket: "uv",
},
{
kind: "socket",
socket: "object",
},
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
+43
View File
@@ -0,0 +1,43 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const valueNode = [
"fxnode.shader.value",
{
version: 1,
title: "Value",
behavior: "standard",
style: "shader",
parameters: {
value: {
type: "number",
default: {
kind: "number",
value: 0,
},
step: 1,
},
},
sockets: {
value: {
title: "Value",
direction: "output",
type: "float",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "parameter",
parameter: "value",
},
{
kind: "socket",
socket: "value",
},
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
@@ -0,0 +1,98 @@
import type { FxNodeDefinition } from "@lib/composition/index.js";
export const vectorMathNode = [
"fxnode.shader.vector-math",
{
version: 1,
title: "Vector Math",
behavior: "standard",
style: "converter",
parameters: {
operation: {
type: "string",
default: {
kind: "string",
value: "add",
},
enum: ["add", "subtract", "multiply", "dot-product", "length", "normalize"],
},
},
sockets: {
a: {
title: "A",
direction: "input",
type: "vector",
maxIncomingLinks: 1,
visible: true,
value: {
type: "vector",
default: {
kind: "vector",
value: [0, 0, 0],
},
},
showValue: true,
},
b: {
title: "B",
direction: "input",
type: "vector",
maxIncomingLinks: 1,
visible: true,
value: {
type: "vector",
default: {
kind: "vector",
value: [0, 0, 0],
},
},
showValue: true,
},
vector: {
title: "Vector",
direction: "output",
type: "vector",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
value: {
title: "Value",
direction: "output",
type: "float",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{
kind: "parameter",
parameter: "operation",
},
{
kind: "socket",
socket: "a",
},
{
kind: "socket",
socket: "b",
visibleWhen: {
parameter: "operation",
equals: "add",
},
},
{
kind: "socket",
socket: "vector",
},
{
kind: "socket",
socket: "value",
},
],
muteBypass: [["a", "vector"]],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];