materials_normalmap2.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - webgl normal map - lee perry-smith</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. background:#000;
  9. color:#fff;
  10. padding:0;
  11. margin:0;
  12. font-weight: bold;
  13. overflow:hidden;
  14. }
  15. a { color: #ffffff; }
  16. #info {
  17. position: absolute;
  18. top: 0px; width: 100%;
  19. color: #ffffff;
  20. padding: 5px;
  21. font-family:Monospace;
  22. font-size:13px;
  23. text-align:center;
  24. z-index:1000;
  25. }
  26. #oldie {
  27. font-family:monospace;
  28. font-size:13px;
  29. text-align:center;
  30. background:rgb(200,100,0);
  31. color:#fff;
  32. padding:1em;
  33. width:475px;
  34. margin:5em auto 0;
  35. border:solid 2px #fff;
  36. border-radius:10px;
  37. display:none;
  38. }
  39. #vt { display:none }
  40. #vt, #vt a { color:orange; }
  41. .code { }
  42. #log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
  43. </style>
  44. </head>
  45. <body>
  46. <pre id="log"></pre>
  47. <div id="info">
  48. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl normalmap demo.
  49. <a href="http://www.ir-ltd.net/infinite-3d-head-scan-released/" target="_blank">Lee Perry-Smith</a> head.
  50. <div id="vt">displacement mapping needs vertex textures (GPU with Shader Model 3.0)<br/>
  51. on Windows use <span class="code">Chrome --use-gl=desktop</span> or Firefox 4<br/>
  52. please star this <a href="http://code.google.com/p/chromium/issues/detail?id=52497">Chrome issue</a> to get ANGLE support
  53. </div>
  54. </div>
  55. <center>
  56. <div id="oldie">
  57. Sorry, your browser doesn't support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>
  58. and <a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Workers</a>.<br/>
  59. <br/>
  60. Please try in
  61. <a href="http://www.chromium.org/getting-involved/dev-channel">Chrome 9+</a> /
  62. <a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 4+</a> /
  63. <a href="http://nightly.webkit.org/">Safari OSX 10.6+</a>
  64. </div>
  65. </center>
  66. <script type="text/javascript" src="../build/ThreeExtras.js"></script>
  67. <script type="text/javascript" src="js/Stats.js"></script>
  68. <script type="text/javascript">
  69. if ( !is_browser_compatible() ) {
  70. document.getElementById( "oldie" ).style.display = "block";
  71. }
  72. var statsEnabled = true;
  73. var container, stats, loader;
  74. var camera, scene, webglRenderer;
  75. var mesh, zmesh, lightMesh, geometry;
  76. var mesh1;
  77. var directionalLight, pointLight, ambientLight;
  78. var mouseX = 0;
  79. var mouseY = 0;
  80. var windowHalfX = window.innerWidth / 2;
  81. var windowHalfY = window.innerHeight / 2;
  82. var r = 0.0;
  83. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  84. init();
  85. setInterval( loop, 1000 / 60 );
  86. function init() {
  87. container = document.createElement('div');
  88. document.body.appendChild(container);
  89. camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
  90. camera.position.z = 900;
  91. scene = new THREE.Scene();
  92. // LIGHTS
  93. ambientLight = new THREE.AmbientLight( 0x050505 );
  94. scene.addLight( ambientLight );
  95. pointLight = new THREE.PointLight( 0x999999 );
  96. pointLight.position.z = 10000;
  97. scene.addLight( pointLight );
  98. directionalLight = new THREE.DirectionalLight( 0xbbbbbb );
  99. directionalLight.position.x = 0;
  100. directionalLight.position.y = 0;
  101. directionalLight.position.z = 1;
  102. directionalLight.position.normalize();
  103. scene.addLight( directionalLight );
  104. // light representation
  105. var sphere = new Sphere( 100, 16, 8 );
  106. lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color:0xffaa00 } ) );
  107. lightMesh.position = pointLight.position;
  108. lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05;
  109. scene.addObject(lightMesh);
  110. // material parameters
  111. var ambient = 0x020202, diffuse = 0x666666, specular = 0x444444, shininess = 2;
  112. var fragment_shader = ShaderUtils.lib[ "normal" ].fragment_shader;
  113. var vertex_shader = ShaderUtils.lib[ "normal" ].vertex_shader;
  114. var uniforms = ShaderUtils.lib[ "normal" ].uniforms;
  115. uniforms[ "tNormal" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
  116. uniforms[ "tDiffuse" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
  117. uniforms[ "enableAO" ].value = false;
  118. uniforms[ "enableDiffuse" ].value = true;
  119. uniforms[ "uPointLightPos" ].value = pointLight.position;
  120. uniforms[ "uPointLightColor" ].value = pointLight.color;
  121. uniforms[ "uDirLightPos" ].value = directionalLight.position;
  122. uniforms[ "uDirLightColor" ].value = directionalLight.color;
  123. uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
  124. uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
  125. uniforms[ "uSpecularColor" ].value.setHex( specular );
  126. uniforms[ "uAmbientColor" ].value.setHex( ambient );
  127. uniforms[ "uShininess" ].value = shininess;
  128. var material = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader,
  129. vertex_shader: vertex_shader,
  130. uniforms: uniforms
  131. } );
  132. //var material = new THREE.MeshLambertMaterial( { map: ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
  133. //var material = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess, map: ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
  134. loader = new THREE.Loader( true );
  135. document.body.appendChild( loader.statusDomElement );
  136. loader.loadAscii( "obj/leeperrysmith/LeePerrySmith.js", function( geometry ) { createScene( geometry, 100, material ) }, "obj/leeperrysmith" );
  137. webglRenderer = new THREE.WebGLRenderer( { scene: scene } );
  138. webglRenderer.setSize( window.innerWidth, window.innerHeight );
  139. container.appendChild( webglRenderer.domElement );
  140. if ( statsEnabled ) {
  141. stats = new Stats();
  142. stats.domElement.style.position = 'absolute';
  143. stats.domElement.style.top = '0px';
  144. stats.domElement.style.zIndex = 100;
  145. container.appendChild( stats.domElement );
  146. }
  147. }
  148. function createScene( geometry, scale, material ) {
  149. geometry.computeTangents();
  150. mesh1 = SceneUtils.addMesh( scene, geometry, scale, 0, - 50, 0, 0, 0, 0, material );
  151. loader.statusDomElement.style.display = "none";
  152. }
  153. function onDocumentMouseMove(event) {
  154. mouseX = ( event.clientX - windowHalfX ) * 10;
  155. mouseY = ( event.clientY - windowHalfY ) * 10;
  156. }
  157. function loop() {
  158. var ry = mouseX * 0.0003, rx = mouseY * 0.0003;
  159. if( mesh1 ) {
  160. mesh1.rotation.y = ry;
  161. mesh1.rotation.x = rx;
  162. }
  163. lightMesh.position.x = 500 * Math.cos( r );
  164. lightMesh.position.z = 500 * Math.sin( r );
  165. r += 0.01;
  166. webglRenderer.render( scene, camera );
  167. if ( statsEnabled ) stats.update();
  168. }
  169. function log( text ) {
  170. var e = document.getElementById("log");
  171. e.innerHTML = text + "<br/>" + e.innerHTML;
  172. }
  173. function is_browser_compatible() {
  174. // WebGL support
  175. try { var test = new Float32Array(1); } catch(e) { return false; }
  176. // Web workers
  177. return !!window.Worker;
  178. }
  179. </script>
  180. </body>
  181. </html>
粤ICP备19079148号