webgl_materials_texture_pvrtc.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 - PVR compressed textures
  33. </div>
  34. <script src="../build/three.min.js"></script>
  35. <script src="js/loaders/CompressedTextureLoader.js"></script>
  36. <script src="js/loaders/PVRLoader.js"></script>
  37. <script src="js/Detector.js"></script>
  38. <script src="js/libs/stats.min.js"></script>
  39. <script>
  40. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  41. var camera, scene, renderer;
  42. var meshes = [];
  43. init();
  44. animate();
  45. function init() {
  46. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  47. camera.position.z = 1000;
  48. scene = new THREE.Scene();
  49. geometry = new THREE.BoxGeometry( 200, 200, 200 );
  50. /*
  51. */
  52. var onCube1Loaded = function(texture){
  53. texture.magFilter = THREE.LinearFilter;
  54. texture.minFilter = THREE.LinearFilter;
  55. texture.mapping = THREE.CubeReflectionMapping;
  56. material6.needsUpdate = true;
  57. };
  58. var onCube2Loaded = function(texture){
  59. texture.magFilter = THREE.LinearFilter;
  60. // texture.minFilter = THREE.LinearMipMapNearestFilter;
  61. texture.minFilter = THREE.LinearFilter;
  62. texture.mapping = THREE.CubeReflectionMapping;
  63. material8.needsUpdate = true;
  64. };
  65. var loader = new THREE.PVRLoader();
  66. var disturb_4bpp_rgb = loader.load( 'textures/compressed/disturb_4bpp_rgb.pvr');
  67. var disturb_4bpp_rgb_v3 = loader.load( 'textures/compressed/disturb_4bpp_rgb_v3.pvr');
  68. var disturb_4bpp_rgb_mips = loader.load( 'textures/compressed/disturb_4bpp_rgb_mips.pvr');
  69. var disturb_2bpp_rgb = loader.load( 'textures/compressed/disturb_2bpp_rgb.pvr');
  70. var flare_4bpp_rgba = loader.load( 'textures/compressed/flare_4bpp_rgba.pvr');
  71. var flare_2bpp_rgba = loader.load( 'textures/compressed/flare_2bpp_rgba.pvr');
  72. var park3_cube_nomip_4bpp_rgb = loader.load( 'textures/compressed/park3_cube_nomip_4bpp_rgb.pvr', onCube1Loaded );
  73. var park3_cube_mip_2bpp_rgb_v3 = loader.load( 'textures/compressed/park3_cube_mip_2bpp_rgb_v3.pvr', onCube2Loaded );
  74. disturb_2bpp_rgb.minFilter =
  75. disturb_2bpp_rgb.magFilter =
  76. flare_4bpp_rgba.minFilter =
  77. flare_4bpp_rgba.magFilter =
  78. disturb_4bpp_rgb.minFilter =
  79. disturb_4bpp_rgb.magFilter =
  80. disturb_4bpp_rgb_v3.minFilter =
  81. disturb_4bpp_rgb_v3.magFilter =
  82. flare_2bpp_rgba.minFilter =
  83. flare_2bpp_rgba.magFilter = THREE.LinearFilter;
  84. var material1 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb } );
  85. var material2 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_mips } );
  86. var material3 = new THREE.MeshBasicMaterial( { map: disturb_2bpp_rgb } );
  87. var material4 = new THREE.MeshBasicMaterial( { map: flare_4bpp_rgba , side: THREE.DoubleSide, depthTest: false, transparent: true } );
  88. var material5 = new THREE.MeshBasicMaterial( { map: flare_2bpp_rgba , side: THREE.DoubleSide, depthTest: false, transparent: true } );
  89. var material6 = new THREE.MeshBasicMaterial( { envMap: park3_cube_nomip_4bpp_rgb } );
  90. var material8 = new THREE.MeshBasicMaterial( { envMap: park3_cube_mip_2bpp_rgb_v3 } );
  91. var material7 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_v3 } );
  92. var mesh = new THREE.Mesh( geometry, material1 );
  93. mesh.position.x = -500;
  94. mesh.position.y = 200;
  95. scene.add( mesh );
  96. meshes.push( mesh );
  97. mesh = new THREE.Mesh( geometry, material2 );
  98. mesh.position.x = -166;
  99. mesh.position.y = 200;
  100. scene.add( mesh );
  101. meshes.push( mesh );
  102. mesh = new THREE.Mesh( geometry, material3 );
  103. mesh.position.x = 166;
  104. mesh.position.y = 200;
  105. scene.add( mesh );
  106. meshes.push( mesh );
  107. mesh = new THREE.Mesh( geometry, material7 );
  108. mesh.position.x = 500;
  109. mesh.position.y = 200;
  110. scene.add( mesh );
  111. meshes.push( mesh );
  112. mesh = new THREE.Mesh( geometry, material4 );
  113. mesh.position.x = -500;
  114. mesh.position.y = -200;
  115. scene.add( mesh );
  116. meshes.push( mesh );
  117. mesh = new THREE.Mesh( geometry, material5 );
  118. mesh.position.x = -166;
  119. mesh.position.y = -200;
  120. scene.add( mesh );
  121. meshes.push( mesh );
  122. var torus = new THREE.TorusGeometry( 100, 50, 32, 24 )
  123. mesh = new THREE.Mesh( torus, material6 );
  124. mesh.position.x = 166;
  125. mesh.position.y = -200;
  126. scene.add( mesh );
  127. meshes.push( mesh );
  128. mesh = new THREE.Mesh( torus, material8 );
  129. mesh.position.x = 500;
  130. mesh.position.y = -200;
  131. scene.add( mesh );
  132. meshes.push( mesh );
  133. renderer = new THREE.WebGLRenderer( { antialias: true } );
  134. renderer.setPixelRatio( window.devicePixelRatio );
  135. renderer.setSize( window.innerWidth, window.innerHeight );
  136. document.body.appendChild( renderer.domElement );
  137. stats = new Stats();
  138. document.body.appendChild( stats.domElement );
  139. window.addEventListener( 'resize', onWindowResize, false );
  140. }
  141. function onWindowResize() {
  142. camera.aspect = window.innerWidth / window.innerHeight;
  143. camera.updateProjectionMatrix();
  144. renderer.setSize( window.innerWidth, window.innerHeight );
  145. }
  146. function animate() {
  147. requestAnimationFrame( animate );
  148. var time = Date.now() * 0.001;
  149. for ( var i = 0; i < meshes.length; i ++ ) {
  150. var mesh = meshes[ i ];
  151. mesh.rotation.x = time;
  152. mesh.rotation.y = time;
  153. }
  154. renderer.render( scene, camera );
  155. stats.update();
  156. }
  157. </script>
  158. </body>
  159. </html>