webgl_performance_doublesided.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - performance</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. background:#fff;
  10. padding:0;
  11. margin:0;
  12. font-weight: bold;
  13. overflow:hidden;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <script src="../build/Three.js"></script>
  19. <script src="js/Detector.js"></script>
  20. <script src="js/Stats.js"></script>
  21. <script>
  22. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  23. var container, stats;
  24. var camera, scene, renderer;
  25. var mesh, geometry;
  26. var mouseX = 0, mouseY = 0;
  27. var SCREEN_WIDTH = window.innerWidth,
  28. SCREEN_HEIGHT = window.innerHeight;
  29. var windowHalfX = SCREEN_WIDTH / 2;
  30. var windowHalfY = SCREEN_HEIGHT / 2;
  31. var FANCY = true;
  32. init();
  33. animate();
  34. function init() {
  35. container = document.createElement( 'div' );
  36. document.body.appendChild( container );
  37. camera = new THREE.PerspectiveCamera( 50, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 20000 );
  38. camera.position.z = 3200;
  39. scene = new THREE.Scene();
  40. scene.add( camera );
  41. var light = new THREE.PointLight( 0x0011ff, 1, 5500 );
  42. light.position.set( 4000, 0, 0 );
  43. scene.add( light );
  44. var light = new THREE.PointLight( 0xff1100, 1, 5500 );
  45. light.position.set( -4000, 0, 0 );
  46. scene.add( light );
  47. if ( FANCY ) {
  48. var light = new THREE.PointLight( 0xffaa00, 2, 3000 );
  49. light.position.set( 0, 0, 0 );
  50. scene.add( light );
  51. var path = "textures/cube/SwedishRoyalCastle/";
  52. var format = '.jpg';
  53. var urls = [
  54. path + 'px' + format, path + 'nx' + format,
  55. path + 'py' + format, path + 'ny' + format,
  56. path + 'pz' + format, path + 'nz' + format
  57. ];
  58. var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
  59. reflectionCube.format = THREE.RGBFormat;
  60. var material = new THREE.MeshPhongMaterial( { specular: 0xffffff, shininess: 100, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1, perPixel: true } );
  61. material.wrapAround = true;
  62. material.wrapRGB.set( 0.5, 0.5, 0.5 );
  63. } else {
  64. var material = new THREE.MeshPhongMaterial( { specular: 0xffffff, shading: THREE.SmoothShading, perPixel: true } );
  65. }
  66. var geometry = new THREE.SphereGeometry( 1, 32, 16, 0, Math.PI );
  67. for ( var i = 0; i < 5000; i ++ ) {
  68. var mesh = new THREE.Mesh( geometry, material );
  69. mesh.position.x = Math.random() * 10000 - 5000;
  70. mesh.position.y = Math.random() * 10000 - 5000;
  71. mesh.position.z = Math.random() * 10000 - 5000;
  72. mesh.rotation.x = Math.random() * 360 * ( Math.PI / 180 );
  73. mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
  74. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  75. mesh.matrixAutoUpdate = false;
  76. mesh.updateMatrix();
  77. mesh.doubleSided = true;
  78. scene.add( mesh );
  79. }
  80. renderer = new THREE.WebGLRenderer( { clearColor: 0x050505, clearAlpha: 1, antialias: FANCY } );
  81. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  82. renderer.gammaInput = true;
  83. renderer.gammaOutput = true;
  84. renderer.physicallyBasedShading = FANCY;
  85. container.appendChild( renderer.domElement );
  86. stats = new Stats();
  87. stats.domElement.style.position = 'absolute';
  88. stats.domElement.style.top = '0px';
  89. stats.domElement.style.zIndex = 100;
  90. stats.domElement.children[ 0 ].children[ 0 ].style.color = "#eee";
  91. stats.domElement.children[ 0 ].style.background = "transparent";
  92. stats.domElement.children[ 0 ].children[ 1 ].style.display = "none";
  93. container.appendChild( stats.domElement );
  94. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  95. window.addEventListener( 'resize', onWindowResize, false );
  96. }
  97. //
  98. function onWindowResize( event ) {
  99. SCREEN_WIDTH = window.innerWidth;
  100. SCREEN_HEIGHT = window.innerHeight;
  101. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  102. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  103. camera.updateProjectionMatrix();
  104. windowHalfX = SCREEN_WIDTH / 2;
  105. windowHalfY = SCREEN_HEIGHT / 2;
  106. }
  107. function onDocumentMouseMove(event) {
  108. mouseX = ( event.clientX - windowHalfX ) * 10;
  109. mouseY = ( event.clientY - windowHalfY ) * 10;
  110. }
  111. //
  112. function animate() {
  113. requestAnimationFrame( animate );
  114. render();
  115. stats.update();
  116. }
  117. function render() {
  118. camera.position.x += ( mouseX - camera.position.x ) * .05;
  119. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  120. camera.lookAt( scene.position );
  121. renderer.render( scene, camera );
  122. }
  123. </script>
  124. </body>
  125. </html>