Skip to content

Commit fa0dd44

Browse files
committed
breaking: disable normal pass by default, set gl to no tonemapping while the composer is mounted
1 parent d230437 commit fa0dd44

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/EffectComposer.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TextureDataType } from 'three'
2-
import { HalfFloatType } from 'three'
2+
import { HalfFloatType, NoToneMapping } from 'three'
33
import React, {
44
forwardRef,
55
useMemo,
@@ -32,11 +32,12 @@ export const EffectComposerContext = createContext<{
3232
resolutionScale?: number
3333
}>(null!)
3434

35-
export type EffectComposerProps = {
35+
export type EffectComposerProps = {
3636
enabled?: boolean
3737
children: JSX.Element | JSX.Element[]
3838
depthBuffer?: boolean
39-
disableNormalPass?: boolean
39+
/** Only used for SSGI currently, leave it disabled for everything else unless it's needed */
40+
enableNormalPass?: boolean
4041
stencilBuffer?: boolean
4142
autoClear?: boolean
4243
resolutionScale?: number
@@ -62,7 +63,7 @@ export const EffectComposer = React.memo(
6263
renderPriority = 1,
6364
autoClear = true,
6465
depthBuffer,
65-
disableNormalPass,
66+
enableNormalPass,
6667
stencilBuffer,
6768
multisampling = 8,
6869
frameBufferType = HalfFloatType,
@@ -89,7 +90,7 @@ export const EffectComposer = React.memo(
8990
// Create normal pass
9091
let downSamplingPass = null
9192
let normalPass = null
92-
if (!disableNormalPass) {
93+
if (enableNormalPass) {
9394
normalPass = new NormalPass(scene, camera)
9495
normalPass.enabled = false
9596
effectComposer.addPass(normalPass)
@@ -109,7 +110,7 @@ export const EffectComposer = React.memo(
109110
multisampling,
110111
frameBufferType,
111112
scene,
112-
disableNormalPass,
113+
enableNormalPass,
113114
resolutionScale,
114115
])
115116

@@ -170,6 +171,15 @@ export const EffectComposer = React.memo(
170171
}
171172
}, [composer, children, camera, normalPass, downSamplingPass, instance])
172173

174+
// Disable tone mapping because threejs disallows tonemapping on render targets
175+
useEffect(() => {
176+
const currentTonemapping = gl.toneMapping
177+
gl.toneMapping = NoToneMapping
178+
return () => {
179+
gl.toneMapping = currentTonemapping
180+
}
181+
}, [])
182+
173183
// Memoize state, otherwise it would trigger all consumers on every render
174184
const state = useMemo(
175185
() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }),

0 commit comments

Comments
 (0)