1
0

webgpu_upscaling_taau.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - postprocessing taau</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. <meta property="og:title" content="three.js webgpu - postprocessing taau">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgpu_upscaling_taau.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgpu_upscaling_taau.jpg">
  11. <link type="text/css" rel="stylesheet" href="example.css">
  12. </head>
  13. <body>
  14. <div id="info" class="invert">
  15. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  16. <div class="title-wrapper">
  17. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>TAAU</span>
  18. </div>
  19. <small>
  20. Temporal Reprojection Anti-Aliasing with Upsampling.<br />
  21. Model: <a href="https://artstation.com/artwork/1AGwX" target="_blank" rel="noopener">Littlest Tokyo</a> by <a href="https://artstation.com/glenatron" target="_blank" rel="noopener">Glen Fox</a>, CC Attribution.
  22. </small>
  23. </div>
  24. <script type="importmap">
  25. {
  26. "imports": {
  27. "three": "../build/three.webgpu.js",
  28. "three/webgpu": "../build/three.webgpu.js",
  29. "three/tsl": "../build/three.tsl.js",
  30. "three/addons/": "./jsm/"
  31. }
  32. }
  33. </script>
  34. <script type="module">
  35. import * as THREE from 'three/webgpu';
  36. import { mrt, output, pass, velocity } from 'three/tsl';
  37. import { taau } from 'three/addons/tsl/display/TAAUNode.js';
  38. import { sharpen } from 'three/addons/tsl/display/SharpenNode.js';
  39. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  40. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  41. import { Inspector } from 'three/addons/inspector/Inspector.js';
  42. import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
  43. import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
  44. const params = {
  45. upscaleMethod: 'TAAU',
  46. resolutionScale: 0.5,
  47. sharpening: true,
  48. sharpness: 0.2,
  49. };
  50. let camera, scene, renderer, renderPipeline, controls, mixer, timer;
  51. init();
  52. async function init() {
  53. camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 0.1, 100 );
  54. camera.position.set( - 0.5, 0, 12 );
  55. scene = new THREE.Scene();
  56. timer = new THREE.Timer();
  57. timer.connect( document );
  58. // model
  59. const dracoLoader = new DRACOLoader();
  60. const loader = new GLTFLoader();
  61. loader.setDRACOLoader( dracoLoader );
  62. loader.load( 'models/gltf/LittlestTokyo.glb', function ( gltf ) {
  63. const model = gltf.scene;
  64. model.scale.set( 0.01, 0.01, 0.01 );
  65. scene.add( model );
  66. mixer = new THREE.AnimationMixer( model );
  67. mixer.clipAction( gltf.animations[ 0 ] ).play();
  68. } );
  69. // renderer
  70. renderer = new THREE.WebGPURenderer();
  71. renderer.setPixelRatio( window.devicePixelRatio );
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. renderer.setAnimationLoop( animate );
  74. renderer.inspector = new Inspector();
  75. document.body.appendChild( renderer.domElement );
  76. await renderer.init();
  77. const pmremGenerator = new THREE.PMREMGenerator( renderer );
  78. scene = new THREE.Scene();
  79. scene.background = new THREE.Color( 0xbfe3dd );
  80. scene.environment = pmremGenerator.fromScene( new RoomEnvironment(), 0.04 ).texture;
  81. // controls
  82. controls = new OrbitControls( camera, renderer.domElement );
  83. controls.enableDamping = true;
  84. controls.target.set( - 0.5, 0, 0 );
  85. // render pipeline
  86. renderPipeline = new THREE.RenderPipeline( renderer );
  87. const scenePass = pass( scene, camera );
  88. scenePass.setResolutionScale( params.resolutionScale );
  89. scenePass.setMRT( mrt( {
  90. output: output,
  91. velocity: velocity
  92. } ) );
  93. const scenePassColor = scenePass.getTextureNode( 'output' ).toInspector( 'Color' );
  94. const scenePassDepth = scenePass.getTextureNode( 'depth' ).toInspector( 'Depth', () => {
  95. return scenePass.getLinearDepthNode();
  96. } );
  97. const scenePassVelocity = scenePass.getTextureNode( 'velocity' ).toInspector( 'Velocity' );
  98. const taauNode = taau( scenePassColor, scenePassDepth, scenePassVelocity, camera );
  99. const sharpenNode = sharpen( taauNode.getTextureNode(), params.sharpness );
  100. function updatePipeline() {
  101. if ( params.upscaleMethod === 'TAAU' ) {
  102. renderPipeline.outputNode = params.sharpening ? sharpenNode : taauNode;
  103. } else {
  104. renderPipeline.outputNode = scenePass;
  105. }
  106. renderPipeline.needsUpdate = true;
  107. }
  108. // gui
  109. const gui = renderer.inspector.createParameters( 'Settings' );
  110. gui.add( params, 'upscaleMethod', [ 'Bilinear', 'TAAU' ] ).onChange( updatePipeline );
  111. gui.add( params, 'resolutionScale', 0.25, 1.0, 0.25 ).onChange( ( value ) => {
  112. scenePass.setResolutionScale( value );
  113. } );
  114. gui.add( params, 'sharpening' ).onChange( updatePipeline );
  115. gui.add( params, 'sharpness', 0, 2, 0.05 ).onChange( ( value ) => {
  116. sharpenNode.sharpness.value = value;
  117. } );
  118. updatePipeline();
  119. //
  120. window.addEventListener( 'resize', onWindowResize );
  121. }
  122. function onWindowResize() {
  123. const width = window.innerWidth;
  124. const height = window.innerHeight;
  125. camera.aspect = width / height;
  126. camera.updateProjectionMatrix();
  127. renderer.setSize( width, height );
  128. }
  129. function animate() {
  130. controls.update();
  131. timer.update();
  132. const delta = timer.getDelta();
  133. if ( mixer ) {
  134. mixer.update( delta );
  135. }
  136. renderPipeline.render();
  137. }
  138. </script>
  139. </body>
  140. </html>
粤ICP备19079148号