forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LightProbeGenerator: adapt for WebGPU compatibility (mrdoob#29335)
* adapt for webGPU * improve backend detection * rework * rework * exclude from tests --------- Co-authored-by: aardgoose <angus.sawyer@email.com>
- Loading branch information
Showing
6 changed files
with
155 additions
and
12 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
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
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,125 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>three.js webgpu - light probe from cubeCamera</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 - light probe from cubeCamera | ||
</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 { OrbitControls } from 'three/addons/controls/OrbitControls.js'; | ||
import { LightProbeHelper } from 'three/addons/helpers/LightProbeHelperGPU.js'; | ||
import { LightProbeGenerator } from 'three/addons/lights/LightProbeGenerator.js'; | ||
|
||
let renderer, scene, camera, cubeCamera; | ||
|
||
let lightProbe; | ||
|
||
init(); | ||
|
||
function init() { | ||
|
||
// renderer | ||
renderer = new THREE.WebGPURenderer( { antialias: true } ); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
document.body.appendChild( renderer.domElement ); | ||
|
||
// scene | ||
scene = new THREE.Scene(); | ||
|
||
// camera | ||
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 ); | ||
camera.position.set( 0, 0, 30 ); | ||
|
||
const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( 256 ); | ||
|
||
cubeCamera = new THREE.CubeCamera( 1, 1000, cubeRenderTarget ); | ||
|
||
// controls | ||
const controls = new OrbitControls( camera, renderer.domElement ); | ||
controls.addEventListener( 'change', render ); | ||
controls.minDistance = 10; | ||
controls.maxDistance = 50; | ||
controls.enablePan = false; | ||
|
||
// probe | ||
lightProbe = new THREE.LightProbe(); | ||
scene.add( lightProbe ); | ||
|
||
// envmap | ||
const genCubeUrls = function ( prefix, postfix ) { | ||
|
||
return [ | ||
prefix + 'px' + postfix, prefix + 'nx' + postfix, | ||
prefix + 'py' + postfix, prefix + 'ny' + postfix, | ||
prefix + 'pz' + postfix, prefix + 'nz' + postfix | ||
]; | ||
|
||
}; | ||
|
||
const urls = genCubeUrls( 'textures/cube/pisa/', '.png' ); | ||
|
||
new THREE.CubeTextureLoader().load( urls, async function ( cubeTexture ) { | ||
|
||
scene.background = cubeTexture; | ||
|
||
await renderer.init(); | ||
|
||
cubeCamera.update( renderer, scene ); | ||
|
||
const probe = await LightProbeGenerator.fromCubeRenderTarget( renderer, cubeRenderTarget ); | ||
|
||
lightProbe.copy( probe ); | ||
|
||
scene.add( new LightProbeHelper( lightProbe, 5 ) ); | ||
|
||
render(); | ||
|
||
} ); | ||
|
||
// listener | ||
window.addEventListener( 'resize', onWindowResize ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
|
||
camera.aspect = window.innerWidth / window.innerHeight; | ||
camera.updateProjectionMatrix(); | ||
|
||
render(); | ||
|
||
} | ||
|
||
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