1- import { Event as Event3 , Material , Texture } from "three" ;
1+ import { Event as Event3 , Material , Texture , WebGLRenderer } from "three" ;
22import { Pass } from "../core/Pass.js" ;
33import { Effect } from "../effects/Effect.js" ;
44import { GBuffer } from "../enums/GBuffer.js" ;
@@ -76,6 +76,19 @@ export class EffectPass extends Pass<EffectMaterial> {
7676
7777 }
7878
79+ override get renderer ( ) : WebGLRenderer | null {
80+
81+ return super . renderer ;
82+
83+ }
84+
85+ override set renderer ( value : WebGLRenderer | null ) {
86+
87+ super . renderer = value ;
88+ this . updateMaterialTransparency ( ) ;
89+
90+ }
91+
7992 override get subpasses ( ) : readonly Pass < Material | null > [ ] {
8093
8194 return super . subpasses ;
@@ -188,6 +201,7 @@ export class EffectPass extends Pass<EffectMaterial> {
188201
189202 // Get the material for the current effect combination.
190203 this . fullscreenMaterial = this . effectMaterialManager . getMaterial ( this . effects ) ;
204+ this . updateMaterialTransparency ( ) ;
191205
192206 // Pick up new materials.
193207 for ( const material of this . effectMaterialManager . materials ) {
@@ -198,6 +212,24 @@ export class EffectPass extends Pass<EffectMaterial> {
198212
199213 }
200214
215+ /**
216+ * Updates the fullscreen material to use alpha blending if needed.
217+ */
218+
219+ private updateMaterialTransparency ( ) : void {
220+
221+ if ( this . renderer === null ) {
222+
223+ return ;
224+
225+ }
226+
227+ const alpha = this . renderer . getContext ( ) . getContextAttributes ( ) ?. alpha ?? false ;
228+ const outputBuffer = this . output . defaultBuffer ?. value ?? null ;
229+ this . fullscreenMaterial . transparent = ( alpha && outputBuffer === null ) ;
230+
231+ }
232+
201233 /**
202234 * Updates the G-Buffer struct uniform.
203235 */
@@ -340,6 +372,12 @@ export class EffectPass extends Pass<EffectMaterial> {
340372
341373 }
342374
375+ protected override onOutputChange ( ) : void {
376+
377+ this . updateMaterialTransparency ( ) ;
378+
379+ }
380+
343381 override checkRequirements ( ) : void {
344382
345383 for ( const effect of this . effects ) {
0 commit comments