@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
41 lines (40 loc) • 1.51 kB
JavaScript
;
import { TypedGlNode } from "./_Base";
import { ThreeToGl } from "../../../core/ThreeToGl";
import oklab from "./gl/oklab.glsl";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { FunctionGLDefinition } from "./utils/GLDefinition";
const OUTPUT_NAME = "rgb";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
class OklabToRgbGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.oklab = ParamConfig.VECTOR3([1, 1, 1]);
}
}
const ParamsConfig = new OklabToRgbGlParamsConfig();
export class OklabToRgbGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "oklabToRgb";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC3)
]);
}
setLines(shaders_collection_controller) {
const function_declaration_lines = [];
const body_lines = [];
function_declaration_lines.push(new FunctionGLDefinition(this, oklab));
const value = ThreeToGl.vector3(this.variableForInputParam(this.p.oklab));
const rgb = this.glVarName(OUTPUT_NAME);
body_lines.push(`vec3 ${rgb} = linear_srgb_from_oklab(${value})`);
shaders_collection_controller.addDefinitions(this, function_declaration_lines);
shaders_collection_controller.addBodyLines(this, body_lines);
}
}