webgl_lights_deferred_pointlights.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - deferred rendering</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-color: #000;
  10. margin: 0px;
  11. overflow: hidden;
  12. }
  13. #info {
  14. position: absolute;
  15. top: 20px; width: 100%;
  16. color: #ffffff;
  17. padding: 5px;
  18. font-family: Monospace;
  19. font-size: 13px;
  20. text-align: center;
  21. }
  22. a {
  23. color: #ff0080;
  24. text-decoration: none;
  25. }
  26. a:hover {
  27. color: #0080ff;
  28. }
  29. #stats { position: absolute; top:10px; left: 5px }
  30. #stats #fps { background: transparent !important }
  31. #stats #fps #fpsText { color: #aaa !important }
  32. #stats #fps #fpsGraph { display: none }
  33. </style>
  34. </head>
  35. <body>
  36. <div id="info">
  37. <a href="http://threejs.org" target="_blank">three.js</a> - deferred point lights WebGL demo by <a href="http://de.redplant.de" target=_blank>redPlant</a> -
  38. <a href="http://www.ir-ltd.net/infinite-3d-head-scan-released/" target="_blank">Lee Perry-Smith</a> head -
  39. light attenuation formula by <a href="http://imdoingitwrong.wordpress.com/tag/glsl/" target=_blank>Tom Madams</a>
  40. </div>
  41. <div id="container"></div>
  42. <script src="../build/three.min.js"></script>
  43. <script src="js/Detector.js"></script>
  44. <script src="js/libs/stats.min.js"></script>
  45. <script src="js/ShaderDeferred.js"></script>
  46. <script src="js/shaders/CopyShader.js"></script>
  47. <script src="js/shaders/FXAAShader.js"></script>
  48. <script src="js/shaders/ColorCorrectionShader.js"></script>
  49. <script src="js/postprocessing/EffectComposer.js"></script>
  50. <script src="js/postprocessing/RenderPass.js"></script>
  51. <script src="js/postprocessing/ShaderPass.js"></script>
  52. <script src="js/postprocessing/MaskPass.js"></script>
  53. <script src="js/controls/TrackballControls.js"></script>
  54. <!--
  55. <script src="js/loaders/UTF8Loader.js"></script>
  56. <script src="js/loaders/MTLLoader.js"></script>
  57. -->
  58. <script>
  59. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  60. var SCALE = 0.75;
  61. var MARGIN = 100;
  62. var WIDTH = window.innerWidth;
  63. var HEIGHT = window.innerHeight - 2 * MARGIN;
  64. var SCALED_WIDTH = Math.floor( SCALE * WIDTH );
  65. var SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
  66. var NEAR = 1.0, FAR = 350.0;
  67. var VIEW_ANGLE = 45;
  68. var ASPECT = WIDTH / HEIGHT;
  69. var mouseX = 0;
  70. var mouseY = 0;
  71. var targetX = 0, targetY = 0;
  72. var angle = 0;
  73. var target = new THREE.Vector3( 0, 0, 0 );
  74. var windowHalfX = window.innerWidth / 2;
  75. var windowHalfY = window.innerHeight / 2;
  76. // core
  77. var renderer, camera, controls, stats, clock;
  78. // scenes and scene nodes
  79. var lightScene, lightNode, scene, sceneNode, emitterScene, emitterNode, quadScene, quadNode;
  80. // rendertargets
  81. var rtColor, rtNormals, rtDepth, rtLight, rtEmitter, rtFinal;
  82. // composer
  83. var compColor, compNormals, compDepth, compLightBuffer, compFinal, compEmitter, compositePass;
  84. var effectFXAA;
  85. // materials
  86. var colorShader, normalShader, bumpShader, clipDepthShader, lightShader, unlitShader, compositeShader;
  87. var matNormal, matClipDepth, matBasic, matUnlit;
  88. var numLights = 50;
  89. var lights = new Array();
  90. // -----------------------------
  91. function bootstrap() {
  92. renderer = new THREE.WebGLRenderer( { alpha: false } );
  93. renderer.setSize( WIDTH, HEIGHT );
  94. renderer.setClearColorHex( 0x000000, 1 );
  95. renderer.domElement.style.position = "absolute";
  96. renderer.domElement.style.top = MARGIN + "px";
  97. renderer.domElement.style.left = "0px";
  98. var container = document.getElementById( 'container' );
  99. container.appendChild( renderer.domElement );
  100. // scene camera
  101. camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
  102. camera.position.z = 150;
  103. controls = new THREE.TrackballControls( camera, renderer.domElement );
  104. // scene for walt's head model
  105. scene = new THREE.Scene();
  106. sceneNode = new THREE.Object3D();
  107. scene.add( sceneNode );
  108. scene.add( camera );
  109. // scene for light proxy geometry
  110. lightScene = new THREE.Scene();
  111. lightNode = new THREE.Object3D();
  112. lightScene.add( lightNode );
  113. // scene for the coloured emitter spheres
  114. emitterScene = new THREE.Scene();
  115. emitterNode = new THREE.Object3D();
  116. emitterScene.add( emitterNode );
  117. // full screen quad for compositing
  118. quadScene = new THREE.Scene();
  119. quadNode = new THREE.Object3D();
  120. quadScene.add( quadNode );
  121. quadNode.add( new THREE.Mesh( new THREE.PlaneGeometry( 1, 1 ) ) );
  122. // stats
  123. stats = new Stats();
  124. stats.domElement.style.position = 'absolute';
  125. stats.domElement.style.top = '8px';
  126. stats.domElement.style.zIndex = 100;
  127. container.appendChild( stats.domElement );
  128. // clock
  129. clock = new THREE.Clock();
  130. }
  131. // -----------------------------
  132. function createRenderTargets() {
  133. var rtParamsFloatLinear = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
  134. format: THREE.RGBAFormat, type: THREE.FloatType };
  135. var rtParamsFloatNearest = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, stencilBuffer: false,
  136. format: THREE.RGBAFormat, type: THREE.FloatType };
  137. var rtParamsUByte = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
  138. format: THREE.RGBFormat, type: THREE.UnsignedByteType };
  139. // ----------------------------------------------------------
  140. // g-buffer
  141. // ----------------------------------------------------------
  142. rtNormals = new THREE.WebGLRenderTarget( SCALED_WIDTH, SCALED_HEIGHT, rtParamsFloatLinear );
  143. rtDepth = new THREE.WebGLRenderTarget( SCALED_WIDTH, SCALED_HEIGHT, rtParamsFloatLinear );
  144. rtColor = new THREE.WebGLRenderTarget( SCALED_WIDTH, SCALED_HEIGHT, rtParamsFloatNearest );
  145. rtLight = new THREE.WebGLRenderTarget( SCALED_WIDTH, SCALED_HEIGHT, rtParamsFloatLinear );
  146. rtEmitter = new THREE.WebGLRenderTarget( SCALED_WIDTH, SCALED_HEIGHT, rtParamsUByte );
  147. rtFinal = new THREE.WebGLRenderTarget( SCALED_WIDTH, SCALED_HEIGHT, rtParamsUByte );
  148. rtNormals.generateMipmaps = false;
  149. rtDepth.generateMipmaps = false;
  150. rtColor.generateMipmaps = false;
  151. rtLight.generateMipmaps = false;
  152. rtEmitter.generateMipmaps = false;
  153. rtFinal.generateMipmaps = false;
  154. var passNormals = new THREE.RenderPass( scene, camera );
  155. compNormals = new THREE.EffectComposer( renderer, rtNormals );
  156. compNormals.addPass( passNormals );
  157. var passDepth = new THREE.RenderPass( scene, camera );
  158. compDepth = new THREE.EffectComposer( renderer, rtDepth );
  159. compDepth.addPass( passDepth );
  160. var passColor = new THREE.RenderPass( scene, camera );
  161. compColor = new THREE.EffectComposer( renderer, rtColor );
  162. compColor.addPass( passColor );
  163. // ----------------------------------------------------------
  164. // light emitter spheres
  165. // ----------------------------------------------------------
  166. var emitterPass = new THREE.RenderPass( emitterScene, camera );
  167. compEmitter = new THREE.EffectComposer( renderer, rtEmitter );
  168. compEmitter.addPass( emitterPass );
  169. // ----------------------------------------------------------
  170. // lighting pass
  171. // ----------------------------------------------------------
  172. var passLight = new THREE.RenderPass( lightScene, camera );
  173. compLightBuffer = new THREE.EffectComposer( renderer, rtLight );
  174. compLightBuffer.addPass( passLight );
  175. lightShader.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
  176. lightShader.uniforms[ 'samplerNormals' ].value = compNormals.renderTarget2;
  177. lightShader.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
  178. lightShader.uniforms[ 'samplerLightBuffer' ].value = rtLight;
  179. var geomEmitter = new THREE.SphereGeometry( 0.7, 7, 7 );
  180. for ( var x = 0; x < numLights; x ++ ) {
  181. var light = lights[ x ];
  182. // setup material
  183. var matLight = new THREE.ShaderMaterial( {
  184. uniforms: THREE.UniformsUtils.clone( lightShader.uniforms ),
  185. vertexShader: lightShader.vertexShader,
  186. fragmentShader: lightShader.fragmentShader,
  187. defines: { "ADDITIVE_SPECULAR": false, "SPECULAR_INTENSITY" : 0.048, "SHININESS": 75.01 },
  188. blending: THREE.AdditiveBlending,
  189. depthWrite: false,
  190. transparent: true
  191. } );
  192. matLight.uniforms[ "lightPos" ].value = light.position;
  193. matLight.uniforms[ "lightRadius" ].value = light.distance;
  194. matLight.uniforms[ "lightIntensity" ].value = light.intensity;
  195. matLight.uniforms[ "lightColor" ].value = light.color;
  196. // setup proxy geometry for this light
  197. var geomLight = new THREE.SphereGeometry( light.distance, 16, 8 );
  198. var meshLight = new THREE.Mesh( geomLight, matLight );
  199. lightNode.add( meshLight );
  200. // create emitter sphere
  201. var matEmitter = new THREE.ShaderMaterial( {
  202. uniforms: THREE.UniformsUtils.clone( unlitShader.uniforms ),
  203. vertexShader: unlitShader.vertexShader,
  204. fragmentShader: unlitShader.fragmentShader
  205. } );
  206. var meshEmitter = new THREE.Mesh( geomEmitter, matEmitter );
  207. meshEmitter.position = light.position;
  208. emitterNode.add( meshEmitter );
  209. // add emitter to light node
  210. meshLight.emitter = meshEmitter;
  211. }
  212. // ----------------------------------------------------------
  213. // composite
  214. // ----------------------------------------------------------
  215. compositeShader.uniforms[ 'samplerLightBuffer' ].value = compLightBuffer.renderTarget2;
  216. compositeShader.uniforms[ 'samplerEmitter' ].value = compEmitter.renderTarget2;
  217. compositePass = new THREE.ShaderPass( compositeShader );
  218. compositePass.needsSwap = true;
  219. //compositePass.renderToScreen = true;
  220. effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
  221. //effectFXAA.uniforms[ 'resolution' ].value.set( 1 / WIDTH, 1 / HEIGHT );
  222. effectFXAA.uniforms[ 'resolution' ].value.set( 1 / SCALED_WIDTH, 1 / SCALED_HEIGHT );
  223. //effectFXAA.renderToScreen = true;
  224. var effectColor = new THREE.ShaderPass( THREE.ColorCorrectionShader );
  225. effectColor.renderToScreen = true;
  226. effectColor.uniforms[ 'powRGB' ].value.set( 1, 1, 1 );
  227. effectColor.uniforms[ 'mulRGB' ].value.set( 2, 2, 2 );
  228. compFinal = new THREE.EffectComposer( renderer, rtFinal );
  229. compFinal.addPass( compositePass );
  230. compFinal.addPass( effectFXAA );
  231. compFinal.addPass( effectColor );
  232. }
  233. // -----------------------------
  234. function initScene( object, y, scale ) {
  235. object.traverse( function( node ) {
  236. if ( node.material ) {
  237. // color material
  238. var uniforms = THREE.UniformsUtils.clone( colorShader.uniforms );
  239. var defines = { "USE_MAP": !!node.material.map, "GAMMA_INPUT": true };
  240. var material = new THREE.ShaderMaterial( {
  241. fragmentShader: colorShader.fragmentShader,
  242. vertexShader: colorShader.vertexShader,
  243. uniforms: uniforms,
  244. defines: defines
  245. } );
  246. uniforms.diffuse.value.copy( node.material.color );
  247. uniforms.map.value = node.material.map;
  248. if ( node.material.bumpMap ) {
  249. var offset = node.material.bumpMap.offset;
  250. var repeat = node.material.bumpMap.repeat;
  251. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  252. }
  253. if ( node.material.transparent ) {
  254. material.alphaTest = 0.1;
  255. }
  256. if ( node.material.name === "eyetrans" ) {
  257. material.visible = false;
  258. }
  259. node.properties.colorMaterial = material;
  260. // normal material
  261. if ( node.material.bumpMap ) {
  262. var uniforms = THREE.UniformsUtils.clone( bumpShader.uniforms );
  263. var normalMaterial = new THREE.ShaderMaterial( {
  264. uniforms: uniforms,
  265. vertexShader: bumpShader.vertexShader,
  266. fragmentShader: bumpShader.fragmentShader,
  267. defines: { "USE_BUMPMAP": true }
  268. } );
  269. uniforms.bumpMap.value = node.material.bumpMap;
  270. uniforms.bumpScale.value = node.material.bumpScale;
  271. var offset = node.material.bumpMap.offset;
  272. var repeat = node.material.bumpMap.repeat;
  273. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  274. node.properties.normalMaterial = normalMaterial;
  275. } else {
  276. node.properties.normalMaterial = matNormal;
  277. }
  278. // depth material
  279. node.properties.depthMaterial = matClipDepth;
  280. }
  281. } );
  282. object.position.y = y;
  283. object.scale.set( scale, scale, scale );
  284. sceneNode.add( object );
  285. }
  286. // -----------------------------
  287. function initMaterials() {
  288. // -----------------------
  289. // shader definitions
  290. // -----------------------
  291. colorShader = THREE.ShaderDeferred[ "color" ];
  292. normalShader = THREE.ShaderDeferred[ "normals" ];
  293. bumpShader = THREE.ShaderDeferred[ "bump" ];
  294. clipDepthShader = THREE.ShaderDeferred[ "clipDepth" ];
  295. unlitShader = THREE.ShaderDeferred[ "unlit" ];
  296. lightShader = THREE.ShaderDeferred[ "light" ];
  297. compositeShader = THREE.ShaderDeferred[ "composite" ];
  298. unlitShader.uniforms[ "viewWidth" ].value = SCALED_WIDTH;
  299. unlitShader.uniforms[ "viewHeight" ].value = SCALED_HEIGHT;
  300. lightShader.uniforms[ "viewWidth" ].value = SCALED_WIDTH;
  301. lightShader.uniforms[ "viewHeight" ].value = SCALED_HEIGHT;
  302. // -----------------------
  303. // default materials
  304. // -----------------------
  305. matNormal = new THREE.ShaderMaterial( {
  306. uniforms: THREE.UniformsUtils.clone( normalShader.uniforms ),
  307. vertexShader: normalShader.vertexShader,
  308. fragmentShader: normalShader.fragmentShader
  309. } );
  310. matClipDepth = new THREE.ShaderMaterial( {
  311. uniforms: THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
  312. vertexShader: clipDepthShader.vertexShader,
  313. fragmentShader: clipDepthShader.fragmentShader
  314. } );
  315. }
  316. // -----------------------------
  317. function initLights() {
  318. var distance = 40;
  319. // front light
  320. var light = new THREE.PointLight();
  321. light.color = new THREE.Vector3( 1, 1, 1 );
  322. light.intensity = 1.5;
  323. light.distance = 1.5 * distance;
  324. lights.push( light );
  325. // random lights
  326. for ( var i = 1; i < numLights; i ++ ) {
  327. var light = new THREE.PointLight();
  328. light.color = new THREE.Vector3( Math.random(), Math.random(), Math.random() ).normalize();
  329. // gamma to linear
  330. light.color.x *= light.color.x;
  331. light.color.y *= light.color.y;
  332. light.color.z *= light.color.z;
  333. light.intensity = 2.0;
  334. light.distance = distance;
  335. lights.push( light );
  336. }
  337. }
  338. // -----------------------------
  339. function onDocumentMouseMove( event ) {
  340. mouseX = ( event.clientX - windowHalfX ) * 1;
  341. mouseY = ( event.clientY - windowHalfY ) * 1;
  342. }
  343. // -----------------------------
  344. function animate() {
  345. var delta = clock.getDelta();
  346. requestAnimationFrame( animate );
  347. //controls.update( delta );
  348. targetX = mouseX * .001;
  349. targetY = mouseY * .001;
  350. angle += 0.05 * ( targetX - angle );
  351. camera.position.x = -Math.sin( angle ) * 150;
  352. camera.position.z = Math.cos( angle ) * 150;
  353. camera.lookAt( target );
  354. stats.update();
  355. render();
  356. }
  357. // -----------------------------
  358. function render() {
  359. // -----------------------------
  360. // g-buffer color
  361. // -----------------------------
  362. sceneNode.traverse( function( node ) {
  363. if ( node.material ) {
  364. node.material = node.properties.colorMaterial;
  365. }
  366. } );
  367. compColor.render();
  368. // -----------------------------
  369. // g-buffer depth
  370. // -----------------------------
  371. sceneNode.traverse( function( node ) {
  372. if ( node.material ) {
  373. node.material = node.properties.depthMaterial;
  374. }
  375. } );
  376. compDepth.render();
  377. // -----------------------------
  378. // g-buffer normals
  379. // -----------------------------
  380. sceneNode.traverse( function( node ) {
  381. if ( node.material ) {
  382. node.material = node.properties.normalMaterial;
  383. }
  384. } );
  385. compNormals.render();
  386. // -----------------------------
  387. // emitter pass
  388. // -----------------------------
  389. for ( var i = 0, il = lightNode.children.length; i < il; i ++ ) {
  390. var light = lightNode.children[ i ];
  391. var color = light.material.uniforms[ "lightColor" ].value;
  392. var emitter = light.emitter;
  393. emitter.material.uniforms[ "samplerDepth" ].value = compDepth.renderTarget2;
  394. emitter.material.uniforms[ "lightColor" ].value = color;
  395. }
  396. compEmitter.render();
  397. // -----------------------------
  398. // light pass
  399. // -----------------------------
  400. camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
  401. for ( var i = 0, il = lightNode.children.length; i < il; i ++ ) {
  402. var uniforms = lightNode.children[ i ].material.uniforms;
  403. uniforms[ "matProjInverse" ].value = camera.projectionMatrixInverse;
  404. uniforms[ "matView" ].value = camera.matrixWorldInverse;
  405. }
  406. var time = Date.now() * 0.0005;
  407. // update lights
  408. var x, y, z;
  409. for ( var i = 0; i < numLights; i ++ ) {
  410. if ( i > 0 ) {
  411. x = Math.sin( time + i * 1.7 ) * 80;
  412. y = Math.cos( time + i * 1.5 ) * 40;
  413. z = Math.cos( time + i * 1.3 ) * 30;
  414. } else {
  415. x = Math.sin( time * 3 ) * 20;
  416. y = 15;
  417. z = Math.cos( time * 3 ) * 25 + 10;
  418. }
  419. var light = lightNode.children[ i ];
  420. var lightPosition = light.material.uniforms[ "lightPos" ].value;
  421. lightPosition.x = x;
  422. lightPosition.y = y;
  423. lightPosition.z = z;
  424. light.emitter.position = lightPosition;
  425. light.position = lightPosition;
  426. light.frustumCulled = false;
  427. }
  428. compLightBuffer.render();
  429. // -----------------------------
  430. // composite pass
  431. // -----------------------------
  432. compFinal.render( 0.1 );
  433. }
  434. // -----------------------------
  435. // entry point
  436. // -----------------------------
  437. bootstrap();
  438. initMaterials();
  439. initLights();
  440. createRenderTargets();
  441. /*
  442. var loader = new THREE.UTF8Loader();
  443. loader.load( "models/utf8/ben_dds.js", function ( object ) {
  444. initScene( object, -75, 150 );
  445. animate();
  446. }, { normalizeRGB: true } );
  447. */
  448. /*
  449. loader.load( "models/utf8/WaltHi.js", function ( object ) {
  450. initScene( object, -35, 1 );
  451. animate();
  452. }, { normalizeRGB: true } );
  453. */
  454. var loader = new THREE.JSONLoader();
  455. loader.load( "obj/leeperrysmith/LeePerrySmith.js", function( geometry, materials ) {
  456. var mapColor = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
  457. var mapHeight = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Disp_NoSmoothUV-4096.jpg" );
  458. mapHeight.repeat.set( 0.998, 0.998 );
  459. mapHeight.offset.set( 0.001, 0.001 )
  460. mapHeight.wrapS = mapHeight.wrapT = THREE.RepeatWrapping;
  461. mapHeight.anisotropy = 4;
  462. mapHeight.format = THREE.RGBFormat;
  463. var material = new THREE.MeshPhongMaterial( { map: mapColor, bumpMap: mapHeight, bumpScale: 2.5 } );
  464. var object = new THREE.Mesh( geometry, material );
  465. // box
  466. var mapHeight2 = THREE.ImageUtils.loadTexture( "obj/lightmap/rocks.jpg" );
  467. mapHeight2.repeat.set( 3, 1.5 );
  468. mapHeight2.wrapS = mapHeight2.wrapT = THREE.RepeatWrapping;
  469. mapHeight2.anisotropy = 4;
  470. mapHeight2.format = THREE.RGBFormat;
  471. var mapHeight3 = THREE.ImageUtils.loadTexture( "textures/water.jpg" );
  472. mapHeight3.repeat.set( 16, 8 );
  473. mapHeight3.wrapS = mapHeight3.wrapT = THREE.RepeatWrapping;
  474. mapHeight3.anisotropy = 4;
  475. mapHeight3.format = THREE.RGBFormat;
  476. var geoPlane = new THREE.PlaneGeometry( 40, 20 );
  477. var matPlane = new THREE.MeshPhongMaterial( { color: 0xffffff, bumpMap: mapHeight2, bumpScale: 0.5 } );
  478. var matPlane2 = new THREE.MeshPhongMaterial( { color: 0x331919, bumpMap: mapHeight2, bumpScale: 1 } );
  479. var matPlane3 = new THREE.MeshPhongMaterial( { color: 0xffffff, bumpMap: mapHeight3, bumpScale: 1 } );
  480. // bottom
  481. var mesh = new THREE.Mesh( geoPlane, matPlane2 );
  482. mesh.position.z = -2;
  483. mesh.position.y = -6;
  484. mesh.rotation.x = -Math.PI/2;
  485. object.add( mesh );
  486. // top
  487. var mesh = new THREE.Mesh( geoPlane, matPlane3 );
  488. mesh.position.z = -2;
  489. mesh.position.y = 6;
  490. mesh.rotation.x = Math.PI/2;
  491. object.add( mesh );
  492. // back
  493. var mesh = new THREE.Mesh( geoPlane, matPlane );
  494. mesh.position.z = -4;
  495. mesh.position.y = 0;
  496. object.add( mesh );
  497. // right
  498. var mesh = new THREE.Mesh( geoPlane, matPlane );
  499. mesh.position.z = 0;
  500. mesh.position.y = 0;
  501. mesh.position.x = 13;
  502. mesh.rotation.y = -Math.PI/2;
  503. //object.add( mesh );
  504. // left
  505. var mesh = new THREE.Mesh( geoPlane, matPlane );
  506. mesh.position.z = 0;
  507. mesh.position.y = 0;
  508. mesh.position.x = -13;
  509. mesh.rotation.y = Math.PI/2;
  510. //object.add( mesh );
  511. initScene( object, 0, 8 );
  512. animate();
  513. } );
  514. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  515. </script>
  516. </body>
  517. </html>
粤ICP备19079148号