webgl_materials_texture_anisotropy.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. <style>
  8. body {
  9. color: #000;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. background-color: #fff;
  14. margin: 0px;
  15. padding: 0px;
  16. overflow: hidden;
  17. }
  18. #info {
  19. position: absolute;
  20. top: 0px; width: 100%;
  21. padding: 5px;
  22. z-index:100;
  23. }
  24. .lbl { color:#fff; font-size:16px; font-weight:bold; position: absolute; bottom:0px; z-index:100; text-shadow:#000 1px 1px 1px; background-color:rgba(0,0,0,0.85); padding:1em }
  25. #lbl_left { text-align:left; left:0px }
  26. #lbl_right { text-align:left; right:0px }
  27. .g { color:#aaa }
  28. .c { color:#fa0 }
  29. a { color:red }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="info">
  34. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - anisotropic texture filtering example
  35. </div>
  36. <div id="lbl_left" class="lbl">
  37. anisotropy: <span class="c" id="val_left"></span><br/>
  38. </div>
  39. <div id="lbl_right" class="lbl">
  40. anisotropy: <span class="c" id="val_right"></span><br/>
  41. </div>
  42. <script src="../build/three.min.js"></script>
  43. <script src="js/Detector.js"></script>
  44. <script src="js/Stats.js"></script>
  45. <script>
  46. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  47. var SCREEN_WIDTH = window.innerWidth;
  48. var SCREEN_HEIGHT = window.innerHeight;
  49. var container,stats;
  50. var camera, scene1, scene2, renderer;
  51. var mouseX = 0, mouseY = 0;
  52. var windowHalfX = window.innerWidth / 2;
  53. var windowHalfY = window.innerHeight / 2;
  54. init();
  55. animate();
  56. function init() {
  57. container = document.createElement( 'div' );
  58. document.body.appendChild( container );
  59. renderer = new THREE.WebGLRenderer( { antialias: true } );
  60. //
  61. camera = new THREE.PerspectiveCamera( 35, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 25000 );
  62. camera.position.z = 1500;
  63. scene1 = new THREE.Scene();
  64. scene2 = new THREE.Scene();
  65. scene1.fog = new THREE.Fog( 0xffffff, 1, 25000 );
  66. scene1.fog.color.setHSV( 0.6, 0.05, 1 );
  67. scene2.fog = scene1.fog;
  68. scene1.add( new THREE.AmbientLight( 0xeef0ff ) );
  69. scene2.add( new THREE.AmbientLight( 0xeef0ff ) );
  70. var light1 = new THREE.DirectionalLight( 0xffffff, 2 );
  71. light1.position.set( 1, 1, 1 );
  72. scene1.add( light1 );
  73. var light2 = new THREE.DirectionalLight( 0xffffff, 2 );
  74. light2.position = light1.position;
  75. scene2.add( light2 );
  76. // GROUND
  77. var maxAnisotropy = renderer.getMaxAnisotropy();
  78. var texture1 = THREE.ImageUtils.loadTexture( "textures/crate.gif" );
  79. var material1 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture1 } );
  80. texture1.anisotropy = maxAnisotropy;
  81. texture1.wrapS = texture1.wrapT = THREE.RepeatWrapping;
  82. texture1.repeat.set( 512, 512 );
  83. var texture2 = THREE.ImageUtils.loadTexture( "textures/crate.gif" );
  84. var material2 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture2 } );
  85. texture2.anisotropy = 1;
  86. texture2.wrapS = texture2.wrapT = THREE.RepeatWrapping;
  87. texture2.repeat.set( 512, 512 );
  88. if ( maxAnisotropy > 0 ) {
  89. document.getElementById( "val_left" ).innerHTML = texture1.anisotropy;
  90. document.getElementById( "val_right" ).innerHTML = texture2.anisotropy;
  91. } else {
  92. document.getElementById( "val_left" ).innerHTML = "not supported";
  93. document.getElementById( "val_right" ).innerHTML = "not supported";
  94. }
  95. //
  96. var geometry = new THREE.PlaneGeometry( 100, 100 );
  97. var mesh1 = new THREE.Mesh( geometry, material1 );
  98. mesh1.rotation.x = - Math.PI / 2;
  99. mesh1.scale.set( 1000, 1000, 1000 );
  100. var mesh2 = new THREE.Mesh( geometry, material2 );
  101. mesh2.rotation.x = - Math.PI / 2;
  102. mesh2.scale.set( 1000, 1000, 1000 );
  103. scene1.add( mesh1 );
  104. scene2.add( mesh2 );
  105. // RENDERER
  106. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  107. renderer.setClearColor( scene1.fog.color, 1 );
  108. renderer.autoClear = false;
  109. renderer.domElement.style.position = "relative";
  110. container.appendChild( renderer.domElement );
  111. // STATS1
  112. stats = new Stats();
  113. stats.domElement.style.position = 'absolute';
  114. stats.domElement.style.top = '0px';
  115. stats.domElement.style.zIndex = 100;
  116. container.appendChild( stats.domElement );
  117. stats.domElement.children[ 0 ].children[ 0 ].style.color = "#777";
  118. stats.domElement.children[ 0 ].style.background = "transparent";
  119. stats.domElement.children[ 0 ].children[ 1 ].style.display = "none";
  120. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  121. }
  122. function onDocumentMouseMove(event) {
  123. mouseX = ( event.clientX - windowHalfX );
  124. mouseY = ( event.clientY - windowHalfY );
  125. }
  126. function animate() {
  127. requestAnimationFrame( animate );
  128. render();
  129. stats.update();
  130. }
  131. function render() {
  132. camera.position.x += ( mouseX - camera.position.x ) * .05;
  133. camera.position.y = THREE.Math.clamp( camera.position.y + ( - ( mouseY - 200 ) - camera.position.y ) * .05, 50, 1000 );
  134. camera.lookAt( scene1.position );
  135. renderer.enableScissorTest( false );
  136. renderer.clear();
  137. renderer.enableScissorTest( true );
  138. renderer.setScissor( 0, 0, SCREEN_WIDTH/2 - 2, SCREEN_HEIGHT );
  139. renderer.render( scene1, camera );
  140. renderer.setScissor( SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2 - 2, SCREEN_HEIGHT );
  141. renderer.render( scene2, camera );
  142. }
  143. </script>
  144. </body>
  145. </html>