123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <!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>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { GUI } from './jsm/libs/dat.gui.module.js';
- import { EffectComposer } from './jsm/postprocessing/EffectComposer.js';
- import { RenderPass } from './jsm/postprocessing/RenderPass.js';
- import { AfterimagePass } from './jsm/postprocessing/AfterimagePass.js';
- var camera, scene, renderer, composer;
- var mesh;
- var afterimagePass;
- var 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 );
- var geometry = new THREE.BoxBufferGeometry( 150, 150, 150, 2, 2, 2 );
- var 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, false );
- }
- function createGUI() {
- var 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 animate() {
- requestAnimationFrame( animate );
- mesh.rotation.x += 0.005;
- mesh.rotation.y += 0.01;
- if ( params.enable ) {
- composer.render();
- } else {
- renderer.render( scene, camera );
- }
- }
- </script>
- </body>
- </html>
|