2
0

raytracing_sandbox.html 6.8 KB

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