-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Post-processing with WebXR #18846
Closed
Closed
Post-processing with WebXR #18846
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a0d70d5
Hack EffectComposer for VR
takahirox 9dfda1a
Add WebVR PostProcessing example
takahirox f658f87
Update examples/files.hs for WebVR PostProcessing example
takahirox 4fed06d
Fix animation loop of WebVR PostProcessing example
takahirox c87ce06
Resize renderer drawingBufferSize when entering/leaving VR mode in We…
takahirox 2481cda
User renderer.getDrawingBufferSize() instead of renderer.getDrawingBu…
takahirox 9af198e
Merge branch 'dev' into EffectComposerVRHack
takahirox 8e4818c
Merge branch 'dev' into EffectComposerVRHack. Fix the conflicts.
takahirox c3e8b57
Move setRenderTarget() from render() to init() in WebVR PostProcessin…
takahirox 31cfc5e
Efficient EffectComposer size change in .render()
takahirox 55d1b2c
Remove deprecated WebXR API token
takahirox f0fdd62
Merge branch 'dev' into EffectComposerVRHack
takahirox fcbbb6e
Merge branch 'dev' into EffectComposerVRHack
takahirox 236142b
Simplified EffectComposer renderer size update for VR
takahirox 4d6e7e4
Merge remote-tracking branch 'upstream/dev' into EffectComposerVRHack
takahirox 470e6ab
Use module in webvr_postprocessing example
takahirox f1f24d8
Update WebXRManager to follow the newest WebXR API
takahirox f3143e0
Update jsm
takahirox 17c5a0b
Minor clean up webvr_postprocessing example
takahirox d83c5cd
Merge branch 'EffectComposerVRHack' of https://github.com/takahirox/t…
Neptilo 1bec375
Rename webvr folder to webxr
Neptilo bfb2a20
Merge https://github.com/mrdoob/three.js into dev
Neptilo 4614e87
Update EffectComposer to use WebXR
Neptilo 3aa99d2
Undo changes in build files
Neptilo 4347741
Change setDrawingBufferSize to setSize in EffectComposer
Neptilo 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>three.js vr - postprocessing</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
<link type="text/css" rel="stylesheet" href="main.css"> | ||
</head> | ||
<body> | ||
|
||
<script type="module"> | ||
|
||
import * as THREE from '../build/three.module.js'; | ||
|
||
import { CopyShader } from './jsm/shaders/CopyShader.js'; | ||
import { DotScreenShader } from './jsm/shaders/DotScreenShader.js'; | ||
import { RGBShiftShader } from './jsm/shaders/RGBShiftShader.js'; | ||
|
||
import { EffectComposer } from './jsm/postprocessing/EffectComposer.js'; | ||
import { ShaderPass } from './jsm/postprocessing/ShaderPass.js'; | ||
|
||
import { VRButton } from './jsm/webxr/VRButton.js'; | ||
|
||
var camera, scene, renderer, composer; | ||
var object, light; | ||
|
||
init(); | ||
animate(); | ||
|
||
function init() { | ||
|
||
renderer = new THREE.WebGLRenderer(); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
renderer.xr.enabled = true; | ||
document.body.appendChild( renderer.domElement ); | ||
|
||
document.body.appendChild( VRButton.createButton( renderer ) ); | ||
|
||
// | ||
|
||
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 ); | ||
|
||
scene = new THREE.Scene(); | ||
scene.fog = new THREE.Fog( 0x000000, 1, 1000 ); | ||
|
||
object = new THREE.Object3D(); | ||
object.position.z = - 500; | ||
scene.add( object ); | ||
|
||
var geometry = new THREE.SphereBufferGeometry( 1, 4, 4 ); | ||
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } ); | ||
|
||
for ( var i = 0; i < 100; i ++ ) { | ||
|
||
var mesh = new THREE.Mesh( geometry, material ); | ||
mesh.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 ).normalize(); | ||
mesh.position.multiplyScalar( Math.random() * 400 ); | ||
mesh.rotation.set( Math.random() * 2, Math.random() * 2, Math.random() * 2 ); | ||
mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50; | ||
object.add( mesh ); | ||
|
||
} | ||
|
||
scene.add( new THREE.AmbientLight( 0x222222 ) ); | ||
|
||
light = new THREE.DirectionalLight( 0xffffff ); | ||
light.position.set( 1, 1, 1 ); | ||
scene.add( light ); | ||
|
||
// postprocessing | ||
|
||
composer = new EffectComposer( renderer ); | ||
|
||
renderer.setRenderTarget( composer.readBuffer ); | ||
|
||
var effect = new ShaderPass( DotScreenShader ); | ||
effect.uniforms[ 'scale' ].value = 4; | ||
composer.addPass( effect ); | ||
|
||
effect = new ShaderPass( RGBShiftShader ); | ||
effect.uniforms[ 'amount' ].value = 0.0015; | ||
composer.addPass( effect ); | ||
|
||
scene.onAfterRender = function () { | ||
|
||
composer.render(); | ||
|
||
}; | ||
|
||
// | ||
|
||
window.addEventListener( 'resize', onWindowResize, false ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
camera.aspect = window.innerWidth / window.innerHeight; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
composer.setSize( window.innerWidth, window.innerHeight ); | ||
|
||
} | ||
|
||
function animate() { | ||
|
||
renderer.setAnimationLoop( render ); | ||
|
||
} | ||
|
||
function render() { | ||
|
||
object.rotation.x += 0.005; | ||
object.rotation.y += 0.01; | ||
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears you are scaling by pixel ratio twice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of
setPixelRatio
aftergetDrawingBufferSize
was made in the previous PR (commit f0fdd62) and I didn't change it. But it seems you're right. I'll changegetDrawingBufferSize
togetBufferSize
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mugen87 Does this code block now look OK to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
getBufferSize()
exists...Apart from that, you are right. The code should use
WebGLRenderer.getSize()
otherwise the render targets of the composer will be too big.