-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
WebGPURenderer: Improve AO approach #28863
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
dda58fa
Introduce NodeHandler
sunag 677d83f
Introduce `renderer.transparent` and `renderer.opaque`
sunag 98992f7
TSL: Introduce `after` and `before`
sunag e206f04
add standardPass() and improve ao approach
sunag 03dafb6
fix dispose rtt
sunag c491708
wip nodeHandler
sunag 2dcefd8
wip ao
sunag 933600a
set enableAO default to false
sunag 8b2981e
Merge branch 'dev' into dev-ao-approach
sunag 840ab10
update live demo
sunag a9622fe
Merge branch 'dev' into dev-ao-approach
sunag a6e86ef
fix dispose
sunag 37d557a
cleanup
sunag ad12812
added example
sunag dcf2e52
remove standardPass
sunag 1b95e74
added .toTexture() for others parameters
sunag 6adc8a7
cleanup
sunag 3f41fc5
cleanup
sunag ecd527e
revert
sunag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,146 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>three.js webgpu - ambient occlusion (GTAO)</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": "../src/Three.WebGPU.js", | ||
| "three/tsl": "../src/Three.WebGPU.js", | ||
| "three/addons/": "./jsm/" | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <script type="module"> | ||
|
|
||
| import * as THREE from 'three'; | ||
| import { standardPass, viewportSharedTexture } from 'three/tsl'; | ||
|
|
||
| import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; | ||
| import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js'; | ||
| import { RGBELoader } from 'three/addons/loaders/RGBELoader.js'; | ||
| import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; | ||
|
|
||
| import Stats from 'three/addons/libs/stats.module.js'; | ||
|
|
||
| let camera, scene, renderer, postProcessing, controls, clock, stats, mixer; | ||
|
|
||
| init(); | ||
|
|
||
| async function init() { | ||
|
|
||
| camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 ); | ||
| camera.position.set( 5, 2, 8 ); | ||
|
|
||
| scene = new THREE.Scene(); | ||
| scene.background = new THREE.Color( 0xbfe3dd ); | ||
|
|
||
| clock = new THREE.Clock(); | ||
|
|
||
| const hdrloader = new RGBELoader(); | ||
| const texture = await hdrloader.loadAsync( 'textures/equirectangular/quarry_01_1k.hdr' ); | ||
| texture.mapping = THREE.EquirectangularReflectionMapping; | ||
|
|
||
| scene.environment = texture; | ||
|
|
||
| renderer = new THREE.WebGPURenderer(); | ||
| renderer.setSize( window.innerWidth, window.innerHeight ); | ||
| renderer.setAnimationLoop( animate ); | ||
| document.body.appendChild( renderer.domElement ); | ||
|
|
||
| controls = new OrbitControls( camera, renderer.domElement ); | ||
| controls.target.set( 0, 0.5, 0 ); | ||
| controls.update(); | ||
| controls.enablePan = false; | ||
| controls.enableDamping = true; | ||
|
|
||
| stats = new Stats(); | ||
| document.body.appendChild( stats.dom ); | ||
|
|
||
| // | ||
|
|
||
| const verticalRefractor = viewportSharedTexture(); | ||
|
|
||
| const planeRefractor = new THREE.Mesh( new THREE.PlaneGeometry( 3, 3 ), new THREE.MeshStandardNodeMaterial( { | ||
| backdropNode: verticalRefractor.saturation( 0 ) | ||
| } ) ); | ||
| planeRefractor.material.transparent = true; | ||
| planeRefractor.position.z = 3; | ||
| planeRefractor.position.y = 1; | ||
| scene.add( planeRefractor ); | ||
|
|
||
| // | ||
|
|
||
| const emissiveObject = new THREE.Mesh( new THREE.SphereGeometry( .5, 32, 32 ), new THREE.MeshStandardNodeMaterial( { | ||
| emissive: new THREE.Color( 0xFFFFFF ) | ||
| } ) ); | ||
| emissiveObject.position.z = 1; | ||
| emissiveObject.position.y = 1; | ||
| scene.add( emissiveObject ); | ||
|
|
||
| // | ||
|
|
||
| const stdPass = standardPass( scene, camera ); | ||
|
|
||
| postProcessing = new THREE.PostProcessing( renderer ); | ||
| postProcessing.outputNode = stdPass; | ||
|
|
||
| const dracoLoader = new DRACOLoader(); | ||
| dracoLoader.setDecoderPath( 'jsm/libs/draco/' ); | ||
| dracoLoader.setDecoderConfig( { type: 'js' } ); | ||
| const loader = new GLTFLoader(); | ||
| loader.setDRACOLoader( dracoLoader ); | ||
| loader.setPath( 'models/gltf/' ); | ||
|
|
||
| const gltf = await loader.loadAsync( 'LittlestTokyo.glb' ); | ||
|
|
||
| const model = gltf.scene; | ||
| model.position.set( 1, 1, 0 ); | ||
| model.scale.set( 0.01, 0.01, 0.01 ); | ||
| scene.add( model ); | ||
|
|
||
| mixer = new THREE.AnimationMixer( model ); | ||
| mixer.clipAction( gltf.animations[ 0 ] ).play(); | ||
|
|
||
| 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(); | ||
|
|
||
| if ( mixer ) { | ||
|
|
||
| mixer.update( delta ); | ||
|
|
||
| } | ||
|
|
||
| controls.update(); | ||
|
|
||
| postProcessing.render(); | ||
| stats.update(); | ||
|
|
||
| } | ||
|
|
||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,33 @@ | ||
| class NodeHandler { | ||
|
|
||
| constructor() { | ||
|
|
||
| this.handlers = []; | ||
|
|
||
| } | ||
|
|
||
| onHandle( name, callback ) { | ||
|
|
||
| this.handlers[ name ] = callback; | ||
|
|
||
| return this; | ||
|
|
||
| } | ||
|
|
||
| handle( name, node, builder ) { | ||
|
|
||
| const callback = this.handlers[ name ]; | ||
|
|
||
| if ( callback !== undefined ) { | ||
|
|
||
| node = callback( node, builder ); | ||
|
|
||
| } | ||
|
|
||
| return node || null; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| export default NodeHandler; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused variable, import, function or class