UNPKG

@polygonjs/polygonjs

Version:

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

59 lines (58 loc) 1.8 kB
"use strict"; import { TypedPostNode, PostParamOptions } from "./_Base"; import { HueSaturationEffect, EffectPass, BlendFunction } from "postprocessing"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { BLEND_FUNCTION_MENU_OPTIONS } from "../../../core/post/BlendFunction"; class HueSaturationPostParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param hue */ this.hue = ParamConfig.FLOAT(0, { range: [0, Math.PI], rangeLocked: [false, false], step: 1e-5, ...PostParamOptions }); /** @param saturation */ this.saturation = ParamConfig.FLOAT(0, { range: [-1, 1], rangeLocked: [false, false], ...PostParamOptions }); /** @param effect opacity */ this.opacity = ParamConfig.FLOAT(1, { range: [0, 1], rangeLocked: [true, false], ...PostParamOptions }); /** @param render mode */ this.blendFunction = ParamConfig.INTEGER(BlendFunction.MULTIPLY, { ...PostParamOptions, ...BLEND_FUNCTION_MENU_OPTIONS }); } } const ParamsConfig = new HueSaturationPostParamsConfig(); export class HueSaturationPostNode extends TypedPostNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "hueSaturation"; } createPass(context) { const effect = new HueSaturationEffect(); const camera = context.camera; const pass = new EffectPass(camera, effect); this.updatePass(pass); return pass; } updatePass(pass) { const effect = pass.effects[0]; effect.hue = this.pv.hue; effect.saturation = this.pv.saturation; effect.blendMode.opacity.value = this.pv.opacity; effect.blendMode.blendFunction = this.pv.blendFunction; } }