raytracing_sandbox_workers.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - raytracing renderer with web workers</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. font-family: Monospace;
  10. color: #ffffff;
  11. margin: 0px;
  12. padding: 0px;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script src="../build/three.min.js"></script>
  18. <script src="js/renderers/RaytracingWorkerRenderer.js"></script>
  19. <script>
  20. var hash = location.hash ? location.hash.substring(1) : '3';
  21. var WORKERS = +hash || navigator.hardwareConcurrency || 3;
  22. var container;
  23. var camera, controls, scene, renderer;
  24. var torus, cube;
  25. init();
  26. render();
  27. function initScene(width, height) {
  28. camera = new THREE.PerspectiveCamera( 60, width / height, 1, 1000 );
  29. camera.position.z = 600;
  30. scene = new THREE.Scene();
  31. // materials
  32. var phongMaterial = new THREE.MeshPhongMaterial( {
  33. color: 0xffffff,
  34. specular: 0x222222,
  35. shininess: 150,
  36. vertexColors: THREE.NoColors,
  37. shading: THREE.SmoothShading
  38. } );
  39. var phongMaterialBox = new THREE.MeshPhongMaterial( {
  40. color: 0xffffff,
  41. specular: 0x111111,
  42. shininess: 100,
  43. vertexColors: THREE.NoColors,
  44. shading: THREE.FlatShading
  45. } );
  46. var phongMaterialBoxBottom = new THREE.MeshPhongMaterial( {
  47. color: 0x666666,
  48. specular: 0x111111,
  49. shininess: 100,
  50. vertexColors: THREE.NoColors,
  51. shading: THREE.FlatShading
  52. } );
  53. var phongMaterialBoxLeft = new THREE.MeshPhongMaterial( {
  54. color: 0x990000,
  55. specular: 0x111111,
  56. shininess: 100,
  57. vertexColors: THREE.NoColors,
  58. shading: THREE.FlatShading
  59. } );
  60. var phongMaterialBoxRight = new THREE.MeshPhongMaterial( {
  61. color: 0x0066ff,
  62. specular: 0x111111,
  63. shininess: 100,
  64. vertexColors: THREE.NoColors,
  65. shading: THREE.FlatShading
  66. } );
  67. var mirrorMaterialFlat = new THREE.MeshPhongMaterial( {
  68. color: 0x000000,
  69. specular: 0xff8888,
  70. shininess: 10000,
  71. vertexColors: THREE.NoColors,
  72. shading: THREE.FlatShading
  73. } );
  74. mirrorMaterialFlat.mirror = true;
  75. mirrorMaterialFlat.reflectivity = 1;
  76. var mirrorMaterialFlatDark = new THREE.MeshPhongMaterial( {
  77. color: 0x000000,
  78. specular: 0xaaaaaa,
  79. shininess: 10000,
  80. vertexColors: THREE.NoColors,
  81. shading: THREE.FlatShading
  82. } );
  83. mirrorMaterialFlatDark.mirror = true;
  84. mirrorMaterialFlatDark.reflectivity = 1;
  85. var mirrorMaterialSmooth = new THREE.MeshPhongMaterial( {
  86. color: 0xffaa00,
  87. specular: 0x222222,
  88. shininess: 10000,
  89. vertexColors: THREE.NoColors,
  90. shading: THREE.SmoothShading
  91. } );
  92. mirrorMaterialSmooth.mirror = true;
  93. mirrorMaterialSmooth.reflectivity = 0.3;
  94. var glassMaterialFlat = new THREE.MeshPhongMaterial( {
  95. color: 0x000000,
  96. specular: 0x00ff00,
  97. shininess: 10000,
  98. vertexColors: THREE.NoColors,
  99. shading: THREE.FlatShading
  100. } );
  101. glassMaterialFlat.glass = true;
  102. glassMaterialFlat.reflectivity = 0.5;
  103. var glassMaterialSmooth = new THREE.MeshPhongMaterial( {
  104. color: 0x000000,
  105. specular: 0xffaa55,
  106. shininess: 10000,
  107. vertexColors: THREE.NoColors,
  108. shading: THREE.SmoothShading
  109. } );
  110. glassMaterialSmooth.glass = true;
  111. glassMaterialSmooth.reflectivity = 0.25;
  112. glassMaterialSmooth.refractionRatio = 0.6;
  113. // geometries
  114. var torusGeometry = new THREE.TorusKnotGeometry( 150 );
  115. var sphereGeometry = new THREE.SphereGeometry( 100, 16, 8 );
  116. var planeGeometry = new THREE.BoxGeometry( 600, 5, 600 );
  117. var boxGeometry = new THREE.BoxGeometry( 100, 100, 100 );
  118. // TorusKnot
  119. //torus = new THREE.Mesh( torusGeometry, phongMaterial );
  120. //scene.add( torus );
  121. // Sphere
  122. sphere = new THREE.Mesh( sphereGeometry, phongMaterial );
  123. sphere.scale.multiplyScalar( 0.5 );
  124. sphere.position.set( -50, -250+5, -50 );
  125. scene.add( sphere );
  126. sphere2 = new THREE.Mesh( sphereGeometry, mirrorMaterialSmooth );
  127. sphere2.scale.multiplyScalar( 0.5 );
  128. sphere2.position.set( 175, -250+5, -150 );
  129. scene.add( sphere2 );
  130. // Box
  131. box = new THREE.Mesh( boxGeometry, mirrorMaterialFlat );
  132. box.position.set( -175, -250+2.5, -150 );
  133. box.rotation.y = 0.5;
  134. scene.add( box );
  135. // Glass
  136. glass = new THREE.Mesh( sphereGeometry, glassMaterialSmooth );
  137. glass.scale.multiplyScalar( 0.5 );
  138. glass.position.set( 75, -250+5, -75 );
  139. glass.rotation.y = 0.5;
  140. scene.add( glass );
  141. // bottom
  142. plane = new THREE.Mesh( planeGeometry, phongMaterialBoxBottom );
  143. plane.position.set( 0, -300+2.5, -300 );
  144. scene.add( plane );
  145. // top
  146. plane = new THREE.Mesh( planeGeometry, phongMaterialBox );
  147. plane.position.set( 0, 300-2.5, -300 );
  148. scene.add( plane );
  149. // back
  150. plane = new THREE.Mesh( planeGeometry, phongMaterialBox );
  151. plane.rotation.x = 1.57;
  152. plane.position.set( 0, 0, -300 );
  153. scene.add( plane );
  154. plane = new THREE.Mesh( planeGeometry, mirrorMaterialFlatDark );
  155. plane.rotation.x = 1.57;
  156. plane.position.set( 0, 0, -300+10 );
  157. plane.scale.multiplyScalar( 0.85 );
  158. scene.add( plane );
  159. // left
  160. plane = new THREE.Mesh( planeGeometry, phongMaterialBoxLeft );
  161. plane.rotation.z = 1.57;
  162. plane.position.set( -300, 0, -300 );
  163. scene.add( plane );
  164. // right
  165. plane = new THREE.Mesh( planeGeometry, phongMaterialBoxRight );
  166. plane.rotation.z = 1.57;
  167. plane.position.set( 300, 0, -300 );
  168. scene.add( plane );
  169. // light
  170. var intensity = 70000;
  171. var light = new THREE.PointLight( 0xffaa55, intensity );
  172. light.position.set( -200, 100, 100 );
  173. light.physicalAttenuation = true;
  174. scene.add( light );
  175. var light = new THREE.PointLight( 0x55aaff, intensity );
  176. light.position.set( 200, 100, 100 );
  177. light.physicalAttenuation = true;
  178. scene.add( light );
  179. var light = new THREE.PointLight( 0xffffff, intensity * 1.5 );
  180. light.position.set( 0, 0, 300 );
  181. light.physicalAttenuation = true;
  182. scene.add( light );
  183. }
  184. function init() {
  185. container = document.createElement( 'div' );
  186. document.body.appendChild( container );
  187. var info = document.createElement( 'div' );
  188. info.style.position = 'absolute';
  189. info.style.top = '10px';
  190. info.style.width = '100%';
  191. info.style.zIndex = '100';
  192. info.style.textAlign = 'center';
  193. info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js<a/> - raytracing renderer (using ' + WORKERS + ' web workers)';
  194. container.appendChild( info );
  195. //
  196. initScene( window.innerWidth, window.innerHeight );
  197. //
  198. renderer = new THREE.RaytracingWorkerRenderer({
  199. workers: WORKERS
  200. });
  201. renderer.setClearColor( 0xf0f0f0 );
  202. renderer.setSize( window.innerWidth, window.innerHeight );
  203. renderer.domElement.style.position = "absolute";
  204. renderer.domElement.style.top = "0px";
  205. renderer.domElement.style.left = "0px";
  206. container.appendChild( renderer.domElement );
  207. }
  208. function render() {
  209. renderer.render( scene, camera );
  210. }
  211. </script>
  212. </body>
  213. </html>