-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
495 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.