2
0

webgl_loader_texture_pvrtc.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - webgl - PVR compressed textures
  12. </div>
  13. <script src="../build/three.js"></script>
  14. <script src="js/loaders/PVRLoader.js"></script>
  15. <script src="js/WebGL.js"></script>
  16. <script>
  17. if ( WEBGL.isWebGLAvailable() === false ) {
  18. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  19. }
  20. var camera, scene, renderer;
  21. var meshes = [];
  22. init();
  23. animate();
  24. function init() {
  25. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  26. camera.position.z = 1000;
  27. scene = new THREE.Scene();
  28. var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
  29. //
  30. var onCube1Loaded = function ( texture ) {
  31. texture.magFilter = THREE.LinearFilter;
  32. texture.minFilter = THREE.LinearFilter;
  33. texture.mapping = THREE.CubeReflectionMapping;
  34. material6.needsUpdate = true;
  35. };
  36. var onCube2Loaded = function ( texture ) {
  37. texture.magFilter = THREE.LinearFilter;
  38. // texture.minFilter = THREE.LinearMipMapNearestFilter;
  39. texture.minFilter = THREE.LinearFilter;
  40. texture.mapping = THREE.CubeReflectionMapping;
  41. material8.needsUpdate = true;
  42. };
  43. //
  44. var loader = new THREE.PVRLoader();
  45. var disturb_4bpp_rgb = loader.load( 'textures/compressed/disturb_4bpp_rgb.pvr' );
  46. var disturb_4bpp_rgb_v3 = loader.load( 'textures/compressed/disturb_4bpp_rgb_v3.pvr' );
  47. var disturb_4bpp_rgb_mips = loader.load( 'textures/compressed/disturb_4bpp_rgb_mips.pvr' );
  48. var disturb_2bpp_rgb = loader.load( 'textures/compressed/disturb_2bpp_rgb.pvr' );
  49. var flare_4bpp_rgba = loader.load( 'textures/compressed/flare_4bpp_rgba.pvr' );
  50. var flare_2bpp_rgba = loader.load( 'textures/compressed/flare_2bpp_rgba.pvr' );
  51. var park3_cube_nomip_4bpp_rgb = loader.load( 'textures/compressed/park3_cube_nomip_4bpp_rgb.pvr', onCube1Loaded );
  52. var park3_cube_mip_2bpp_rgb_v3 = loader.load( 'textures/compressed/park3_cube_mip_2bpp_rgb_v3.pvr', onCube2Loaded );
  53. disturb_2bpp_rgb.minFilter =
  54. disturb_2bpp_rgb.magFilter =
  55. flare_4bpp_rgba.minFilter =
  56. flare_4bpp_rgba.magFilter =
  57. disturb_4bpp_rgb.minFilter =
  58. disturb_4bpp_rgb.magFilter =
  59. disturb_4bpp_rgb_v3.minFilter =
  60. disturb_4bpp_rgb_v3.magFilter =
  61. flare_2bpp_rgba.minFilter =
  62. flare_2bpp_rgba.magFilter = THREE.LinearFilter;
  63. var material1 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb } );
  64. var material2 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_mips } );
  65. var material3 = new THREE.MeshBasicMaterial( { map: disturb_2bpp_rgb } );
  66. var material4 = new THREE.MeshBasicMaterial( { map: flare_4bpp_rgba, side: THREE.DoubleSide, depthTest: false, transparent: true } );
  67. var material5 = new THREE.MeshBasicMaterial( { map: flare_2bpp_rgba, side: THREE.DoubleSide, depthTest: false, transparent: true } );
  68. var material6 = new THREE.MeshBasicMaterial( { envMap: park3_cube_nomip_4bpp_rgb } );
  69. var material8 = new THREE.MeshBasicMaterial( { envMap: park3_cube_mip_2bpp_rgb_v3 } );
  70. var material7 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_v3 } );
  71. //
  72. var mesh = new THREE.Mesh( geometry, material1 );
  73. mesh.position.x = - 500;
  74. mesh.position.y = 200;
  75. scene.add( mesh );
  76. meshes.push( mesh );
  77. mesh = new THREE.Mesh( geometry, material2 );
  78. mesh.position.x = - 166;
  79. mesh.position.y = 200;
  80. scene.add( mesh );
  81. meshes.push( mesh );
  82. mesh = new THREE.Mesh( geometry, material3 );
  83. mesh.position.x = 166;
  84. mesh.position.y = 200;
  85. scene.add( mesh );
  86. meshes.push( mesh );
  87. mesh = new THREE.Mesh( geometry, material7 );
  88. mesh.position.x = 500;
  89. mesh.position.y = 200;
  90. scene.add( mesh );
  91. meshes.push( mesh );
  92. mesh = new THREE.Mesh( geometry, material4 );
  93. mesh.position.x = - 500;
  94. mesh.position.y = - 200;
  95. scene.add( mesh );
  96. meshes.push( mesh );
  97. mesh = new THREE.Mesh( geometry, material5 );
  98. mesh.position.x = - 166;
  99. mesh.position.y = - 200;
  100. scene.add( mesh );
  101. meshes.push( mesh );
  102. var torus = new THREE.TorusBufferGeometry( 100, 50, 32, 24 );
  103. mesh = new THREE.Mesh( torus, material6 );
  104. mesh.position.x = 166;
  105. mesh.position.y = - 200;
  106. scene.add( mesh );
  107. meshes.push( mesh );
  108. mesh = new THREE.Mesh( torus, material8 );
  109. mesh.position.x = 500;
  110. mesh.position.y = - 200;
  111. scene.add( mesh );
  112. meshes.push( mesh );
  113. //
  114. renderer = new THREE.WebGLRenderer( { antialias: true } );
  115. renderer.setPixelRatio( window.devicePixelRatio );
  116. renderer.setSize( window.innerWidth, window.innerHeight );
  117. document.body.appendChild( renderer.domElement );
  118. window.addEventListener( 'resize', onWindowResize, false );
  119. }
  120. function onWindowResize() {
  121. camera.aspect = window.innerWidth / window.innerHeight;
  122. camera.updateProjectionMatrix();
  123. renderer.setSize( window.innerWidth, window.innerHeight );
  124. }
  125. function animate() {
  126. requestAnimationFrame( animate );
  127. var time = Date.now() * 0.001;
  128. for ( var i = 0; i < meshes.length; i ++ ) {
  129. var mesh = meshes[ i ];
  130. mesh.rotation.x = time;
  131. mesh.rotation.y = time;
  132. }
  133. renderer.render( scene, camera );
  134. }
  135. </script>
  136. </body>
  137. </html>