webgl_materials_texture_compressed.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - compressed textures</title>
  5. <meta charset="utf-8">
  6. <style>
  7. body {
  8. margin: 0px;
  9. background-color: #050505;
  10. color: #fff;
  11. overflow: hidden;
  12. }
  13. a { color: #e00 }
  14. #info {
  15. position: absolute;
  16. top: 0px; width: 100%;
  17. color: #ffffff;
  18. padding: 5px;
  19. font-family:Monospace;
  20. font-size:13px;
  21. text-align:center;
  22. z-index:1000;
  23. }
  24. #stats { position: absolute; top:0; left: 0 }
  25. #stats #fps { background: transparent !important }
  26. #stats #fps #fpsText { color: #aaa !important }
  27. #stats #fps #fpsGraph { display: none }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="info">
  32. <a href="http://threejs.org" target="_blank">three.js</a> - webgl - compressed textures -
  33. leaf texture by <a href="http://opengameart.org/node/10505">lauris71</a>, explosion texture by <a href="http://opengameart.org/node/7728">bart</a>
  34. </div>
  35. <script src="../build/three.min.js"></script>
  36. <script src="js/Detector.js"></script>
  37. <script src="js/libs/stats.min.js"></script>
  38. <script>
  39. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  40. var camera, scene, renderer;
  41. var meshes = [];
  42. init();
  43. animate();
  44. function init() {
  45. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  46. camera.position.z = 1000;
  47. scene = new THREE.Scene();
  48. geometry = new THREE.CubeGeometry( 200, 200, 200 );
  49. /*
  50. This is how compressed textures are supposed to be used:
  51. DXT1 - RGB - opaque textures
  52. DXT3 - RGBA - transparent textures with sharp alpha transitions
  53. DXT5 - RGBA - transparent textures with full alpha range
  54. */
  55. var map1 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/disturb_dxt1_nomip.dds' );
  56. map1.minFilter = map1.magFilter = THREE.LinearFilter;
  57. map1.anisotropy = 4;
  58. var map2 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/disturb_dxt1_mip.dds' );
  59. map2.anisotropy = 4;
  60. var map3 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/hepatica_dxt3_mip.dds' );
  61. map3.anisotropy = 4;
  62. var map4 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/explosion_dxt5_mip.dds' );
  63. map4.anisotropy = 4;
  64. var map5 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/disturb_argb_nomip.dds' );
  65. map5.minFilter = map5.magFilter = THREE.LinearFilter;
  66. map5.anisotropy = 4;
  67. var map6 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/disturb_argb_mip.dds' );
  68. map6.anisotropy = 4;
  69. var cubemap1 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/Mountains.dds', new THREE.CubeReflectionMapping, function( cubemap ) {
  70. cubemap1.magFilter = cubemap1.minFilter = THREE.LinearFilter;
  71. material1.needsUpdate = true;
  72. } );
  73. var cubemap2 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/Mountains_argb_mip.dds', new THREE.CubeReflectionMapping, function( cubemap ) {
  74. cubemap2.magFilter = cubemap2.minFilter = THREE.LinearFilter;
  75. material5.needsUpdate = true;
  76. } );
  77. var cubemap3 = THREE.ImageUtils.loadDDSTexture( 'textures/compressed/Mountains_argb_nomip.dds', new THREE.CubeReflectionMapping, function( cubemap ) {
  78. cubemap3.magFilter = cubemap3.minFilter = THREE.LinearFilter;
  79. material6.needsUpdate = true;
  80. } );
  81. var material1 = new THREE.MeshBasicMaterial( { map: map1, envMap: cubemap1 } );
  82. var material2 = new THREE.MeshBasicMaterial( { map: map2 } );
  83. var material3 = new THREE.MeshBasicMaterial( { map: map3, alphaTest: 0.5, side: THREE.DoubleSide } );
  84. var material4 = new THREE.MeshBasicMaterial( { map: map4, side: THREE.DoubleSide, blending: THREE.AdditiveBlending, depthTest: false, transparent: true } );
  85. var material5 = new THREE.MeshBasicMaterial( { envMap: cubemap2 } );
  86. var material6 = new THREE.MeshBasicMaterial( { envMap: cubemap3 } );
  87. var material7 = new THREE.MeshBasicMaterial( { map: map5 } );
  88. var material8 = new THREE.MeshBasicMaterial( { map: map6 } );
  89. var mesh = new THREE.Mesh( new THREE.TorusGeometry( 100, 50, 32, 16 ), material1 );
  90. mesh.position.x = -600;
  91. mesh.position.y = -200;
  92. scene.add( mesh );
  93. meshes.push( mesh );
  94. mesh = new THREE.Mesh( geometry, material2 );
  95. mesh.position.x = -200;
  96. mesh.position.y = -200;
  97. scene.add( mesh );
  98. meshes.push( mesh );
  99. mesh = new THREE.Mesh( geometry, material3 );
  100. mesh.position.x = -200;
  101. mesh.position.y = 200;
  102. scene.add( mesh );
  103. meshes.push( mesh );
  104. mesh = new THREE.Mesh( geometry, material4 );
  105. mesh.position.x = -600;
  106. mesh.position.y = 200;
  107. scene.add( mesh );
  108. meshes.push( mesh );
  109. mesh = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200 ), material5 );
  110. mesh.position.x = 200;
  111. mesh.position.y = 200;
  112. scene.add( mesh );
  113. meshes.push( mesh );
  114. mesh = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200 ), material6 );
  115. mesh.position.x = 200;
  116. mesh.position.y = -200;
  117. scene.add( mesh );
  118. meshes.push( mesh );
  119. mesh = new THREE.Mesh( geometry, material7 );
  120. mesh.position.x = 600;
  121. mesh.position.y = -200;
  122. scene.add( mesh );
  123. meshes.push( mesh );
  124. mesh = new THREE.Mesh( geometry, material8 );
  125. mesh.position.x = 600;
  126. mesh.position.y = 200;
  127. scene.add( mesh );
  128. meshes.push( mesh );
  129. renderer = new THREE.WebGLRenderer( { antialias: true } );
  130. renderer.setSize( window.innerWidth, window.innerHeight );
  131. document.body.appendChild( renderer.domElement );
  132. stats = new Stats();
  133. document.body.appendChild( stats.domElement );
  134. window.addEventListener( 'resize', onWindowResize, false );
  135. }
  136. function onWindowResize() {
  137. camera.aspect = window.innerWidth / window.innerHeight;
  138. camera.updateProjectionMatrix();
  139. renderer.setSize( window.innerWidth, window.innerHeight );
  140. }
  141. function animate() {
  142. requestAnimationFrame( animate );
  143. var time = Date.now() * 0.001;
  144. for ( var i = 0; i < meshes.length; i ++ ) {
  145. var mesh = meshes[ i ];
  146. mesh.rotation.x = time;
  147. mesh.rotation.y = time;
  148. }
  149. renderer.render( scene, camera );
  150. stats.update();
  151. }
  152. </script>
  153. </body>
  154. </html>