UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in

93 lines 4.3 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { NoToneMapping } from "three"; import { MODULES } from "../../../engine/engine_modules.js"; import { serializable } from "../../../engine/engine_serialization.js"; import { PostProcessingEffect } from "../PostProcessingEffect.js"; import { VolumeParameter } from "../VolumeParameter.js"; import { registerCustomEffectType } from "../VolumeProfile.js"; import { ToneMappingEffect } from "./Tonemapping.js"; /** * @category Effects * @group Components */ export class ColorAdjustments extends PostProcessingEffect { get typeName() { return "ColorAdjustments"; } postExposure = new VolumeParameter(0); contrast = new VolumeParameter(0); hueShift = new VolumeParameter(0); saturation = new VolumeParameter(0); init() { this.postExposure.valueProcessor = v => { v = Math.pow(2.0, v); return v; }; this.contrast.valueProcessor = (v) => { let divisor = 1; if (v > 0) divisor = 200; else if (v < 0) divisor = 100; // if (v > 0) divisor *= Math.PI; const val = v / divisor; return val; }; this.contrast.defaultValue = 0; this.hueShift.valueProcessor = (v) => Math.PI * v / 180; this.hueShift.defaultValue = 0; this.saturation.valueProcessor = (v) => { if (v < 0) return (v / 100); const sat = (v / (100 * Math.PI)); return sat; }; this.saturation.defaultValue = 0; } onCreateEffect() { const effects = []; // TODO: do we still need this? if (this.context.renderer.toneMapping !== NoToneMapping && this.postExposure.overrideState) this.context.renderer.toneMapping = NoToneMapping; // find the ToneMapping effect because we need it to apply post exposure let tonemappingEffect = this.postprocessingContext?.components.find(c => c instanceof ToneMappingEffect); if (!tonemappingEffect) { tonemappingEffect = new ToneMappingEffect(); this.postprocessingContext?.components.push(tonemappingEffect); } // We need this effect if someone uses ACES or AgX tonemapping; // problem is that we CAN'T use this effect for the "Linear" case, the package expects that in this case you remove the effect this.postExposure.onValueChanged = (v) => { if (this.postExposure.overrideState) { tonemappingEffect.exposure.value = v; } }; const brightnesscontrast = new MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect(); this.contrast.onValueChanged = v => brightnesscontrast.contrast = v; const hueSaturationEffect = new MODULES.POSTPROCESSING.MODULE.HueSaturationEffect(); effects.push(brightnesscontrast); effects.push(hueSaturationEffect); this.hueShift.onValueChanged = v => hueSaturationEffect.hue = v; this.saturation.onValueChanged = v => hueSaturationEffect.saturation = v; return effects; } } __decorate([ serializable(VolumeParameter) ], ColorAdjustments.prototype, "postExposure", void 0); __decorate([ serializable(VolumeParameter) ], ColorAdjustments.prototype, "contrast", void 0); __decorate([ serializable(VolumeParameter) ], ColorAdjustments.prototype, "hueShift", void 0); __decorate([ serializable(VolumeParameter) ], ColorAdjustments.prototype, "saturation", void 0); registerCustomEffectType("ColorAdjustments", ColorAdjustments); //# sourceMappingURL=ColorAdjustments.js.map