Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Add FXAANode. #28859

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"webgpu_postprocessing_anamorphic",
"webgpu_postprocessing_ao",
"webgpu_postprocessing_dof",
"webgpu_postprocessing_fxaa",
"webgpu_postprocessing_sobel",
"webgpu_postprocessing",
"webgpu_procedural_texture",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 166 additions & 0 deletions examples/webgpu_postprocessing_fxaa.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgpu - FXAA</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>

<body>

<script type="importmap">
{
"imports": {
"three": "../build/three.webgpu.js",
"three/tsl": "../build/three.webgpu.js",
"three/addons/": "./jsm/"
}
}
</script>

<script type="module">

import * as THREE from 'three';
import { pass, renderOutput } from 'three/tsl';

import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

const params = {
enabled: true,
animated: false
};

let camera, scene, renderer, clock, group;
let postProcessing;

init();

async function init() {

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 200 );
camera.position.z = 50;

scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );

clock = new THREE.Clock();

//

const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d );
hemiLight.position.set( 0, 1000, 0 );
scene.add( hemiLight );

const dirLight = new THREE.DirectionalLight( 0xffffff, 3 );
dirLight.position.set( - 3000, 1000, - 1000 );
scene.add( dirLight );

//

group = new THREE.Group();

const geometry = new THREE.TetrahedronGeometry();
const material = new THREE.MeshStandardMaterial( { color: 0xf73232, flatShading: true } );

for ( let i = 0; i < 100; i ++ ) {

const mesh = new THREE.Mesh( geometry, material );

mesh.position.x = Math.random() * 50 - 25;
mesh.position.y = Math.random() * 50 - 25;
mesh.position.z = Math.random() * 50 - 25;

mesh.scale.setScalar( Math.random() * 2 + 1 );

mesh.rotation.x = Math.random() * Math.PI;
mesh.rotation.y = Math.random() * Math.PI;
mesh.rotation.z = Math.random() * Math.PI;

group.add( mesh );

}

scene.add( group );

renderer = new THREE.WebGPURenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

// post processing

postProcessing = new THREE.PostProcessing( renderer );

// ignore default output color transform ( toneMapping and outputColorSpace )
// use renderOutput() for control the sequence

postProcessing.outputColorTransform = false;

// scene pass

const scenePass = pass( scene, camera );
const outputPass = renderOutput( scenePass );

// FXAA must be computed in sRGB color space (so after tone mapping and color space conversion)

const fxaaPass = outputPass.fxaa();
postProcessing.outputNode = fxaaPass;

//

window.addEventListener( 'resize', onWindowResize );

//

const gui = new GUI();
gui.title( 'FXAA settings' );
gui.add( params, 'enabled' ).onChange( ( value ) => {

if ( value === true ) {

postProcessing.outputNode = fxaaPass;

} else {

postProcessing.outputNode = outputPass;

}

postProcessing.needsUpdate = true;

} );
gui.add( params, 'animated' );

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

}

//

function animate() {

const delta = clock.getDelta();

if ( params.animated === true ) {

group.rotation.y += delta * 0.1;

}

postProcessing.render();

}

</script>

</body>
</html>
1 change: 1 addition & 0 deletions src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export { default as RGBShiftNode, rgbShift } from './display/RGBShiftNode.js';
export { default as FilmNode, film } from './display/FilmNode.js';
export { default as Lut3DNode, lut3D } from './display/Lut3DNode.js';
export { default as GTAONode, ao } from './display/GTAONode.js';
export { default as FXAANode, fxaa } from './display/FXAANode.js';
export { default as RenderOutputNode, renderOutput } from './display/RenderOutputNode.js';

export { default as PassNode, pass, passTexture, depthPass } from './display/PassNode.js';
Expand Down
Loading