-
-
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.
WebGPURenderer: Support Compressed Texture Array (#29231)
* WebGPURenderer: Support Compressed Texture Array * small cleanup * more cleanup
- Loading branch information
1 parent
78f2ffb
commit cde3cd2
Showing
8 changed files
with
168 additions
and
28 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,129 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>three.js webgl - 2D compressed texture array</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 - 2D Compressed Texture Array<br /> | ||
Loop from the movie Spirited away | ||
by the <a href="https://www.ghibli.jp/" target="_blank" rel="noopener">Studio Ghibli</a><br /> | ||
</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, uniform, uv } from 'three/tsl'; | ||
|
||
import Stats from 'three/addons/libs/stats.module.js'; | ||
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js'; | ||
|
||
let camera, scene, mesh, renderer, stats, clock; | ||
|
||
const depth = uniform( 0 ); | ||
|
||
const planeWidth = 50; | ||
const planeHeight = 25; | ||
|
||
let depthStep = 1; | ||
|
||
init(); | ||
|
||
async function init() { | ||
|
||
const container = document.createElement( 'div' ); | ||
document.body.appendChild( container ); | ||
|
||
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 2000 ); | ||
camera.position.z = 70; | ||
|
||
scene = new THREE.Scene(); | ||
|
||
// | ||
clock = new THREE.Clock(); | ||
|
||
renderer = new THREE.WebGPURenderer(); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
renderer.setAnimationLoop( animate ); | ||
container.appendChild( renderer.domElement ); | ||
|
||
// | ||
|
||
const ktx2Loader = new KTX2Loader(); | ||
ktx2Loader.setTranscoderPath( 'jsm/libs/basis/' ); | ||
await ktx2Loader.detectSupportAsync( renderer ); | ||
|
||
ktx2Loader.load( 'textures/spiritedaway.ktx2', function ( texturearray ) { | ||
|
||
const material = new THREE.NodeMaterial(); | ||
|
||
material.colorNode = texture( texturearray, uv().flipY() ).depth( depth ); | ||
const geometry = new THREE.PlaneGeometry( planeWidth, planeHeight ); | ||
|
||
mesh = new THREE.Mesh( geometry, material ); | ||
|
||
scene.add( mesh ); | ||
|
||
} ); | ||
|
||
|
||
stats = new Stats(); | ||
container.appendChild( stats.dom ); | ||
|
||
window.addEventListener( 'resize', onWindowResize ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
camera.aspect = window.innerWidth / window.innerHeight; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
|
||
} | ||
|
||
function animate() { | ||
|
||
if ( mesh ) { | ||
|
||
const delta = clock.getDelta() * 10; | ||
|
||
depthStep += delta; | ||
|
||
const value = depthStep % 5; | ||
|
||
depth.value = value; | ||
|
||
} | ||
|
||
render(); | ||
stats.update(); | ||
|
||
} | ||
|
||
function render() { | ||
|
||
renderer.render( scene, camera ); | ||
|
||
} | ||
|
||
</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
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
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
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
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