@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
40 lines (32 loc) • 1.13 kB
text/typescript
/**
* multiplies a value by -1
*
*
*
*/
import {BaseNodeGlMathFunctionArg1GlNode} from './_BaseMathFunction';
import {ThreeToGl} from '../../../core/ThreeToGl';
import {ShadersCollectionController} from './code/utils/ShadersCollectionController';
export class NegateGlNode extends BaseNodeGlMathFunctionArg1GlNode {
static override type() {
return 'negate';
}
override initializeNode() {
super.initializeNode();
this.io.connection_points.set_input_name_function((index: number) => ['in'][index]);
}
protected override _gl_input_name(index: number) {
return ['in'][index];
}
override setLines(shaders_collection_controller: ShadersCollectionController) {
const connectionPoints = this.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return;
}
const in_value = ThreeToGl.any(this.variableForInput(this._gl_input_name(0)));
const gl_type = connectionPoints[0].type();
const out = this.glVarName(this.io.connection_points.output_name(0));
const body_line = `${gl_type} ${out} = -1.0 * ${in_value}`;
shaders_collection_controller.addBodyLines(this, [body_line]);
}
}