Skip to content

Commit

Permalink
breaking: disable normal pass by default, set gl to no tonemapping wh…
Browse files Browse the repository at this point in the history
…ile the composer is mounted
  • Loading branch information
drcmda committed Feb 15, 2024
1 parent d230437 commit fa0dd44
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/EffectComposer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TextureDataType } from 'three'
import { HalfFloatType } from 'three'
import { HalfFloatType, NoToneMapping } from 'three'
import React, {
forwardRef,
useMemo,
Expand Down Expand Up @@ -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
Expand All @@ -62,7 +63,7 @@ export const EffectComposer = React.memo(
renderPriority = 1,
autoClear = true,
depthBuffer,
disableNormalPass,
enableNormalPass,
stencilBuffer,
multisampling = 8,
frameBufferType = HalfFloatType,
Expand All @@ -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)
Expand All @@ -109,7 +110,7 @@ export const EffectComposer = React.memo(
multisampling,
frameBufferType,
scene,
disableNormalPass,
enableNormalPass,
resolutionScale,
])

Expand Down Expand Up @@ -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 }),
Expand Down

0 comments on commit fa0dd44

Please sign in to comment.