-
-
Notifications
You must be signed in to change notification settings - Fork 36k
WebGPURenderer: Support for access previous frame textures using pass()
#29069
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9b47968
PassNode: Support for previous frame textures
sunag 99207ca
add support to change render target textures
sunag 0f35881
add `webgpu_postprocessing_difference` example
sunag a317129
revision
sunag adb9396
Update webgpu_postprocessing_difference.html
sunag 5df7ea8
revision
sunag daee115
revision
sunag 68c6fa3
revision
sunag f22d858
update screenshot
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
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 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,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( { forceWebGL: true }); | ||
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 ); | ||
|
||
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 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
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.
Uh oh!
There was an error while loading. Please reload this page.