webgl_performance_doublesided.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. var FANCY = true;
  36. init();
  37. animate();
  38. function init() {
  39. container = document.createElement( 'div' );
  40. document.body.appendChild( container );
  41. camera = new THREE.PerspectiveCamera( 50, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 20000 );
  42. camera.position.z = 3200;
  43. scene = new THREE.Scene();
  44. var light = new THREE.PointLight( 0x0011ff, 1, 5500 );
  45. light.position.set( 4000, 0, 0 );
  46. scene.add( light );
  47. var light = new THREE.PointLight( 0xff1100, 1, 5500 );
  48. light.position.set( -4000, 0, 0 );
  49. scene.add( light );
  50. if ( FANCY ) {
  51. var light = new THREE.PointLight( 0xffaa00, 2, 3000 );
  52. light.position.set( 0, 0, 0 );
  53. scene.add( light );
  54. var path = "textures/cube/SwedishRoyalCastle/";
  55. var format = '.jpg';
  56. var urls = [
  57. path + 'px' + format, path + 'nx' + format,
  58. path + 'py' + format, path + 'ny' + format,
  59. path + 'pz' + format, path + 'nz' + format
  60. ];
  61. var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
  62. reflectionCube.format = THREE.RGBFormat;
  63. var material = new THREE.MeshPhongMaterial( { specular: 0xffffff, shininess: 100, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1, side: THREE.DoubleSide } );
  64. material.wrapAround = true;
  65. material.wrapRGB.set( 0.5, 0.5, 0.5 );
  66. } else {
  67. var material = new THREE.MeshPhongMaterial( { specular: 0xffffff, shading: THREE.SmoothShading, doubleSided: true } );
  68. }
  69. var geometry = new THREE.SphereGeometry( 1, 32, 16, 0, Math.PI );
  70. for ( var i = 0; i < 5000; i ++ ) {
  71. var mesh = new THREE.Mesh( geometry, material );
  72. mesh.position.x = Math.random() * 10000 - 5000;
  73. mesh.position.y = Math.random() * 10000 - 5000;
  74. mesh.position.z = Math.random() * 10000 - 5000;
  75. mesh.rotation.x = Math.random() * 2 * Math.PI;
  76. mesh.rotation.y = Math.random() * 2 * Math.PI;
  77. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  78. mesh.matrixAutoUpdate = false;
  79. mesh.updateMatrix();
  80. scene.add( mesh );
  81. }
  82. renderer = new THREE.WebGLRenderer( { clearColor: 0x050505, clearAlpha: 1, antialias: FANCY } );
  83. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  84. renderer.gammaInput = true;
  85. renderer.gammaOutput = true;
  86. renderer.physicallyBasedShading = FANCY;
  87. container.appendChild( renderer.domElement );
  88. stats = new Stats();
  89. container.appendChild( stats.domElement );
  90. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  91. window.addEventListener( 'resize', onWindowResize, false );
  92. }
  93. //
  94. function onWindowResize( event ) {
  95. SCREEN_WIDTH = window.innerWidth;
  96. SCREEN_HEIGHT = window.innerHeight;
  97. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  98. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  99. camera.updateProjectionMatrix();
  100. windowHalfX = SCREEN_WIDTH / 2;
  101. windowHalfY = SCREEN_HEIGHT / 2;
  102. }
  103. function onDocumentMouseMove(event) {
  104. mouseX = ( event.clientX - windowHalfX ) * 10;
  105. mouseY = ( event.clientY - windowHalfY ) * 10;
  106. }
  107. //
  108. function animate() {
  109. requestAnimationFrame( animate );
  110. render();
  111. stats.update();
  112. }
  113. function render() {
  114. camera.position.x += ( mouseX - camera.position.x ) * .05;
  115. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  116. camera.lookAt( scene.position );
  117. renderer.render( scene, camera );
  118. }
  119. </script>
  120. </body>
  121. </html>