polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
54 lines (53 loc) • 2.21 kB
JavaScript
import Quaternion from "./gl/quaternion.glsl";
import Impostor from "./gl/impostor.glsl";
import {TypedGlNode} from "./_Base";
import {ThreeToGl as ThreeToGl2} from "../../../../src/core/ThreeToGl";
import {ParamConfig, NodeParamsConfig} from "../utils/params/ParamsConfig";
import {GlConnectionPointType, GlConnectionPoint} from "../utils/io/connections/Gl";
import {FunctionGLDefinition} from "./utils/GLDefinition";
const OUTPUT_NAME = "uv";
class ImpostorUvGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.cameraPos = ParamConfig.VECTOR3([0, 0, 0]);
this.uv = ParamConfig.VECTOR2([0, 0]);
this.tilesCount = ParamConfig.INTEGER(8, {
range: [0, 32],
rangeLocked: [true, false]
});
this.offset = ParamConfig.FLOAT(0);
}
}
const ParamsConfig2 = new ImpostorUvGlParamsConfig();
export class ImpostorUvGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.params_config = ParamsConfig2;
}
static type() {
return "impostorUv";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC2)
]);
}
set_lines(shaders_collection_controller) {
const body_lines = [];
shaders_collection_controller.add_definitions(this, [
new FunctionGLDefinition(this, Quaternion),
new FunctionGLDefinition(this, Impostor)
]);
const center = ThreeToGl2.vector3(this.variable_for_input(this.p.center.name()));
const cameraPos = ThreeToGl2.vector3(this.variable_for_input(this.p.cameraPos.name()));
const uv = ThreeToGl2.vector2(this.variable_for_input(this.p.uv.name()));
const tilesCount = ThreeToGl2.float(this.variable_for_input(this.p.tilesCount.name()));
const offset = ThreeToGl2.float(this.variable_for_input(this.p.offset.name()));
const impostor_uv = this.gl_var_name(OUTPUT_NAME);
const args = [center, cameraPos, uv, tilesCount, offset].join(", ");
body_lines.push(`vec2 ${impostor_uv} = impostor_uv(${args})`);
shaders_collection_controller.add_body_lines(this, body_lines);
}
}