1
0

webgpu_postprocessing_afterimage.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - postprocessing afterimage</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <script type="importmap">
  11. {
  12. "imports": {
  13. "three": "../build/three.webgpu.js",
  14. "three/tsl": "../build/three.webgpu.js",
  15. "three/addons/": "./jsm/"
  16. }
  17. }
  18. </script>
  19. <script type="module">
  20. import * as THREE from 'three';
  21. import { pass, afterImage } from 'three/tsl';
  22. import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
  23. let camera, scene, renderer;
  24. let mesh, postProcessing, combinedPass;
  25. const params = {
  26. damp: 0.96
  27. };
  28. init();
  29. createGUI();
  30. function init() {
  31. renderer = new THREE.WebGPURenderer( { antialias: true } );
  32. renderer.setPixelRatio( window.devicePixelRatio );
  33. renderer.setSize( window.innerWidth, window.innerHeight );
  34. renderer.setAnimationLoop( animate );
  35. document.body.appendChild( renderer.domElement );
  36. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  37. camera.position.z = 400;
  38. scene = new THREE.Scene();
  39. scene.fog = new THREE.Fog( 0x000000, 1, 1000 );
  40. const geometry = new THREE.TorusKnotGeometry( 100, 30, 100, 16 );
  41. const material = new THREE.MeshNormalMaterial();
  42. mesh = new THREE.Mesh( geometry, material );
  43. scene.add( mesh );
  44. // postprocessing
  45. postProcessing = new THREE.PostProcessing( renderer );
  46. const scenePass = pass( scene, camera );
  47. const scenePassColor = scenePass.getTextureNode();
  48. combinedPass = scenePassColor;
  49. combinedPass = afterImage( combinedPass, params.damp );
  50. postProcessing.outputNode = combinedPass;
  51. window.addEventListener( 'resize', onWindowResize );
  52. }
  53. function createGUI() {
  54. const gui = new GUI( { title: 'Damp setting' } );
  55. gui.add( combinedPass.damp, 'value', 0, 1 ).step( 0.001 );
  56. }
  57. function onWindowResize() {
  58. camera.aspect = window.innerWidth / window.innerHeight;
  59. camera.updateProjectionMatrix();
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. }
  62. function render() {
  63. mesh.rotation.x += 0.0075;
  64. mesh.rotation.y += 0.015;
  65. postProcessing.render();
  66. }
  67. function animate() {
  68. render();
  69. }
  70. </script>
  71. </body>
  72. </html>