Needle Engine

Changes between version 3.44.1 and 3.44.2
Files changed (4) hide show
  1. src/engine-components/postprocessing/Effects/ColorAdjustments.ts +7 -6
  2. src/engine-components/postprocessing/PostProcessingEffect.ts +1 -1
  3. src/engine-components/postprocessing/Effects/Tonemapping.ts +18 -3
  4. src/engine-components/postprocessing/VolumeParameter.ts +3 -4
src/engine-components/postprocessing/Effects/ColorAdjustments.ts CHANGED
@@ -30,7 +30,6 @@
30
30
  v = Math.pow(2.0, v);
31
31
  return v;
32
32
  }
33
- this.postExposure.defaultValue = 0;
34
33
 
35
34
  this.contrast.valueProcessor = (v: number) => {
36
35
  let divisor = 1;
@@ -62,16 +61,18 @@
62
61
 
63
62
 
64
63
  // find the ToneMapping effect because we need it to apply post exposure
65
- const hasTonemapping = this.postprocessingContext?.components.find(c => c instanceof ToneMappingEffect) as ToneMappingEffect;
66
- if(!hasTonemapping){
67
- this.postprocessingContext?.components.push(new ToneMappingEffect());
64
+ let tonemappingEffect = this.postprocessingContext?.components.find(c => c instanceof ToneMappingEffect) as ToneMappingEffect;
65
+ if (!tonemappingEffect) {
66
+ tonemappingEffect = new ToneMappingEffect();
67
+ this.postprocessingContext?.components.push(tonemappingEffect);
68
68
  }
69
69
 
70
70
  // We need this effect if someone uses ACES or AgX tonemapping;
71
71
  // problem is that we CAN'T use this effect for the "Linear" case, the package expects that in this case you remove the effect
72
72
  this.postExposure!.onValueChanged = (v) => {
73
- if (this.postExposure.overrideState)
74
- this.context.renderer.toneMappingExposure = v;
73
+ if (this.postExposure.overrideState) {
74
+ tonemappingEffect.exposure.value = v;
75
+ }
75
76
  };
76
77
 
77
78
  const brightnesscontrast = new BrightnessContrastEffect();
src/engine-components/postprocessing/PostProcessingEffect.ts CHANGED
@@ -59,7 +59,7 @@
59
59
  const value = params[key];
60
60
  const param = this[key];
61
61
  if (param instanceof VolumeParameter) {
62
- param.value = value;
62
+ param.initialize(value);
63
63
  }
64
64
  // allow assigning values to properties that are not VolumeParameters
65
65
  // this is useful when effects are created in code
src/engine-components/postprocessing/Effects/Tonemapping.ts CHANGED
@@ -73,6 +73,10 @@
73
73
  @serializable(VolumeParameter)
74
74
  readonly mode: VolumeParameter = new VolumeParameter(undefined);
75
75
 
76
+ @serializable(VolumeParameter)
77
+ readonly exposure: VolumeParameter = new VolumeParameter(1);
78
+
79
+ /** Set the tonemapping mode to e.g. "agx" */
76
80
  setMode(mode: NEToneMappingModeNames) {
77
81
  const enumValue = NEToneMappingMode[mode as NEToneMappingModeNames];
78
82
  if (enumValue === undefined) {
@@ -94,6 +98,7 @@
94
98
  }
95
99
 
96
100
  onCreateEffect(): EffectProviderResult | undefined {
101
+
97
102
  // TODO: this should be done in the PostProcessingHandler
98
103
  if (this.postprocessingContext) {
99
104
  for (const other of this.postprocessingContext.components) {
@@ -107,6 +112,7 @@
107
112
  }
108
113
  }
109
114
 
115
+
110
116
  // ensure the effect tonemapping value is initialized
111
117
  if (this.mode.isInitialized == false) {
112
118
  const init = threeToNeToneMapping(this.context.renderer.toneMapping);
@@ -120,15 +126,24 @@
120
126
  this.mode.onValueChanged = (newValue) => {
121
127
  const threeMode = toThreeToneMapping(newValue);
122
128
  tonemapping.mode = threeToneMappingToEffectMode(threeMode);
123
- if (debug) console.log("ToneMapping mode changed to", newValue, NEToneMappingMode[threeMode], ToneMappingMode[tonemapping.mode]);
129
+ if (debug) console.log("ToneMapping mode changed to", NEToneMappingMode[newValue], threeMode, tonemapping.mode);
124
130
  };
125
- if (debug) console.log("Use ToneMapping", this.context.renderer.toneMapping, this.mode.value, NEToneMappingMode[threeMode], ToneMappingMode[tonemapping.mode]);
131
+ if (debug) console.log("Use ToneMapping", NEToneMappingMode[this.mode.value], threeMode, tonemapping.mode, "renderer.tonemapping: " + this.context.renderer.toneMapping);
132
+
133
+
134
+ this.exposure.onValueChanged = (newValue) => {
135
+ this.context.renderer.toneMappingExposure = newValue;
136
+ };
137
+
126
138
  return tonemapping;
127
139
  }
128
140
 
129
141
 
130
142
  onBeforeRender(): void {
131
- this.context.renderer.toneMapping = toThreeToneMapping(this.mode.value);
143
+ if (this.mode.overrideState)
144
+ this.context.renderer.toneMapping = toThreeToneMapping(this.mode.value);
145
+ if (this.exposure.overrideState)
146
+ this.context.renderer.toneMappingExposure = this.exposure.value;
132
147
  }
133
148
 
134
149
 
src/engine-components/postprocessing/VolumeParameter.ts CHANGED
@@ -49,6 +49,8 @@
49
49
  return this._valueRaw;
50
50
  }
51
51
  set value(val: any) {
52
+ // When a user creates an effect and then just sets a VolumeParameter via `effect.param.value` we want to use this value as the initial value
53
+ if (!this.isInitialized) this.initialize(val);
52
54
  this.processValue(val, false);
53
55
  }
54
56
  private _value: any;
@@ -108,9 +110,6 @@
108
110
  if (this.onValueChanged) {
109
111
  this.onValueChanged(val, oldValue, this);
110
112
  }
111
- else if (debug) {
112
- console.log("VolumeParameter: onValueChanged not set");
113
- }
114
113
  }
115
114
 
116
115
  private testIfValueChanged(newValue: any): boolean {
@@ -147,7 +146,7 @@
147
146
 
148
147
  if (typeof data === "object" && "value" in data) {
149
148
  const value = data.value;
150
- parameter.value = value;
149
+ parameter.initialize(value);
151
150
  parameter.overrideState = data.overrideState;
152
151
  }
153
152
  else {