Răsfoiți Sursa

Examples: Implement dispose() in post processing passes. (#24724)

Michael Herzog 2 ani în urmă
părinte
comite
a232277a2b

+ 17 - 4
examples/jsm/postprocessing/AfterimagePass.js

@@ -30,7 +30,7 @@ class AfterimagePass extends Pass {
 			magFilter: NearestFilter,
 		} );
 
-		this.shaderMaterial = new ShaderMaterial( {
+		this.compFsMaterial = new ShaderMaterial( {
 
 			uniforms: this.uniforms,
 			vertexShader: this.shader.vertexShader,
@@ -38,10 +38,10 @@ class AfterimagePass extends Pass {
 
 		} );
 
-		this.compFsQuad = new FullScreenQuad( this.shaderMaterial );
+		this.compFsQuad = new FullScreenQuad( this.compFsMaterial );
 
-		const material = new MeshBasicMaterial();
-		this.copyFsQuad = new FullScreenQuad( material );
+		this.copyFsMaterial = new MeshBasicMaterial();
+		this.copyFsQuad = new FullScreenQuad( this.copyFsMaterial );
 
 	}
 
@@ -85,6 +85,19 @@ class AfterimagePass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.textureComp.dispose();
+		this.textureOld.dispose();
+
+		this.compFsMaterial.dispose();
+		this.copyFsMaterial.dispose();
+
+		this.compFsQuad.dispose();
+		this.copyFsQuad.dispose();
+
+	}
+
 }
 
 export { AfterimagePass };

+ 12 - 0
examples/jsm/postprocessing/BloomPass.js

@@ -105,6 +105,18 @@ class BloomPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.renderTargetX.dispose();
+		this.renderTargetY.dispose();
+
+		this.materialCombine.dispose();
+		this.materialConvolution.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 const CombineShader = {

+ 11 - 0
examples/jsm/postprocessing/BokehPass.js

@@ -126,6 +126,17 @@ class BokehPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.renderTargetDepth.dispose();
+
+		this.materialDepth.dispose();
+		this.materialBokeh.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { BokehPass };

+ 7 - 0
examples/jsm/postprocessing/CubeTexturePass.js

@@ -73,6 +73,13 @@ class CubeTexturePass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.cubeMesh.geometry.dispose();
+		this.cubeMesh.material.dispose();
+
+	}
+
 }
 
 export { CubeTexturePass };

+ 8 - 0
examples/jsm/postprocessing/DotScreenPass.js

@@ -53,6 +53,14 @@ class DotScreenPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.material.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { DotScreenPass };

+ 8 - 0
examples/jsm/postprocessing/FilmPass.js

@@ -54,6 +54,14 @@ class FilmPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.material.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { FilmPass };

+ 13 - 1
examples/jsm/postprocessing/GlitchPass.js

