@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
40 lines (39 loc) • 1.5 kB
JavaScript
;
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { TypedGlNode } from "./_Base";
import DitherMethods from "./gl/dither.glsl";
import { GlConnectionPoint, GlConnectionPointType } from "../utils/io/connections/Gl";
import { ThreeToGl } from "../../../core/ThreeToGl";
import { FunctionGLDefinition } from "./utils/GLDefinition";
const OUTPUT_NAME = "dither";
class DitherGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.alpha = ParamConfig.FLOAT(1);
this.alphaTest = ParamConfig.FLOAT(0.5);
}
}
const ParamsConfig = new DitherGlParamsConfig();
export class DitherGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "dither";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT)
]);
}
setLines(shadersCollectionController) {
const alpha = ThreeToGl.float(this.variableForInputParam(this.p.alpha));
const alphaTest = ThreeToGl.float(this.variableForInputParam(this.p.alphaTest));
const output = this.glVarName(OUTPUT_NAME);
const body_line = `float ${output} = dither(${alpha}, ${alphaTest})`;
shadersCollectionController.addBodyLines(this, [body_line]);
shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, DitherMethods)]);
}
}