@@ -148,6 +148,12 @@ export abstract class Pass<TMaterial extends Material | null = null>
148148
149149 private _attached : boolean ;
150150
151+ /**
152+ * @see {@link autoSyncDefaultBuffers }
153+ */
154+
155+ private _autoSyncDefaultBuffers : boolean ;
156+
151157 /**
152158 * @see {@link timer }
153159 */
@@ -251,6 +257,7 @@ export abstract class Pass<TMaterial extends Material | null = null>
251257 this . _name = name ;
252258 this . _enabled = true ;
253259 this . _attached = false ;
260+ this . _autoSyncDefaultBuffers = true ;
254261 this . _renderer = null ;
255262 this . _timer = null ;
256263 this . _scene = null ;
@@ -339,6 +346,29 @@ export abstract class Pass<TMaterial extends Material | null = null>
339346
340347 }
341348
349+ /**
350+ * Controls whether the settings of the input and output default buffers should be synchronized.
351+ *
352+ * @defaultValue true
353+ */
354+
355+ protected get autoSyncDefaultBuffers ( ) : boolean {
356+
357+ return this . _autoSyncDefaultBuffers ;
358+
359+ }
360+
361+ protected set autoSyncDefaultBuffers ( value : boolean ) {
362+
363+ if ( this . _autoSyncDefaultBuffers !== value ) {
364+
365+ this . _autoSyncDefaultBuffers = value ;
366+ this . syncDefaultBuffers ( ) ;
367+
368+ }
369+
370+ }
371+
342372 /**
343373 * A list of subpasses.
344374 *
@@ -729,6 +759,59 @@ export abstract class Pass<TMaterial extends Material | null = null>
729759
730760 }
731761
762+ /**
763+ * Synchronizes the texture settings of the input and output default buffers.
764+ *
765+ * This method ensures that the output buffer uses adequate settings for storing values from the input buffer.
766+ */
767+
768+ private syncDefaultBuffers ( ) : void {
769+
770+ const renderer = this . renderer ;
771+ const inputBuffer = this . input . defaultBuffer ?. value ?? null ;
772+ const outputBuffer = this . output . defaultBuffer ?. value ?? null ;
773+
774+ if ( ! this . autoSyncDefaultBuffers || renderer === null || inputBuffer === null || outputBuffer === null ) {
775+
776+ return ;
777+
778+ }
779+
780+ const texture = outputBuffer . texture ;
781+
782+ texture . needsUpdate = (
783+ texture . format !== inputBuffer . format ||
784+ texture . internalFormat !== inputBuffer . internalFormat ||
785+ texture . type !== inputBuffer . type
786+ ) ;
787+
788+ if ( texture . needsUpdate ) {
789+
790+ texture . format = inputBuffer . format ;
791+ texture . internalFormat = inputBuffer . internalFormat ;
792+ texture . type = inputBuffer . type ;
793+
794+ }
795+
796+ // If the output buffer uses low precision, enable sRGB encoding to reduce information loss.
797+ const useSRGBFramebuffer = ! this . output . frameBufferPrecisionHigh && renderer . outputColorSpace === SRGBColorSpace ;
798+
799+ if ( useSRGBFramebuffer && texture . colorSpace !== SRGBColorSpace ) {
800+
801+ texture . colorSpace = SRGBColorSpace ;
802+ texture . needsUpdate = true ;
803+
804+ }
805+
806+ if ( texture . needsUpdate ) {
807+
808+ // Notify listeners.
809+ this . output . defaultBuffer ! . texture . setChanged ( ) ;
810+
811+ }
812+
813+ }
814+
732815 /**
733816 * Checks if this pass uses convolution shaders.
734817 *
@@ -1133,6 +1216,7 @@ export abstract class Pass<TMaterial extends Material | null = null>
11331216
11341217 case "change" :
11351218 this . updateFullscreenMaterialsInput ( ) ;
1219+ this . syncDefaultBuffers ( ) ;
11361220 this . onInputChange ( ) ;
11371221 break ;
11381222
@@ -1159,6 +1243,7 @@ export abstract class Pass<TMaterial extends Material | null = null>
11591243 case "change" :
11601244 this . updateOutputBufferSize ( ) ;
11611245 this . updateFullscreenMaterialsOutput ( ) ;
1246+ this . syncDefaultBuffers ( ) ;
11621247 this . onOutputChange ( ) ;
11631248 break ;
11641249
0 commit comments