@@ -22,7 +22,9 @@ class GlitchPass extends Pass {
 
 		this.uniforms = UniformsUtils.clone( shader.uniforms );
 
-		this.uniforms[ 'tDisp' ].value = this.generateHeightmap( dt_size );
+		this.heightMap = this.generateHeightmap( dt_size );
+
+		this.uniforms[ 'tDisp' ].value = this.heightMap;
 
 		this.material = new ShaderMaterial( {
 			uniforms: this.uniforms,
@@ -113,6 +115,16 @@ class GlitchPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.material.dispose();
+
+		this.heightMap.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { GlitchPass };

+ 8 - 0
examples/jsm/postprocessing/HalftonePass.js

@@ -72,6 +72,14 @@ class HalftonePass extends Pass {
 
  	}
 
+	dispose() {
+
+		this.material.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { HalftonePass };

+ 10 - 0
examples/jsm/postprocessing/OutlinePass.js

@@ -140,6 +140,16 @@ class OutlinePass extends Pass {
 		this.renderTargetEdgeBuffer1.dispose();
 		this.renderTargetEdgeBuffer2.dispose();
 
+		this.depthMaterial.dispose();
+		this.prepareMaskMaterial.dispose();
+		this.edgeDetectionMaterial.dispose();
+		this.separableBlurMaterial1.dispose();
+		this.separableBlurMaterial2.dispose();
+		this.overlayMaterial.dispose();
+		this.materialCopy.dispose();
+
+		this.fsQuad.dispose();
+
 	}
 
 	setSize( width, height ) {

+ 20 - 0
examples/jsm/postprocessing/SAOPass.js

@@ -400,6 +400,26 @@ class SAOPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.saoRenderTarget.dispose();
+		this.blurIntermediateRenderTarget.dispose();
+		this.beautyRenderTarget.dispose();
+		this.normalRenderTarget.dispose();
+		this.depthRenderTarget.dispose();
+
+		this.depthMaterial.dispose();
+		this.normalMaterial.dispose();
+		this.saoMaterial.dispose();
+		this.vBlurMaterial.dispose();
+		this.hBlurMaterial.dispose();
+		this.materialCopy.dispose();
+		this.depthCopy.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 SAOPass.OUTPUT = {

+ 16 - 0
examples/jsm/postprocessing/SMAAPass.js

@@ -183,6 +183,22 @@ class SMAAPass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.edgesRT.dispose();
+		this.weightsRT.dispose();
+
+		this.areaTexture.dispose();
+		this.searchTexture.dispose();
+
+		this.materialEdges.dispose();
+		this.materialWeights.dispose();
+		this.materialBlend.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { SMAAPass };

+ 4 - 0
examples/jsm/postprocessing/SSAARenderPass.js

@@ -63,6 +63,10 @@ class SSAARenderPass extends Pass {
 
 		}
 
+		this.copyMaterial.dispose();
+
+		this.fsQuad.dispose();
+
 	}
 
 	setSize( width, height ) {

+ 10 - 0
examples/jsm/postprocessing/SavePass.js

@@ -57,6 +57,16 @@ class SavePass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.renderTarget.dispose();
+
+		this.material.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { SavePass };

+ 2 - 1
examples/jsm/postprocessing/ShaderPass.js

@@ -65,9 +65,10 @@ class ShaderPass extends Pass {
 
 	dispose() {
 
-		this.fsQuad.dispose();
 		this.material.dispose();
 
+		this.fsQuad.dispose();
+
 	}
 
 }

+ 9 - 0
examples/jsm/postprocessing/TAARenderPass.js

@@ -130,6 +130,15 @@ class TAARenderPass extends SSAARenderPass {
 
 	}
 
+	dispose() {
+
+		super.dispose();
+
+		if ( this.sampleRenderTarget !== undefined ) this.sampleRenderTarget.dispose();
+		if ( this.holdRenderTarget !== undefined ) this.holdRenderTarget.dispose();
+
+	}
+
 }
 
 const _JitterVectors = [

+ 8 - 0
examples/jsm/postprocessing/TexturePass.js

@@ -55,6 +55,14 @@ class TexturePass extends Pass {
 
 	}
 
+	dispose() {
+
+		this.material.dispose();
+
+		this.fsQuad.dispose();
+
+	}
+
 }
 
 export { TexturePass };

+ 16 - 0
examples/jsm/postprocessing/UnrealBloomPass.js

@@ -170,6 +170,22 @@ class UnrealBloomPass extends Pass {
 
 		this.renderTargetBright.dispose();
 
+		//
+
+		for ( let i = 0; i < this.separableBlurMaterials.length; i ++ ) {
+
+			this.separableBlurMaterials[ i ].dispose();
+
+		}
+
+		this.compositeMaterial.dispose();
+		this.materialCopy.dispose();
+		this.basic.dispose();
+
+		//
+
+		this.fsQuad.dispose();
+
 	}
 
 	setSize( width, height ) {