webgl_loader_texture_pvrtc.html 5.9 KB

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