@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
77 lines (76 loc) • 3.17 kB
JavaScript
"use strict";
import { BaseSDFGlNode } from "./_BaseSDF";
import { ThreeToGl } from "../../../core/ThreeToGl";
import Mandelbrot from "./gl/fractal/mandelbrot.glsl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPoint, GlConnectionPointType } from "../utils/io/connections/Gl";
import { FunctionGLDefinition } from "./utils/GLDefinition";
import { GlType } from "../../poly/registers/nodes/types/Gl";
var OutputName = /* @__PURE__ */ ((OutputName2) => {
OutputName2["D"] = "d";
OutputName2["AO"] = "ao";
return OutputName2;
})(OutputName || {});
class SDFFractalMandelbrotGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.power = ParamConfig.FLOAT(8, {
range: [0, 10],
rangeLocked: [false, false]
});
this.QPreMult = ParamConfig.VECTOR3([1, 1, 1]);
this.QPostMult = ParamConfig.VECTOR3([1, 1, 1]);
this.thetaMult = ParamConfig.FLOAT(1, {
range: [-2, 2],
rangeLocked: [true, false]
});
this.iterations = ParamConfig.INTEGER(8, {
range: [1, 32],
rangeLocked: [true, false]
});
this.externalBoundingRadius = ParamConfig.FLOAT(1.2, {
range: [0, 2],
rangeLocked: [true, false]
});
}
}
const ParamsConfig = new SDFFractalMandelbrotGlParamsConfig();
export class SDFFractalMandelbrotGlNode extends BaseSDFGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return GlType.SDF_FRACTAL_MANDELBROT;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint("d" /* D */, GlConnectionPointType.FLOAT),
new GlConnectionPoint("ao" /* AO */, GlConnectionPointType.FLOAT)
]);
}
setLines(shadersCollectionController) {
const position = this.position();
const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center));
const power = ThreeToGl.float(this.variableForInputParam(this.p.power));
const externalBoundingRadius = ThreeToGl.float(this.variableForInputParam(this.p.externalBoundingRadius));
const thetaMult = ThreeToGl.float(this.variableForInputParam(this.p.thetaMult));
const QPreMult = ThreeToGl.vector3(this.variableForInputParam(this.p.QPreMult));
const QPostMult = ThreeToGl.vector3(this.variableForInputParam(this.p.QPostMult));
const d = this.glVarName("d" /* D */);
const ao = this.glVarName("ao" /* AO */);
const mandelbrotStructArgs = [power, QPreMult, QPostMult, thetaMult, externalBoundingRadius];
const mandelbrotStruct = `MandelbrotArgs(${mandelbrotStructArgs.join(", ")})`;
const bodyLines = [
`float ${ao}`,
`float ${d} = mandelbrot(${position} - ${center}, ${ao}, ${mandelbrotStruct})`
];
shadersCollectionController.addBodyLines(this, bodyLines);
shadersCollectionController.addDefinitions(this, [
new FunctionGLDefinition(this, Mandelbrot.replace("___ITERATIONS___", `${this.pv.iterations}`))
]);
}
}