webgl_materials_texture_compressed.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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.loadCompressedTexture( 'textures/compressed/disturb_dxt1_nomip.dds' );
  56. map1.minFilter = map1.magFilter = THREE.LinearFilter;
  57. map1.anisotropy = 4;
  58. var map2 = THREE.ImageUtils.loadCompressedTexture( 'textures/compressed/disturb_dxt1_mip.dds' );
  59. map2.anisotropy = 4;
  60. var map3 = THREE.ImageUtils.loadCompressedTexture( 'textures/compressed/hepatica_dxt3_mip.dds' );
  61. map3.anisotropy = 4;
  62. var map4 = THREE.ImageUtils.loadCompressedTexture( 'textures/compressed/explosion_dxt5_mip.dds' );
  63. map4.anisotropy = 4;
  64. var material1 = new THREE.MeshBasicMaterial( { map: map1 } );
  65. var material2 = new THREE.MeshBasicMaterial( { map: map2 } );
  66. var material3 = new THREE.MeshBasicMaterial( { map: map3, alphaTest: 0.5, side: THREE.DoubleSide } );
  67. var material4 = new THREE.MeshBasicMaterial( { map: map4, side: THREE.DoubleSide, blending: THREE.AdditiveBlending, depthTest: false, transparent: true } );
  68. var mesh = new THREE.Mesh( geometry, material1 );
  69. mesh.position.x = -200;
  70. mesh.position.y = -200;
  71. scene.add( mesh );
  72. meshes.push( mesh );
  73. mesh = new THREE.Mesh( geometry, material2 );
  74. mesh.position.x = 200;
  75. mesh.position.y = -200;
  76. scene.add( mesh );
  77. meshes.push( mesh );
  78. mesh = new THREE.Mesh( geometry, material3 );
  79. mesh.position.x = 200;
  80. mesh.position.y = 200;
  81. scene.add( mesh );
  82. meshes.push( mesh );
  83. mesh = new THREE.Mesh( geometry, material4 );
  84. mesh.position.x = -200;
  85. mesh.position.y = 200;
  86. scene.add( mesh );
  87. meshes.push( mesh );
  88. renderer = new THREE.WebGLRenderer( { antialias: true } );
  89. renderer.setSize( window.innerWidth, window.innerHeight );
  90. document.body.appendChild( renderer.domElement );
  91. stats = new Stats();
  92. document.body.appendChild( stats.domElement );
  93. window.addEventListener( 'resize', onWindowResize, false );
  94. }
  95. function onWindowResize() {
  96. camera.aspect = window.innerWidth / window.innerHeight;
  97. camera.updateProjectionMatrix();
  98. renderer.setSize( window.innerWidth, window.innerHeight );
  99. }
  100. function animate() {
  101. requestAnimationFrame( animate );
  102. var time = Date.now() * 0.001;
  103. for ( var i = 0; i < meshes.length; i ++ ) {
  104. var mesh = meshes[ i ];
  105. mesh.rotation.x = time;
  106. mesh.rotation.y = time;
  107. }
  108. renderer.render( scene, camera );
  109. stats.update();
  110. }
  111. </script>
  112. </body>
  113. </html>