webgl_materials_texture_anisotropy.html 5.2 KB

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