Skip to content

Commit 63f3dfc

Browse files
committed
Add autoSRGB setting
1 parent 191e032 commit 63f3dfc

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/core/Pass.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ export abstract class Pass<TMaterial extends Material | null = null>
154154

155155
private _autoSyncDefaultBuffers: boolean;
156156

157+
/**
158+
* @see {@link autoSRGB}
159+
*/
160+
161+
private _autoSRGB: boolean;
162+
157163
/**
158164
* @see {@link timer}
159165
*/
@@ -258,6 +264,7 @@ export abstract class Pass<TMaterial extends Material | null = null>
258264
this._enabled = true;
259265
this._attached = false;
260266
this._autoSyncDefaultBuffers = true;
267+
this._autoSRGB = true;
261268
this._renderer = null;
262269
this._timer = null;
263270
this._scene = null;
@@ -369,6 +376,29 @@ export abstract class Pass<TMaterial extends Material | null = null>
369376

370377
}
371378

379+
/**
380+
* Controls automatic sRGB encoding for low precision output buffers.
381+
*
382+
* @defaultValue true
383+
*/
384+
385+
protected get autoSRGB(): boolean {
386+
387+
return this._autoSRGB;
388+
389+
}
390+
391+
protected set autoSRGB(value: boolean) {
392+
393+
if(this._autoSRGB !== value) {
394+
395+
this._autoSRGB = value;
396+
this.syncDefaultBuffers();
397+
398+
}
399+
400+
}
401+
372402
/**
373403
* A list of subpasses.
374404
*
@@ -828,9 +858,13 @@ export abstract class Pass<TMaterial extends Material | null = null>
828858
}
829859

830860
// If the output buffer uses low precision, enable sRGB encoding to reduce information loss.
831-
const useSRGBFramebuffer = !this.output.frameBufferPrecisionHigh && renderer.outputColorSpace === SRGBColorSpace;
861+
const useSRGB = (
862+
this.autoSRGB &&
863+
!this.output.frameBufferPrecisionHigh &&
864+
renderer.outputColorSpace === SRGBColorSpace
865+
);
832866

833-
if(useSRGBFramebuffer && texture.colorSpace !== SRGBColorSpace) {
867+
if(useSRGB && texture.colorSpace !== SRGBColorSpace) {
834868

835869
texture.colorSpace = SRGBColorSpace;
836870
texture.needsUpdate = true;

src/passes/GeometryPass.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,22 @@ export class GeometryPass extends Pass implements GeometryPassOptions, Selective
420420
}
421421

422422
const indices = extractIndices(gBuffer);
423-
const useSRGB = (!this.frameBufferPrecisionHigh && renderer.outputColorSpace === SRGBColorSpace);
424-
const colorSpace = useSRGB ? SRGBColorSpace : NoColorSpace;
423+
424+
// If the output buffer uses low precision, enable sRGB encoding to reduce information loss.
425+
const useSRGB = (
426+
this.autoSRGB &&
427+
!this.frameBufferPrecisionHigh &&
428+
renderer.outputColorSpace === SRGBColorSpace
429+
);
425430

426431
for(const entry of this.textureConfigs) {
427432

428433
if(entry[1].isColorBuffer === true && indices.has(entry[0])) {
429434

430435
const index = indices.get(entry[0])!;
431-
gBuffer.textures[index].colorSpace = colorSpace;
436+
const texture = gBuffer.textures[index];
437+
texture.colorSpace = useSRGB ? SRGBColorSpace : NoColorSpace;
438+
texture.needsUpdate = true;
432439

433440
}
434441

0 commit comments

Comments
 (0)