Skip to content

Commit 984ca4a

Browse files
neilrackettMugen87
andauthored
Add FXAAPass class (#31044)
* Added FXAAPass class * Updated JSDocs and indentation * Fixed typo in docs * Update FXAAPass.js * Update FXAAPass.js Fix code style. --------- Co-authored-by: Michael Herzog <[email protected]>
1 parent a853687 commit 984ca4a

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { FXAAShader } from '../shaders/FXAAShader.js';
2+
import { ShaderPass } from './ShaderPass.js';
3+
4+
/**
5+
* A pass for applying FXAA.
6+
*
7+
* ```js
8+
* const fxaaPass = new FXAAPass();
9+
* composer.addPass( fxaaPass );
10+
* ```
11+
*
12+
* @augments ShaderPass
13+
* @three_import import { FXAAPass } from 'three/addons/postprocessing/FXAAPass.js';
14+
*/
15+
class FXAAPass extends ShaderPass {
16+
17+
/**
18+
* Constructs a new FXAA pass.
19+
*/
20+
constructor() {
21+
22+
super( FXAAShader );
23+
24+
}
25+
26+
/**
27+
* Sets the size of the pass.
28+
*
29+
* @param {number} width - The width to set.
30+
* @param {number} height - The height to set.
31+
*/
32+
setSize( width, height ) {
33+
34+
this.material.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
35+
36+
}
37+
38+
}
39+
40+
export { FXAAPass };

examples/webgl_postprocessing_fxaa.html

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
5151
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
5252
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
53-
import { FXAAShader } from 'three/addons/shaders/FXAAShader.js';
53+
import { FXAAPass } from 'three/addons/postprocessing/FXAAPass.js';
5454
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
5555

5656
let camera, scene, renderer, controls, container;
@@ -119,7 +119,7 @@
119119

120120
//
121121

122-
fxaaPass = new ShaderPass( FXAAShader );
122+
fxaaPass = new FXAAPass();
123123

124124
const outputPass = new OutputPass();
125125

@@ -129,11 +129,6 @@
129129

130130
//
131131

132-
const pixelRatio = renderer.getPixelRatio();
133-
134-
fxaaPass.material.uniforms[ 'resolution' ].value.x = 1 / ( container.offsetWidth * pixelRatio );
135-
fxaaPass.material.uniforms[ 'resolution' ].value.y = 1 / ( container.offsetHeight * pixelRatio );
136-
137132
composer2 = new EffectComposer( renderer );
138133
composer2.addPass( renderPass );
139134
composer2.addPass( outputPass );
@@ -157,11 +152,6 @@
157152
composer1.setSize( container.offsetWidth, container.offsetHeight );
158153
composer2.setSize( container.offsetWidth, container.offsetHeight );
159154

160-
const pixelRatio = renderer.getPixelRatio();
161-
162-
fxaaPass.material.uniforms[ 'resolution' ].value.x = 1 / ( container.offsetWidth * pixelRatio );
163-
fxaaPass.material.uniforms[ 'resolution' ].value.y = 1 / ( container.offsetHeight * pixelRatio );
164-
165155
}
166156

167157
function animate() {

0 commit comments

Comments
 (0)