-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
RFC: WebGPURenderer prototype single uniform buffer update / pass #27388
Open
aardgoose
wants to merge
10
commits into
mrdoob:dev
Choose a base branch
from
aardgoose:singlebuffer
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+552
−19
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bc9477d
prototye big buffer
6fe0577
add free and reused of freed extents
b22a879
rework and collect stats
004f89f
pass in stats
1b07ccc
update screenshot
02c7ace
remove unused imports
19a5bd4
fixup
aba6c1f
fixup example
40d6ed1
adjust delete binding to bindGroups
77f7f8f
fix lint errors
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 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,213 @@ | ||
<html lang="en"> | ||
<head> | ||
<title>three.js - WebGPU - Sprites - Common buffer</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> | ||
|
||
<div id="info"> | ||
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - Sprites - Common buffer | ||
<div id="buffer-stats" style=" | ||
position: absolute; | ||
top: 60px; | ||
left: 0; | ||
padding: 10px; | ||
background: rgba( 0, 0, 0, 0.5 ); | ||
color: #fff; | ||
font-family: monospace; | ||
font-size: 12px; | ||
line-height: 1.5; | ||
pointer-events: none; | ||
text-align: left; | ||
"></div> | ||
</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 { texture, uv, userData, rangeFog, color, SpriteNodeMaterial, reference } from 'three/tsl'; | ||
|
||
let camera, scene, renderer, material; | ||
|
||
let map; | ||
|
||
let group; | ||
|
||
let imageWidth = 1, imageHeight = 1; | ||
|
||
const amount = 200; | ||
const radius = 500; | ||
|
||
const bufferStats = document.getElementById( 'buffer-stats' ); | ||
|
||
init(); | ||
|
||
function addSprite( material ) { | ||
|
||
const x = Math.random() - 0.5; | ||
const y = Math.random() - 0.5; | ||
const z = Math.random() - 0.5; | ||
|
||
const sprite = new THREE.Sprite( material ); | ||
|
||
sprite.position.set( x, y, z ); | ||
sprite.position.normalize(); | ||
sprite.position.multiplyScalar( radius ); | ||
|
||
// individual rotation per sprite | ||
sprite.userData.rotation = 0; | ||
|
||
group.add( sprite ); | ||
|
||
} | ||
|
||
function init() { | ||
|
||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
|
||
camera = new THREE.PerspectiveCamera( 60, width / height, 1, 2100 ); | ||
camera.position.z = 1500; | ||
|
||
scene = new THREE.Scene(); | ||
scene.fogNode = rangeFog( color( 0x0000ff ), 1500, 2100 ); | ||
|
||
// create sprites | ||
|
||
const textureLoader = new THREE.TextureLoader(); | ||
|
||
map = textureLoader.load( 'textures/sprite1.png', ( map ) => { | ||
|
||
imageWidth = map.image.width; | ||
imageHeight = map.image.height; | ||
|
||
} ); | ||
|
||
group = new THREE.Group(); | ||
|
||
const textureNode = texture( map ); | ||
|
||
material = new THREE.SpriteNodeMaterial(); | ||
material.colorNode = textureNode.mul( uv() ).mul( 2 ).saturate(); | ||
material.opacityNode = textureNode.a; | ||
material.rotationNode = userData( 'rotation', 'float' ); // get value of: sprite.userData.rotation | ||
material.transparent = true; | ||
|
||
for ( let a = 0; a < amount; a ++ ) { | ||
|
||
addSprite( material ); | ||
|
||
} | ||
|
||
scene.add( group ); | ||
|
||
// | ||
|
||
renderer = new THREE.WebGPURenderer( { antialias: true } ); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
renderer.setAnimationLoop( render ); | ||
renderer.commonBufferSize = 1024; | ||
|
||
document.body.appendChild( renderer.domElement ); | ||
|
||
window.addEventListener( 'resize', onWindowResize ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
|
||
camera.aspect = width / height; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
|
||
} | ||
|
||
function render() { | ||
|
||
const time = Date.now() / 1000; | ||
|
||
for ( let i = 0, l = group.children.length; i < l; i ++ ) { | ||
|
||
const sprite = group.children[ i ]; | ||
|
||
if ( sprite === undefined ) { | ||
|
||
continue; | ||
|
||
|
||
} else { | ||
|
||
if ( Math.round( Math.random( ) * 1000 ) === 1 ) { | ||
|
||
sprite.removeFromParent(); | ||
|
||
continue; | ||
|
||
} | ||
|
||
} | ||
|
||
const scale = Math.sin( time + sprite.position.x * 0.01 ) * 0.3 + 1.0; | ||
|
||
sprite.userData.rotation += 0.1 * ( i / l ); | ||
sprite.scale.set( scale * imageWidth, scale * imageHeight, 1.0 ); | ||
|
||
if ( Math.round( Math.random( ) * 1000 ) === 1 ) { | ||
|
||
addSprite( material ); | ||
|
||
} | ||
|
||
} | ||
|
||
group.rotation.x = time * 0.05; | ||
group.rotation.y = time * 0.075; | ||
group.rotation.z = time * 0.1; | ||
|
||
renderer.render( scene, camera ); | ||
|
||
const info = renderer.info; | ||
|
||
if ( info.render.calls % 20 === 0 ) { | ||
|
||
const stats = info.memory.common; | ||
const lists = stats.freeLists; | ||
|
||
let listText = ''; | ||
|
||
for ( let i = 1, l = lists.length; i < l; i ++ ) { | ||
|
||
listText += `Blocks ${ i } - length: ${ lists[ i ]} `; | ||
|
||
} | ||
|
||
bufferStats.innerHTML = | ||
`Unused bytes: ${ stats.unused }<br>` + | ||
`Alloc: ${ stats.alloc } (reused ${ stats.reused }) Free: ${ stats.free } <br><br>` + | ||
`Free block lists (size: ${ stats.blockSize } B)<br>` + | ||
listText; | ||
|
||
} | ||
|
||
} | ||
|
||
</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.
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 Note