11import {
22 BasicDepthPacking ,
3- Color ,
43 DepthTexture ,
54 Matrix4 ,
65 Scene ,
@@ -15,10 +14,9 @@ import { Resolution } from "../core/Resolution.js";
1514import { BlendFunction } from "../enums/BlendFunction.js" ;
1615import { EffectAttribute } from "../enums/EffectAttribute.js" ;
1716import { KernelSize } from "../enums/KernelSize.js" ;
18- import { DepthMaskMaterial } from "../materials/DepthMaskMaterial.js" ;
1917import { GodRaysMaterial } from "../materials/GodRaysMaterial.js" ;
18+ import { CopyPass } from "../passes/CopyPass.js" ;
2019import { KawaseBlurPass } from "../passes/KawaseBlurPass.js" ;
21- import { ClearPass } from "../passes/ClearPass.js" ;
2220import { RenderPass } from "../passes/RenderPass.js" ;
2321import { ShaderPass } from "../passes/ShaderPass.js" ;
2422import { Effect } from "./Effect.js" ;
@@ -158,17 +156,7 @@ export class GodRaysEffect extends Effect {
158156 */
159157
160158 this . renderPassLight = new RenderPass ( this . lightScene , camera ) ;
161- this . renderPassLight . clearPass . overrideClearColor = new Color ( 0x000000 ) ;
162-
163- /**
164- * A clear pass.
165- *
166- * @type {ClearPass }
167- * @private
168- */
169-
170- this . clearPass = new ClearPass ( true , false , false ) ;
171- this . clearPass . overrideClearColor = new Color ( 0x000000 ) ;
159+ this . renderPassLight . clearPass . enabled = false ;
172160
173161 /**
174162 * A blur pass that reduces aliasing artifacts to make the light softer.
@@ -183,16 +171,14 @@ export class GodRaysEffect extends Effect {
183171 this . blurPass . enabled = blur ;
184172
185173 /**
186- * A depth mask pass.
174+ * A copy pass.
187175 *
188- * @type {ShaderPass }
176+ * @type {CopyPass }
189177 * @private
190178 */
191179
192- this . depthMaskPass = new ShaderPass ( new DepthMaskMaterial ( ) ) ;
193- const depthMaskMaterial = this . depthMaskMaterial ;
194- depthMaskMaterial . depthBuffer1 = this . renderTargetLight . depthTexture ;
195- depthMaskMaterial . copyCameraSettings ( camera ) ;
180+ this . copyPass = new CopyPass ( this . renderTargetLight ) ;
181+ this . copyPass . fullscreenMaterial . color = 0x000000 ;
196182
197183 /**
198184 * A god rays blur pass.
@@ -226,7 +212,6 @@ export class GodRaysEffect extends Effect {
226212
227213 this . camera = value ;
228214 this . renderPassLight . mainCamera = value ;
229- this . depthMaskMaterial . copyCameraSettings ( value ) ;
230215
231216 }
232217
@@ -293,19 +278,6 @@ export class GodRaysEffect extends Effect {
293278
294279 }
295280
296- /**
297- * The depth mask material.
298- *
299- * @type {DepthMaskMaterial }
300- * @private
301- */
302-
303- get depthMaskMaterial ( ) {
304-
305- return this . depthMaskPass . fullscreenMaterial ;
306-
307- }
308-
309281 /**
310282 * The internal god rays material.
311283 *
@@ -502,8 +474,8 @@ export class GodRaysEffect extends Effect {
502474
503475 setDepthTexture ( depthTexture , depthPacking = BasicDepthPacking ) {
504476
505- this . depthMaskPass . fullscreenMaterial . depthBuffer0 = depthTexture ;
506- this . depthMaskPass . fullscreenMaterial . depthPacking0 = depthPacking ;
477+ this . copyPass . fullscreenMaterial . depthBuffer = depthTexture ;
478+ this . copyPass . fullscreenMaterial . depthPacking = depthPacking ;
507479
508480 }
509481
@@ -547,9 +519,8 @@ export class GodRaysEffect extends Effect {
547519
548520 // Render the light source and mask it based on depth.
549521 this . lightScene . add ( lightSource ) ;
522+ this . copyPass . render ( renderer , inputBuffer ) ;
550523 this . renderPassLight . render ( renderer , renderTargetLight ) ;
551- this . clearPass . render ( renderer , renderTargetA ) ;
552- this . depthMaskPass . render ( renderer , renderTargetLight , renderTargetA ) ;
553524
554525 // Restore the original values.
555526 lightSource . material . depthWrite = false ;
@@ -576,15 +547,18 @@ export class GodRaysEffect extends Effect {
576547 Math . min ( Math . max ( ( v . y + 1.0 ) * 0.5 , - 1.0 ) , 2.0 )
577548 ) ;
578549
550+ let renderTarget = renderTargetLight ;
551+
579552 if ( this . blurPass . enabled ) {
580553
581554 // Blur the masked scene to reduce artifacts.
582- this . blurPass . render ( renderer , renderTargetA , renderTargetA ) ;
555+ this . blurPass . render ( renderer , renderTarget , renderTargetA ) ;
556+ renderTarget = renderTargetA ;
583557
584558 }
585559
586560 // Blur the masked scene along radial lines towards the light source.
587- this . godRaysPass . render ( renderer , renderTargetA , this . renderTargetB ) ;
561+ this . godRaysPass . render ( renderer , renderTarget , this . renderTargetB ) ;
588562
589563 }
590564
@@ -601,9 +575,9 @@ export class GodRaysEffect extends Effect {
601575 resolution . setBaseSize ( width , height ) ;
602576 const w = resolution . width , h = resolution . height ;
603577
578+ this . renderTargetLight . setSize ( width , height ) ;
604579 this . renderTargetA . setSize ( w , h ) ;
605580 this . renderTargetB . setSize ( w , h ) ;
606- this . renderTargetLight . setSize ( w , h ) ;
607581 this . blurPass . resolution . copy ( resolution ) ;
608582
609583 }
@@ -620,7 +594,7 @@ export class GodRaysEffect extends Effect {
620594
621595 this . blurPass . initialize ( renderer , alpha , frameBufferType ) ;
622596 this . renderPassLight . initialize ( renderer , alpha , frameBufferType ) ;
623- this . depthMaskPass . initialize ( renderer , alpha , frameBufferType ) ;
597+ this . copyPass . initialize ( renderer , alpha , frameBufferType ) ;
624598 this . godRaysPass . initialize ( renderer , alpha , frameBufferType ) ;
625599
626600 if ( frameBufferType !== undefined ) {
0 commit comments