webgpu_textures_anisotropy.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - anisotropic texture filtering</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 - anisotropic texture filtering">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgpu_textures_anisotropy.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgpu_textures_anisotropy.jpg">
  11. <link type="text/css" rel="stylesheet" href="example.css">
  12. <style>
  13. body {
  14. color: #444;
  15. background-color: #f1f1f1;
  16. }
  17. a {
  18. color: #08f;
  19. }
  20. .lbl {
  21. color: #fff;
  22. font-size: 16px;
  23. font-weight: bold;
  24. position: absolute;
  25. bottom: 0px;
  26. z-index: 100;
  27. text-shadow: #000 1px 1px 1px;
  28. background-color: rgba(0,0,0,0.85);
  29. padding: 1em;
  30. }
  31. #lbl_left {
  32. text-align:left;
  33. left:0px;
  34. }
  35. #lbl_right {
  36. text-align:left;
  37. right:0px
  38. }
  39. .g { color:#aaa }
  40. .c { color:#fa0 }
  41. </style>
  42. </head>
  43. <body>
  44. <div id="info" class="invert">
  45. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  46. <div class="title-wrapper">
  47. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>Anisotropic Texture Filtering</span>
  48. </div>
  49. <small>
  50. Anisotropic texture filtering example.
  51. </small>
  52. </div>
  53. <div id="lbl_left" class="lbl">
  54. anisotropy: <span class="c" id="val_left"></span><br/>
  55. </div>
  56. <div id="lbl_right" class="lbl">
  57. anisotropy: <span class="c" id="val_right"></span><br/>
  58. </div>
  59. <script type="importmap">
  60. {
  61. "imports": {
  62. "three": "../build/three.webgpu.js",
  63. "three/webgpu": "../build/three.webgpu.js",
  64. "three/tsl": "../build/three.tsl.js",
  65. "three/addons/": "./jsm/"
  66. }
  67. }
  68. </script>
  69. <script type="module">
  70. import * as THREE from 'three/webgpu';
  71. let container;
  72. let camera, scene1, scene2, renderer;
  73. let mouseX = 0, mouseY = 0;
  74. init();
  75. function init() {
  76. const SCREEN_WIDTH = window.innerWidth;
  77. const SCREEN_HEIGHT = window.innerHeight;
  78. container = document.createElement( 'div' );
  79. document.body.appendChild( container );
  80. renderer = new THREE.WebGPURenderer( { antialias: true, forceWebGL: false } );
  81. // RENDERER
  82. renderer.setPixelRatio( window.devicePixelRatio );
  83. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  84. renderer.setAnimationLoop( render );
  85. renderer.autoClear = false;
  86. renderer.domElement.style.position = 'relative';
  87. container.appendChild( renderer.domElement );
  88. //
  89. camera = new THREE.PerspectiveCamera( 35, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 25000 );
  90. camera.position.z = 1500;
  91. scene1 = new THREE.Scene();
  92. scene1.fog = new THREE.Fog( 0xf2f7ff, 1, 25000 );
  93. scene2 = new THREE.Scene();
  94. scene2.fog = new THREE.Fog( 0xf2f7ff, 1, 25000 );
  95. scene1.add( new THREE.AmbientLight( 0xeef0ff, 3 ) );
  96. scene2.add( new THREE.AmbientLight( 0xeef0ff, 3 ) );
  97. const light1 = new THREE.DirectionalLight( 0xffffff, 6 );
  98. light1.position.set( 1, 1, 1 );
  99. scene1.add( light1 );
  100. const light2 = new THREE.DirectionalLight( 0xffffff, 6 );
  101. light2.position.set( 1, 1, 1 );
  102. scene2.add( light2 );
  103. // GROUND
  104. const textureLoader = new THREE.TextureLoader();
  105. const maxAnisotropy = renderer.getMaxAnisotropy();
  106. const texture1 = textureLoader.load( 'textures/crate.gif' );
  107. const material1 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture1 } );
  108. texture1.colorSpace = THREE.SRGBColorSpace;
  109. texture1.anisotropy = renderer.getMaxAnisotropy();
  110. texture1.wrapS = texture1.wrapT = THREE.RepeatWrapping;
  111. texture1.repeat.set( 512, 512 );
  112. const texture2 = textureLoader.load( 'textures/crate.gif' );
  113. const material2 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture2 } );
  114. texture2.colorSpace = THREE.SRGBColorSpace;
  115. texture2.anisotropy = 1;
  116. texture2.wrapS = texture2.wrapT = THREE.RepeatWrapping;
  117. texture2.repeat.set( 512, 512 );
  118. if ( maxAnisotropy > 0 ) {
  119. document.getElementById( 'val_left' ).innerHTML = texture1.anisotropy;
  120. document.getElementById( 'val_right' ).innerHTML = texture2.anisotropy;
  121. } else {
  122. document.getElementById( 'val_left' ).innerHTML = 'not supported';
  123. document.getElementById( 'val_right' ).innerHTML = 'not supported';
  124. }
  125. //
  126. const geometry = new THREE.PlaneGeometry( 100, 100 );
  127. const mesh1 = new THREE.Mesh( geometry, material1 );
  128. mesh1.rotation.x = - Math.PI / 2;
  129. mesh1.scale.set( 1000, 1000, 1000 );
  130. const mesh2 = new THREE.Mesh( geometry, material2 );
  131. mesh2.rotation.x = - Math.PI / 2;
  132. mesh2.scale.set( 1000, 1000, 1000 );
  133. scene1.add( mesh1 );
  134. scene2.add( mesh2 );
  135. //
  136. document.addEventListener( 'mousemove', onDocumentMouseMove );
  137. window.addEventListener( 'resize', onWindowResize );
  138. }
  139. function onWindowResize() {
  140. camera.aspect = window.innerWidth / window.innerHeight;
  141. camera.updateProjectionMatrix();
  142. renderer.setSize( window.innerWidth, window.innerHeight );
  143. }
  144. function onDocumentMouseMove( event ) {
  145. const windowHalfX = window.innerWidth / 2;
  146. const windowHalfY = window.innerHeight / 2;
  147. mouseX = ( event.clientX - windowHalfX );
  148. mouseY = ( event.clientY - windowHalfY );
  149. }
  150. function render() {
  151. const SCREEN_WIDTH = window.innerWidth;
  152. const SCREEN_HEIGHT = window.innerHeight;
  153. camera.position.x += ( mouseX - camera.position.x ) * .05;
  154. camera.position.y = THREE.MathUtils.clamp( camera.position.y + ( - ( mouseY - 200 ) - camera.position.y ) * .05, 50, 1000 );
  155. camera.lookAt( scene1.position );
  156. renderer.clear();
  157. renderer.setScissorTest( true );
  158. renderer.setScissor( 0, 0, SCREEN_WIDTH / 2 - 2, SCREEN_HEIGHT );
  159. renderer.render( scene1, camera );
  160. renderer.setScissorTest( true );
  161. renderer.setScissor( SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2 - 2, SCREEN_HEIGHT );
  162. renderer.render( scene2, camera );
  163. renderer.setScissorTest( false );
  164. }
  165. </script>
  166. </body>
  167. </html>
粤ICP备19079148号