webgl_performance_doublesided.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/WebGL.js"></script>
  20. <script src="js/libs/stats.min.js"></script>
  21. <script>
  22. if ( WEBGL.isWebGLAvailable() === false ) {
  23. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  24. }
  25. var container, stats;
  26. var camera, scene, renderer;
  27. var mouseX = 0, mouseY = 0;
  28. var SCREEN_WIDTH = window.innerWidth,
  29. SCREEN_HEIGHT = window.innerHeight;
  30. var windowHalfX = SCREEN_WIDTH / 2;
  31. var windowHalfY = SCREEN_HEIGHT / 2;
  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.background = new THREE.Color( 0x050505 );
  41. scene.add( new THREE.AmbientLight( 0x050505 ) );
  42. var light = new THREE.PointLight( 0x0011ff, 1, 5500 );
  43. light.position.set( 4000, 0, 0 );
  44. scene.add( light );
  45. var light = new THREE.PointLight( 0xff1100, 1, 5500 );
  46. light.position.set( - 4000, 0, 0 );
  47. scene.add( light );
  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 = new THREE.CubeTextureLoader().load( urls );
  59. reflectionCube.format = THREE.RGBFormat;
  60. var material = new THREE.MeshPhongMaterial( { specular: 0x101010, shininess: 100, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1, side: THREE.DoubleSide } );
  61. var geometry = new THREE.SphereBufferGeometry( 1, 32, 16, 0, Math.PI );
  62. for ( var i = 0; i < 5000; i ++ ) {
  63. var mesh = new THREE.Mesh( geometry, material );
  64. mesh.position.x = Math.random() * 10000 - 5000;
  65. mesh.position.y = Math.random() * 10000 - 5000;
  66. mesh.position.z = Math.random() * 10000 - 5000;
  67. mesh.rotation.x = Math.random() * 2 * Math.PI;
  68. mesh.rotation.y = Math.random() * 2 * Math.PI;
  69. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  70. mesh.matrixAutoUpdate = false;
  71. mesh.updateMatrix();
  72. scene.add( mesh );
  73. }
  74. renderer = new THREE.WebGLRenderer( { antialias: true } );
  75. renderer.setPixelRatio( window.devicePixelRatio );
  76. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  77. renderer.gammaInput = true;
  78. renderer.gammaOutput = true;
  79. container.appendChild( renderer.domElement );
  80. stats = new Stats();
  81. container.appendChild( stats.dom );
  82. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  83. window.addEventListener( 'resize', onWindowResize, false );
  84. }
  85. //
  86. function onWindowResize() {
  87. SCREEN_WIDTH = window.innerWidth;
  88. SCREEN_HEIGHT = window.innerHeight;
  89. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  90. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  91. camera.updateProjectionMatrix();
  92. windowHalfX = SCREEN_WIDTH / 2;
  93. windowHalfY = SCREEN_HEIGHT / 2;
  94. }
  95. function onDocumentMouseMove( event ) {
  96. mouseX = ( event.clientX - windowHalfX ) * 10;
  97. mouseY = ( event.clientY - windowHalfY ) * 10;
  98. }
  99. //
  100. function animate() {
  101. requestAnimationFrame( animate );
  102. render();
  103. stats.update();
  104. }
  105. function render() {
  106. camera.position.x += ( mouseX - camera.position.x ) * .05;
  107. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  108. camera.lookAt( scene.position );
  109. renderer.render( scene, camera );
  110. }
  111. </script>
  112. </body>
  113. </html>