-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Nodes: Add `BloomNode`. * E2E: Update screenshot. * BloomNode: Fix reference.
- Loading branch information
Showing
5 changed files
with
519 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,184 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>three.js webgpu - postprocessing - bloom</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"> | ||
<style> | ||
#info > * { | ||
max-width: 650px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div id="container"></div> | ||
|
||
<div id="info"> | ||
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - Bloom pass by <a href="http://eduperiment.com" target="_blank" rel="noopener">Prashant Sharma</a> and <a href="https://clara.io" target="_blank" rel="noopener">Ben Houston</a> | ||
<br/> | ||
Model: <a href="https://blog.sketchfab.com/art-spotlight-primary-ion-drive/" target="_blank" rel="noopener">Primary Ion Drive</a> by | ||
<a href="http://mjmurdock.com/" target="_blank" rel="noopener">Mike Murdock</a>, CC Attribution. | ||
</div> | ||
|
||
<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, bloom } from 'three/tsl'; | ||
|
||
import Stats from 'three/addons/libs/stats.module.js'; | ||
import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; | ||
|
||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; | ||
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; | ||
|
||
|
||
let camera, stats; | ||
let postProcessing, renderer, mixer, clock; | ||
|
||
const params = { | ||
threshold: 0, | ||
strength: 1, | ||
radius: 0, | ||
exposure: 1 | ||
}; | ||
|
||
init(); | ||
|
||
async function init() { | ||
|
||
const container = document.getElementById( 'container' ); | ||
|
||
clock = new THREE.Clock(); | ||
|
||
const scene = new THREE.Scene(); | ||
|
||
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 ); | ||
camera.position.set( - 5, 2.5, - 3.5 ); | ||
scene.add( camera ); | ||
|
||
scene.add( new THREE.AmbientLight( 0xcccccc ) ); | ||
|
||
const pointLight = new THREE.PointLight( 0xffffff, 100 ); | ||
camera.add( pointLight ); | ||
|
||
const loader = new GLTFLoader(); | ||
const gltf = await loader.loadAsync( 'models/gltf/PrimaryIonDrive.glb' ); | ||
|
||
const model = gltf.scene; | ||
scene.add( model ); | ||
|
||
mixer = new THREE.AnimationMixer( model ); | ||
const clip = gltf.animations[ 0 ]; | ||
mixer.clipAction( clip.optimize() ).play(); | ||
|
||
// | ||
|
||
renderer = new THREE.WebGPURenderer( { antialias: true } ); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
renderer.setAnimationLoop( animate ); | ||
renderer.toneMapping = THREE.ReinhardToneMapping; | ||
container.appendChild( renderer.domElement ); | ||
|
||
// | ||
|
||
postProcessing = new THREE.PostProcessing( renderer ); | ||
|
||
const scenePass = pass( scene, camera ); | ||
const scenePassColor = scenePass.getTextureNode( 'output' ); | ||
|
||
const bloomPass = bloom( scenePassColor ); | ||
|
||
postProcessing.outputNode = scenePassColor.add( bloomPass ); | ||
|
||
// | ||
|
||
stats = new Stats(); | ||
container.appendChild( stats.dom ); | ||
|
||
// | ||
|
||
const controls = new OrbitControls( camera, renderer.domElement ); | ||
controls.maxPolarAngle = Math.PI * 0.5; | ||
controls.minDistance = 3; | ||
controls.maxDistance = 8; | ||
|
||
// | ||
|
||
const gui = new GUI(); | ||
|
||
const bloomFolder = gui.addFolder( 'bloom' ); | ||
|
||
bloomFolder.add( params, 'threshold', 0.0, 1.0 ).onChange( function ( value ) { | ||
|
||
bloomPass.threshold.value = value; | ||
|
||
} ); | ||
|
||
bloomFolder.add( params, 'strength', 0.0, 3.0 ).onChange( function ( value ) { | ||
|
||
bloomPass.strength.value = value; | ||
|
||
} ); | ||
|
||
gui.add( params, 'radius', 0.0, 1.0 ).step( 0.01 ).onChange( function ( value ) { | ||
|
||
bloomPass.radius.value = value; | ||
|
||
} ); | ||
|
||
const toneMappingFolder = gui.addFolder( 'tone mapping' ); | ||
|
||
toneMappingFolder.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) { | ||
|
||
renderer.toneMappingExposure = Math.pow( value, 4.0 ); | ||
|
||
} ); | ||
|
||
window.addEventListener( 'resize', onWindowResize ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
|
||
camera.aspect = width / height; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize( width, height ); | ||
|
||
} | ||
|
||
function animate() { | ||
|
||
const delta = clock.getDelta(); | ||
|
||
mixer.update( delta ); | ||
|
||
postProcessing.render(); | ||
|
||
stats.update(); | ||
|
||
} | ||
|
||
</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.