From fa0dd4427f83e5997fe773851f6c60bea7cb3bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=94?= Date: Thu, 15 Feb 2024 14:33:55 +0100 Subject: [PATCH] breaking: disable normal pass by default, set gl to no tonemapping while the composer is mounted --- src/EffectComposer.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/EffectComposer.tsx b/src/EffectComposer.tsx index f4490cd..cc3db74 100644 --- a/src/EffectComposer.tsx +++ b/src/EffectComposer.tsx @@ -1,5 +1,5 @@ import type { TextureDataType } from 'three' -import { HalfFloatType } from 'three' +import { HalfFloatType, NoToneMapping } from 'three' import React, { forwardRef, useMemo, @@ -32,11 +32,12 @@ export const EffectComposerContext = createContext<{ resolutionScale?: number }>(null!) -export type EffectComposerProps = { +export type EffectComposerProps = { enabled?: boolean children: JSX.Element | JSX.Element[] depthBuffer?: boolean - disableNormalPass?: boolean + /** Only used for SSGI currently, leave it disabled for everything else unless it's needed */ + enableNormalPass?: boolean stencilBuffer?: boolean autoClear?: boolean resolutionScale?: number @@ -62,7 +63,7 @@ export const EffectComposer = React.memo( renderPriority = 1, autoClear = true, depthBuffer, - disableNormalPass, + enableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = HalfFloatType, @@ -89,7 +90,7 @@ export const EffectComposer = React.memo( // Create normal pass let downSamplingPass = null let normalPass = null - if (!disableNormalPass) { + if (enableNormalPass) { normalPass = new NormalPass(scene, camera) normalPass.enabled = false effectComposer.addPass(normalPass) @@ -109,7 +110,7 @@ export const EffectComposer = React.memo( multisampling, frameBufferType, scene, - disableNormalPass, + enableNormalPass, resolutionScale, ]) @@ -170,6 +171,15 @@ export const EffectComposer = React.memo( } }, [composer, children, camera, normalPass, downSamplingPass, instance]) + // Disable tone mapping because threejs disallows tonemapping on render targets + useEffect(() => { + const currentTonemapping = gl.toneMapping + gl.toneMapping = NoToneMapping + return () => { + gl.toneMapping = currentTonemapping + } + }, []) + // Memoize state, otherwise it would trigger all consumers on every render const state = useMemo( () => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }),