webgl_performance_doublesided.html 4.1 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. </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 mesh, geometry;
  28. var mouseX = 0, mouseY = 0;
  29. var SCREEN_WIDTH = window.innerWidth,
  30. SCREEN_HEIGHT = window.innerHeight;
  31. var windowHalfX = SCREEN_WIDTH / 2;
  32. var windowHalfY = SCREEN_HEIGHT / 2;
  33. init();
  34. animate();
  35. function init() {
  36. container = document.createElement( 'div' );
  37. document.body.appendChild( container );
  38. camera = new THREE.PerspectiveCamera( 50, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 20000 );
  39. camera.position.z = 3200;
  40. scene = new THREE.Scene();
  41. scene.background = new THREE.Color( 0x050505 );
  42. scene.add( new THREE.AmbientLight( 0x050505 ) );
  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 = new THREE.CubeTextureLoader().load( urls );
  60. reflectionCube.format = THREE.RGBFormat;
  61. var material = new THREE.MeshPhongMaterial( { specular: 0x101010, shininess: 100, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1, side: THREE.DoubleSide } );
  62. var geometry = new THREE.SphereBufferGeometry( 1, 32, 16, 0, Math.PI );
  63. for ( var i = 0; i < 5000; i ++ ) {
  64. var mesh = new THREE.Mesh( geometry, material );
  65. mesh.position.x = Math.random() * 10000 - 5000;
  66. mesh.position.y = Math.random() * 10000 - 5000;
  67. mesh.position.z = Math.random() * 10000 - 5000;
  68. mesh.rotation.x = Math.random() * 2 * Math.PI;
  69. mesh.rotation.y = Math.random() * 2 * Math.PI;
  70. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  71. mesh.matrixAutoUpdate = false;
  72. mesh.updateMatrix();
  73. scene.add( mesh );
  74. }
  75. renderer = new THREE.WebGLRenderer( { antialias: true } );
  76. renderer.setPixelRatio( window.devicePixelRatio );
  77. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  78. renderer.gammaInput = true;
  79. renderer.gammaOutput = true;
  80. container.appendChild( renderer.domElement );
  81. stats = new Stats();
  82. container.appendChild( stats.dom );
  83. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  84. window.addEventListener( 'resize', onWindowResize, false );
  85. }
  86. //
  87. function onWindowResize( event ) {
  88. SCREEN_WIDTH = window.innerWidth;
  89. SCREEN_HEIGHT = window.innerHeight;
  90. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  91. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  92. camera.updateProjectionMatrix();
  93. windowHalfX = SCREEN_WIDTH / 2;
  94. windowHalfY = SCREEN_HEIGHT / 2;
  95. }
  96. function onDocumentMouseMove(event) {
  97. mouseX = ( event.clientX - windowHalfX ) * 10;
  98. mouseY = ( event.clientY - windowHalfY ) * 10;
  99. }
  100. //
  101. function animate() {
  102. requestAnimationFrame( animate );
  103. render();
  104. stats.update();
  105. }
  106. function render() {
  107. camera.position.x += ( mouseX - camera.position.x ) * .05;
  108. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  109. camera.lookAt( scene.position );
  110. renderer.render( scene, camera );
  111. }
  112. </script>
  113. </body>
  114. </html>