1- import { Texture , WebGLRenderTarget } from "three" ;
1+ import { WebGLRenderTarget } from "three" ;
2+ import { TextureResource } from "../core/io/TextureResource.js" ;
23import { Pass } from "../core/Pass.js" ;
34import { GaussianBlurMaterial } from "../materials/GaussianBlurMaterial.js" ;
45
@@ -45,16 +46,16 @@ export interface GaussianBlurPassOptions {
4546export class GaussianBlurPass extends Pass < GaussianBlurMaterial > {
4647
4748 /**
48- * The first blur buffer.
49+ * Identifies the first blur buffer.
4950 */
5051
51- private readonly renderTargetA : WebGLRenderTarget ;
52+ private static readonly BUFFER_A = "BUFFER_A" ;
5253
5354 /**
54- * The second blur buffer.
55+ * Identifies the second blur buffer.
5556 */
5657
57- private readonly renderTargetB : WebGLRenderTarget ;
58+ private static readonly BUFFER_B = "BUFFER_B" ;
5859
5960 /**
6061 * The amount of blur iterations.
@@ -72,14 +73,8 @@ export class GaussianBlurPass extends Pass<GaussianBlurMaterial> {
7273
7374 super ( "GaussianBlurPass" ) ;
7475
75- const renderTargetA = this . createFramebuffer ( ) ;
76- const renderTargetB = this . createFramebuffer ( ) ;
77- renderTargetA . texture . name = "BUFFER_0" ;
78- renderTargetB . texture . name = "BUFFER_1" ;
79- this . output . setBuffer ( renderTargetA . texture . name , renderTargetA ) ;
80- this . output . setBuffer ( renderTargetB . texture . name , renderTargetB ) ;
81- this . renderTargetA = renderTargetA ;
82- this . renderTargetB = renderTargetB ;
76+ this . output . setBuffer ( GaussianBlurPass . BUFFER_A , this . createFramebuffer ( ) ) ;
77+ this . output . setBuffer ( GaussianBlurPass . BUFFER_B , this . createFramebuffer ( ) ) ;
8378
8479 this . fullscreenMaterial = new GaussianBlurMaterial ( { kernelSize } ) ;
8580 this . resolution . scale = resolutionScale ;
@@ -97,13 +92,33 @@ export class GaussianBlurPass extends Pass<GaussianBlurMaterial> {
9792
9893 }
9994
95+ /**
96+ * The first blur render target.
97+ */
98+
99+ private get renderTargetA ( ) : WebGLRenderTarget {
100+
101+ return this . output . getBuffer ( GaussianBlurPass . BUFFER_A ) ! ;
102+
103+ }
104+
105+ /**
106+ * The second blur render target.
107+ */
108+
109+ private get renderTargetB ( ) : WebGLRenderTarget {
110+
111+ return this . output . getBuffer ( GaussianBlurPass . BUFFER_B ) ! ;
112+
113+ }
114+
100115 /**
101116 * A texture that contains the blurred result.
102117 */
103118
104- get texture ( ) : Texture {
119+ get texture ( ) : TextureResource {
105120
106- return this . renderTargetB . texture ;
121+ return this . output . buffers . get ( GaussianBlurPass . BUFFER_B ) ! . texture ;
107122
108123 }
109124
@@ -117,13 +132,13 @@ export class GaussianBlurPass extends Pass<GaussianBlurMaterial> {
117132
118133 const { type, colorSpace } = this . input . defaultBuffer . value ;
119134
120- this . renderTargetA . texture . type = type ;
121- this . renderTargetA . texture . colorSpace = colorSpace ;
122- this . renderTargetA . dispose ( ) ;
135+ for ( const renderTarget of [ this . renderTargetA , this . renderTargetB ] ) {
123136
124- this . renderTargetB . texture . type = type ;
125- this . renderTargetB . texture . colorSpace = colorSpace ;
126- this . renderTargetB . dispose ( ) ;
137+ renderTarget . texture . type = type ;
138+ renderTarget . texture . colorSpace = colorSpace ;
139+ renderTarget . dispose ( ) ;
140+
141+ }
127142
128143 if ( this . input . frameBufferPrecisionHigh ) {
129144
@@ -155,7 +170,7 @@ export class GaussianBlurPass extends Pass<GaussianBlurMaterial> {
155170
156171 override render ( ) : void {
157172
158- if ( this . renderer === null || this . input . defaultBuffer ? .value === null ) {
173+ if ( this . renderer === null || this . input . defaultBuffer === null || this . input . defaultBuffer . value === null ) {
159174
160175 return ;
161176
@@ -166,7 +181,7 @@ export class GaussianBlurPass extends Pass<GaussianBlurMaterial> {
166181 const renderTargetB = this . renderTargetB ;
167182 const blurMaterial = this . blurMaterial ;
168183
169- let previousBuffer = this . input . defaultBuffer ! . value ;
184+ let previousBuffer = this . input . defaultBuffer . value ;
170185
171186 for ( let i = 0 , l = Math . max ( this . iterations , 1 ) ; i < l ; ++ i ) {
172187
0 commit comments