@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
45 lines (44 loc) • 1.9 kB
JavaScript
;
import { BaseSDFGlNode } from "./_BaseSDF";
import { ThreeToGl } from "../../../../src/core/ThreeToGl";
import SDFQuaternionMethods from "./gl/quaternion.glsl";
import SDFTransformMethods from "./gl/raymarching/sdfTransform.glsl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { FunctionGLDefinition } from "./utils/GLDefinition";
import { GlType } from "../../poly/registers/nodes/types/Gl";
const OUTPUT_NAME = "p";
class SDFTransformGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.t = ParamConfig.VECTOR3([0, 0, 0]);
this.r = ParamConfig.VECTOR3([0, 0, 0]);
}
}
const ParamsConfig = new SDFTransformGlParamsConfig();
export class SDFTransformGlNode extends BaseSDFGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return GlType.SDF_TRANSFORM;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC3)
]);
}
setLines(shadersCollectionController) {
const position = this.position();
const t = ThreeToGl.vector3(this.variableForInputParam(this.p.t));
const r = ThreeToGl.vector3(this.variableForInputParam(this.p.r));
const float = this.glVarName(OUTPUT_NAME);
const bodyLine = `vec3 ${float} = SDFTransform(${position}, ${t}, ${r})`;
shadersCollectionController.addBodyLines(this, [bodyLine]);
shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, SDFQuaternionMethods)]);
shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, SDFTransformMethods)]);
}
}