UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

44 lines (43 loc) 1.27 kB
"use strict"; import { Vector2 } from "three"; import { TypedPostNode, PostParamOptions } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { EffectPass, NoiseEffect } from "postprocessing"; class NoisePostParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param effect strength */ this.strength = ParamConfig.FLOAT(1, { range: [0, 1], rangeLocked: [true, false], ...PostParamOptions }); /** @param premultiply */ this.premultiply = ParamConfig.BOOLEAN(1, { ...PostParamOptions }); } } const ParamsConfig = new NoisePostParamsConfig(); export class NoisePostNode extends TypedPostNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this._rendererSize = new Vector2(); } static type() { return "noise"; } createPass(context) { context.renderer.getSize(this._rendererSize); const effect = new NoiseEffect({}); const pass = new EffectPass(context.camera, effect); this.updatePass(pass); return pass; } updatePass(pass) { const effect = pass.effects[0]; effect.premultiply = this.pv.premultiply; effect.blendMode.opacity.value = this.pv.strength; } }