webgl_performance_doublesided.html 4.4 KB

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