@@ -26,7 +26,7 @@ import { Matrix4 } from '../../math/Matrix4.js';
2626import { Vector2 } from '../../math/Vector2.js' ;
2727import { Vector4 } from '../../math/Vector4.js' ;
2828import { RenderTarget } from '../../core/RenderTarget.js' ;
29- import { DoubleSide , BackSide , FrontSide , SRGBColorSpace , NoToneMapping , LinearFilter , LinearSRGBColorSpace , HalfFloatType , RGBAFormat , PCFShadowMap } from '../../constants.js' ;
29+ import { DoubleSide , BackSide , FrontSide , SRGBColorSpace , NoToneMapping , LinearFilter , LinearSRGBColorSpace , HalfFloatType , RGBAFormat , PCFShadowMap , UnsignedByteType } from '../../constants.js' ;
3030
3131/** @module Renderer **/
3232
@@ -453,6 +453,15 @@ class Renderer {
453453 */
454454 this . _frameBufferTarget = null ;
455455
456+ /**
457+ * Used to identify the framebuffer target.
458+ *
459+ * @private
460+ * @type {Number? }
461+ * @default null
462+ */
463+ this . _frameBufferTargetKey = null ;
464+
456465 const alphaClear = this . alpha === true ? 0 : 1 ;
457466
458467 /**
@@ -1123,12 +1132,19 @@ class Renderer {
11231132
11241133 let frameBufferTarget = this . _frameBufferTarget ;
11251134
1126- if ( frameBufferTarget === null ) {
1135+ if ( frameBufferTarget === null || this . _frameBufferTargetKey !== currentToneMapping ) {
1136+
1137+ if ( frameBufferTarget !== null ) frameBufferTarget . dispose ( ) ;
1138+
1139+ // to improve performance we only want to use HalfFloatType if necessary
1140+ // HalfFloatType is required when a) tone mapping is configured or b) the backend specifically requests it
1141+
1142+ const type = ( currentToneMapping !== NoToneMapping || this . backend . needsHalfFloatFrameBufferTarget ( ) ) ? HalfFloatType : UnsignedByteType ;
11271143
11281144 frameBufferTarget = new RenderTarget ( width , height , {
11291145 depthBuffer : depth ,
11301146 stencilBuffer : stencil ,
1131- type : HalfFloatType , // FloatType
1147+ type : type ,
11321148 format : RGBAFormat ,
11331149 colorSpace : LinearSRGBColorSpace ,
11341150 generateMipmaps : false ,
@@ -1140,6 +1156,7 @@ class Renderer {
11401156 frameBufferTarget . isPostProcessingRenderTarget = true ;
11411157
11421158 this . _frameBufferTarget = frameBufferTarget ;
1159+ this . _frameBufferTargetKey = currentToneMapping ;
11431160
11441161 }
11451162
0 commit comments