webgl_materials_texture_pvrtc.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - compressed textures</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. margin: 0px;
  10. background-color: #050505;
  11. color: #fff;
  12. overflow: hidden;
  13. }
  14. a { color: #e00 }
  15. #info {
  16. position: absolute;
  17. top: 0px; width: 100%;
  18. color: #ffffff;
  19. padding: 5px;
  20. font-family:Monospace;
  21. font-size:13px;
  22. text-align:center;
  23. z-index:1000;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="info">
  29. <a href="http://threejs.org" target="_blank">three.js</a> - webgl - PVR compressed textures
  30. </div>
  31. <script src="../build/three.js"></script>
  32. <script src="js/loaders/PVRLoader.js"></script>
  33. <script src="js/Detector.js"></script>
  34. <script src="js/libs/stats.min.js"></script>
  35. <script>
  36. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  37. var camera, scene, renderer;
  38. var meshes = [];
  39. init();
  40. animate();
  41. function init() {
  42. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  43. camera.position.z = 1000;
  44. scene = new THREE.Scene();
  45. geometry = new THREE.BoxGeometry( 200, 200, 200 );
  46. /*
  47. */
  48. var onCube1Loaded = function(texture){
  49. texture.magFilter = THREE.LinearFilter;
  50. texture.minFilter = THREE.LinearFilter;
  51. texture.mapping = THREE.CubeReflectionMapping;
  52. material6.needsUpdate = true;
  53. };
  54. var onCube2Loaded = function(texture){
  55. texture.magFilter = THREE.LinearFilter;
  56. // texture.minFilter = THREE.LinearMipMapNearestFilter;
  57. texture.minFilter = THREE.LinearFilter;
  58. texture.mapping = THREE.CubeReflectionMapping;
  59. material8.needsUpdate = true;
  60. };
  61. var loader = new THREE.PVRLoader();
  62. var disturb_4bpp_rgb = loader.load( 'textures/compressed/disturb_4bpp_rgb.pvr');
  63. var disturb_4bpp_rgb_v3 = loader.load( 'textures/compressed/disturb_4bpp_rgb_v3.pvr');
  64. var disturb_4bpp_rgb_mips = loader.load( 'textures/compressed/disturb_4bpp_rgb_mips.pvr');
  65. var disturb_2bpp_rgb = loader.load( 'textures/compressed/disturb_2bpp_rgb.pvr');
  66. var flare_4bpp_rgba = loader.load( 'textures/compressed/flare_4bpp_rgba.pvr');
  67. var flare_2bpp_rgba = loader.load( 'textures/compressed/flare_2bpp_rgba.pvr');
  68. var park3_cube_nomip_4bpp_rgb = loader.load( 'textures/compressed/park3_cube_nomip_4bpp_rgb.pvr', onCube1Loaded );
  69. var park3_cube_mip_2bpp_rgb_v3 = loader.load( 'textures/compressed/park3_cube_mip_2bpp_rgb_v3.pvr', onCube2Loaded );
  70. disturb_2bpp_rgb.minFilter =
  71. disturb_2bpp_rgb.magFilter =
  72. flare_4bpp_rgba.minFilter =
  73. flare_4bpp_rgba.magFilter =
  74. disturb_4bpp_rgb.minFilter =
  75. disturb_4bpp_rgb.magFilter =
  76. disturb_4bpp_rgb_v3.minFilter =
  77. disturb_4bpp_rgb_v3.magFilter =
  78. flare_2bpp_rgba.minFilter =
  79. flare_2bpp_rgba.magFilter = THREE.LinearFilter;
  80. var material1 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb } );
  81. var material2 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_mips } );
  82. var material3 = new THREE.MeshBasicMaterial( { map: disturb_2bpp_rgb } );
  83. var material4 = new THREE.MeshBasicMaterial( { map: flare_4bpp_rgba , side: THREE.DoubleSide, depthTest: false, transparent: true } );
  84. var material5 = new THREE.MeshBasicMaterial( { map: flare_2bpp_rgba , side: THREE.DoubleSide, depthTest: false, transparent: true } );
  85. var material6 = new THREE.MeshBasicMaterial( { envMap: park3_cube_nomip_4bpp_rgb } );
  86. var material8 = new THREE.MeshBasicMaterial( { envMap: park3_cube_mip_2bpp_rgb_v3 } );
  87. var material7 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_v3 } );
  88. var mesh = new THREE.Mesh( geometry, material1 );
  89. mesh.position.x = -500;
  90. mesh.position.y = 200;
  91. scene.add( mesh );
  92. meshes.push( mesh );
  93. mesh = new THREE.Mesh( geometry, material2 );
  94. mesh.position.x = -166;
  95. mesh.position.y = 200;
  96. scene.add( mesh );
  97. meshes.push( mesh );
  98. mesh = new THREE.Mesh( geometry, material3 );
  99. mesh.position.x = 166;
  100. mesh.position.y = 200;
  101. scene.add( mesh );
  102. meshes.push( mesh );
  103. mesh = new THREE.Mesh( geometry, material7 );
  104. mesh.position.x = 500;
  105. mesh.position.y = 200;
  106. scene.add( mesh );
  107. meshes.push( mesh );
  108. mesh = new THREE.Mesh( geometry, material4 );
  109. mesh.position.x = -500;
  110. mesh.position.y = -200;
  111. scene.add( mesh );
  112. meshes.push( mesh );
  113. mesh = new THREE.Mesh( geometry, material5 );
  114. mesh.position.x = -166;
  115. mesh.position.y = -200;
  116. scene.add( mesh );
  117. meshes.push( mesh );
  118. var torus = new THREE.TorusGeometry( 100, 50, 32, 24 );
  119. mesh = new THREE.Mesh( torus, material6 );
  120. mesh.position.x = 166;
  121. mesh.position.y = -200;
  122. scene.add( mesh );
  123. meshes.push( mesh );
  124. mesh = new THREE.Mesh( torus, material8 );
  125. mesh.position.x = 500;
  126. mesh.position.y = -200;
  127. scene.add( mesh );
  128. meshes.push( mesh );
  129. renderer = new THREE.WebGLRenderer( { antialias: true } );
  130. renderer.setPixelRatio( window.devicePixelRatio );
  131. renderer.setSize( window.innerWidth, window.innerHeight );
  132. document.body.appendChild( renderer.domElement );
  133. stats = new Stats();
  134. document.body.appendChild( stats.dom );
  135. window.addEventListener( 'resize', onWindowResize, false );
  136. }
  137. function onWindowResize() {
  138. camera.aspect = window.innerWidth / window.innerHeight;
  139. camera.updateProjectionMatrix();
  140. renderer.setSize( window.innerWidth, window.innerHeight );
  141. }
  142. function animate() {
  143. requestAnimationFrame( animate );
  144. var time = Date.now() * 0.001;
  145. for ( var i = 0; i < meshes.length; i ++ ) {
  146. var mesh = meshes[ i ];
  147. mesh.rotation.x = time;
  148. mesh.rotation.y = time;
  149. }
  150. renderer.render( scene, camera );
  151. stats.update();
  152. }
  153. </script>
  154. </body>
  155. </html>