@@ -18,6 +18,7 @@ import {
18
18
// @ts -ignore
19
19
DepthDownsamplingPass ,
20
20
Effect ,
21
+ Pass ,
21
22
} from 'postprocessing'
22
23
import { isWebGL2Available } from 'three-stdlib'
23
24
@@ -122,16 +123,34 @@ export const EffectComposer = React.memo(
122
123
const group = useRef ( null )
123
124
const instance = useInstanceHandle ( group )
124
125
useLayoutEffect ( ( ) => {
125
- let effectPass : EffectPass
126
+ const passes : Pass [ ] = [ ]
127
+
126
128
if ( group . current && instance . current && composer ) {
127
- effectPass = new EffectPass ( camera , ...( instance . current . objects as unknown as Effect [ ] ) )
128
- effectPass . renderToScreen = true
129
- composer . addPass ( effectPass )
129
+ const children = instance . current . objects as unknown [ ]
130
+
131
+ for ( let i = 0 ; i < children . length ; i ++ ) {
132
+ const child = children [ i ]
133
+
134
+ if ( child instanceof Effect ) {
135
+ const effects : Effect [ ] = [ ]
136
+ while ( children [ i ] instanceof Effect ) effects . push ( children [ i ++ ] as Effect )
137
+ i --
138
+
139
+ const pass = new EffectPass ( camera , ...effects )
140
+ passes . push ( pass )
141
+ } else if ( child instanceof Pass ) {
142
+ passes . push ( child )
143
+ }
144
+ }
145
+
146
+ for ( const pass of passes ) composer ?. addPass ( pass )
147
+
130
148
if ( normalPass ) normalPass . enabled = true
131
149
if ( downSamplingPass ) downSamplingPass . enabled = true
132
150
}
151
+
133
152
return ( ) => {
134
- if ( effectPass ) composer ?. removePass ( effectPass )
153
+ for ( const pass of passes ) composer ?. removePass ( pass )
135
154
if ( normalPass ) normalPass . enabled = false
136
155
if ( downSamplingPass ) downSamplingPass . enabled = false
137
156
}
0 commit comments