webgl_performance_doublesided.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <script src="../build/three.js"></script>
  11. <script src="js/WebGL.js"></script>
  12. <script src="js/libs/stats.min.js"></script>
  13. <script>
  14. if ( WEBGL.isWebGLAvailable() === false ) {
  15. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  16. }
  17. var container, stats;
  18. var camera, scene, renderer;
  19. var mouseX = 0, mouseY = 0;
  20. var SCREEN_WIDTH = window.innerWidth,
  21. SCREEN_HEIGHT = window.innerHeight;
  22. var windowHalfX = SCREEN_WIDTH / 2;
  23. var windowHalfY = SCREEN_HEIGHT / 2;
  24. init();
  25. animate();
  26. function init() {
  27. container = document.createElement( 'div' );
  28. document.body.appendChild( container );
  29. camera = new THREE.PerspectiveCamera( 50, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 20000 );
  30. camera.position.z = 3200;
  31. scene = new THREE.Scene();
  32. scene.background = new THREE.Color( 0x050505 );
  33. scene.add( new THREE.AmbientLight( 0x050505 ) );
  34. var light = new THREE.PointLight( 0x0011ff, 1, 5500 );
  35. light.position.set( 4000, 0, 0 );
  36. scene.add( light );
  37. var light = new THREE.PointLight( 0xff1100, 1, 5500 );
  38. light.position.set( - 4000, 0, 0 );
  39. scene.add( light );
  40. var light = new THREE.PointLight( 0xffaa00, 2, 3000 );
  41. light.position.set( 0, 0, 0 );
  42. scene.add( light );
  43. var path = "textures/cube/SwedishRoyalCastle/";
  44. var format = '.jpg';
  45. var urls = [
  46. path + 'px' + format, path + 'nx' + format,
  47. path + 'py' + format, path + 'ny' + format,
  48. path + 'pz' + format, path + 'nz' + format
  49. ];
  50. var reflectionCube = new THREE.CubeTextureLoader().load( urls );
  51. reflectionCube.format = THREE.RGBFormat;
  52. var material = new THREE.MeshPhongMaterial( { specular: 0x101010, shininess: 100, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1, side: THREE.DoubleSide } );
  53. var geometry = new THREE.SphereBufferGeometry( 1, 32, 16, 0, Math.PI );
  54. for ( var i = 0; i < 5000; i ++ ) {
  55. var mesh = new THREE.Mesh( geometry, material );
  56. mesh.position.x = Math.random() * 10000 - 5000;
  57. mesh.position.y = Math.random() * 10000 - 5000;
  58. mesh.position.z = Math.random() * 10000 - 5000;
  59. mesh.rotation.x = Math.random() * 2 * Math.PI;
  60. mesh.rotation.y = Math.random() * 2 * Math.PI;
  61. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  62. mesh.matrixAutoUpdate = false;
  63. mesh.updateMatrix();
  64. scene.add( mesh );
  65. }
  66. renderer = new THREE.WebGLRenderer( { antialias: true } );
  67. renderer.setPixelRatio( window.devicePixelRatio );
  68. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  69. renderer.gammaInput = true;
  70. renderer.gammaOutput = true;
  71. container.appendChild( renderer.domElement );
  72. stats = new Stats();
  73. container.appendChild( stats.dom );
  74. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  75. window.addEventListener( 'resize', onWindowResize, false );
  76. }
  77. //
  78. function onWindowResize() {
  79. SCREEN_WIDTH = window.innerWidth;
  80. SCREEN_HEIGHT = window.innerHeight;
  81. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  82. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  83. camera.updateProjectionMatrix();
  84. windowHalfX = SCREEN_WIDTH / 2;
  85. windowHalfY = SCREEN_HEIGHT / 2;
  86. }
  87. function onDocumentMouseMove( event ) {
  88. mouseX = ( event.clientX - windowHalfX ) * 10;
  89. mouseY = ( event.clientY - windowHalfY ) * 10;
  90. }
  91. //
  92. function animate() {
  93. requestAnimationFrame( animate );
  94. render();
  95. stats.update();
  96. }
  97. function render() {
  98. camera.position.x += ( mouseX - camera.position.x ) * .05;
  99. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  100. camera.lookAt( scene.position );
  101. renderer.render( scene, camera );
  102. }
  103. </script>
  104. </body>
  105. </html>