You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

135 lines
2.9 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - postprocessing - afterimage</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>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { AfterimagePass } from 'three/addons/postprocessing/AfterimagePass.js';
let camera, scene, renderer, composer;
let mesh;
let afterimagePass;
const params = {
enable: true
};
init();
createGUI();
animate();
function init() {
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 400;
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x000000, 1, 1000 );
const geometry = new THREE.BoxGeometry( 150, 150, 150, 2, 2, 2 );
const material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
// postprocessing
composer = new EffectComposer( renderer );
composer.addPass( new RenderPass( scene, camera ) );
afterimagePass = new AfterimagePass();
composer.addPass( afterimagePass );
window.addEventListener( 'resize', onWindowResize );
if ( typeof TESTING !== 'undefined' ) {
for ( let i = 0; i < 45; i ++ ) {
render();
}
}
}
function createGUI() {
const gui = new GUI( { name: 'Damp setting' } );
gui.add( afterimagePass.uniforms[ 'damp' ], 'value', 0, 1 ).step( 0.001 );
gui.add( params, 'enable' );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
composer.setSize( window.innerWidth, window.innerHeight );
}
function render() {
mesh.rotation.x += 0.005;
mesh.rotation.y += 0.01;
if ( params.enable ) {
composer.render();
} else {
renderer.render( scene, camera );
}
}
function animate() {
requestAnimationFrame( animate );
render();
}
</script>
</body>
</html>