123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <!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 { 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>
|