UNPKG

@polygonjs/polygonjs

Version:

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

48 lines (47 loc) 1.38 kB
"use strict"; import { TypedPostNode, PostParamOptions } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { EffectPass, VignetteEffect, VignetteTechnique } from "postprocessing"; class VignettePostParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param offset */ this.offset = ParamConfig.FLOAT(0, { range: [0, 1], rangeLocked: [false, false], ...PostParamOptions }); /** @param darkness */ this.darkness = ParamConfig.FLOAT(1, { range: [0, 2], rangeLocked: [true, false], ...PostParamOptions }); } } const ParamsConfig = new VignettePostParamsConfig(); export class VignettePostNode extends TypedPostNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "vignette"; } createPass(context) { const effect = new VignetteEffect({ technique: VignetteTechnique.DEFAULT, offset: this.pv.offset, darkness: this.pv.darkness }); const pass = new EffectPass(context.camera, effect); this.updatePass(pass); return pass; } updatePass(pass) { const effect = pass.effects[0]; const uniforms = effect.uniforms; uniforms.get("offset").value = this.pv.offset; uniforms.get("darkness").value = this.pv.darkness; } }