You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
3.8 KiB
HTML
169 lines
3.8 KiB
HTML
2 months ago
|
<!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/webgpu": "../build/three.webgpu.js",
|
||
|
"three/tsl": "../build/three.tsl.js",
|
||
|
"three/addons/": "./jsm/"
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<script type="module">
|
||
|
|
||
|
import * as THREE from 'three';
|
||
|
import { pass, renderOutput } from 'three/tsl';
|
||
|
import { fxaa } from 'three/addons/tsl/display/FXAANode.js';
|
||
|
|
||
|
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 = fxaa( outputPass );
|
||
|
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>
|