-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebGPURenderer: Support for access previous frame textures using `pas…
…s()` (#29069) * PassNode: Support for previous frame textures * add support to change render target textures * add `webgpu_postprocessing_difference` example * revision * Update webgpu_postprocessing_difference.html * revision * revision * revision * update screenshot
- Loading branch information
Showing
10 changed files
with
279 additions
and
52 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
Binary file modified
BIN
-1.42 KB
(95%)
examples/screenshots/webgpu_postprocessing_bloom_emissive.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.13 KB
(110%)
examples/screenshots/webgpu_postprocessing_bloom_selective.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,130 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>three.js webgpu - frame difference</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> | ||
<br/>saturated color of objects according to the difference from one frame to another | ||
</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, luminance } from 'three/tsl'; | ||
|
||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; | ||
import { Timer } from 'three/addons/misc/Timer.js'; | ||
|
||
import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; | ||
|
||
const params = { | ||
speed: 0 | ||
}; | ||
|
||
let camera, renderer, postProcessing; | ||
let timer, mesh, controls; | ||
|
||
init(); | ||
|
||
function init() { | ||
|
||
renderer = new THREE.WebGPURenderer(); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
renderer.setAnimationLoop( animate ); | ||
renderer.toneMapping = THREE.NeutralToneMapping; | ||
document.body.appendChild( renderer.domElement ); | ||
|
||
// | ||
|
||
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 100 ); | ||
camera.position.set( 1, 2, 3 ); | ||
|
||
const scene = new THREE.Scene(); | ||
scene.fog = new THREE.Fog( 0x0487e2, 7, 25 ); | ||
scene.background = new THREE.Color( 0x0487e2 ); | ||
|
||
timer = new Timer(); | ||
|
||
const texture = new THREE.TextureLoader().load( 'textures/crate.gif' ); | ||
texture.colorSpace = THREE.SRGBColorSpace; | ||
|
||
const geometry = new THREE.BoxGeometry(); | ||
const material = new THREE.MeshBasicMaterial( { map: texture } ); | ||
|
||
mesh = new THREE.Mesh( geometry, material ); | ||
scene.add( mesh ); | ||
|
||
// post processing | ||
|
||
postProcessing = new THREE.PostProcessing( renderer ); | ||
|
||
const scenePass = pass( scene, camera ); | ||
|
||
const currentTexture = scenePass.getTextureNode(); | ||
const previousTexture = scenePass.getPreviousTextureNode(); | ||
|
||
const frameDiff = previousTexture.sub( currentTexture ).abs(); | ||
|
||
const saturationAmount = luminance( frameDiff ).mul( 1000 ).clamp( 0, 3 ); | ||
|
||
postProcessing.outputNode = currentTexture.saturation( saturationAmount ); | ||
|
||
// | ||
|
||
controls = new OrbitControls( camera, renderer.domElement ); | ||
controls.minDistance = 2; | ||
controls.maxDistance = 10; | ||
controls.enableDamping = true; | ||
controls.dampingFactor = 0.01; | ||
|
||
window.addEventListener( 'resize', onWindowResize ); | ||
|
||
// | ||
|
||
const gui = new GUI(); | ||
gui.add( params, 'speed', 0, 2 ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
camera.aspect = window.innerWidth / window.innerHeight; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
|
||
} | ||
|
||
function animate() { | ||
|
||
timer.update(); | ||
|
||
controls.update(); | ||
|
||
mesh.rotation.y += timer.getDelta() * 5 * params.speed; | ||
|
||
postProcessing.render(); | ||
|
||
} | ||
|
||
</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
Oops, something went wrong.