materials_normalmap2.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  83. init();
  84. setInterval( loop, 1000 / 60 );
  85. function init() {
  86. container = document.createElement('div');
  87. document.body.appendChild(container);
  88. camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
  89. camera.position.z = 900;
  90. scene = new THREE.Scene();
  91. // LIGHTS
  92. ambientLight = new THREE.AmbientLight( 0x444444 );
  93. scene.addLight( ambientLight );
  94. pointLight = new THREE.PointLight( 0xffffff );
  95. pointLight.position.z = 600;
  96. scene.addLight( pointLight );
  97. directionalLight = new THREE.DirectionalLight( 0xffffff );
  98. directionalLight.position.x = 1;
  99. directionalLight.position.y = 1;
  100. directionalLight.position.z = - 1;
  101. directionalLight.position.normalize();
  102. scene.addLight( directionalLight );
  103. // material parameters
  104. var ambient = 0x444444, diffuse = 0x555555, specular = 0x181820, shininess = 2;
  105. var fragment_shader = ShaderUtils.lib[ "normal" ].fragment_shader;
  106. var vertex_shader = ShaderUtils.lib[ "normal" ].vertex_shader;
  107. var uniforms = ShaderUtils.lib[ "normal" ].uniforms;
  108. uniforms[ "tNormal" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
  109. uniforms[ "uNormalScale" ].value = - 0.75;
  110. uniforms[ "tDiffuse" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
  111. uniforms[ "enableAO" ].value = false;
  112. uniforms[ "enableDiffuse" ].value = true;
  113. uniforms[ "uPointLightPos" ].value = pointLight.position;
  114. uniforms[ "uPointLightColor" ].value = pointLight.color;
  115. uniforms[ "uDirLightPos" ].value = directionalLight.position;
  116. uniforms[ "uDirLightColor" ].value = directionalLight.color;
  117. uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
  118. uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
  119. uniforms[ "uSpecularColor" ].value.setHex( specular );
  120. uniforms[ "uAmbientColor" ].value.setHex( ambient );
  121. uniforms[ "uShininess" ].value = shininess;
  122. var material = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader,
  123. vertex_shader: vertex_shader,
  124. uniforms: uniforms
  125. } );
  126. loader = new THREE.Loader( true );
  127. document.body.appendChild( loader.statusDomElement );
  128. loader.loadAscii( "obj/leeperrysmith/LeePerrySmith.js", function( geometry ) { createScene( geometry, 100, material ) }, "obj/leeperrysmith" );
  129. webglRenderer = new THREE.WebGLRenderer( { scene: scene } );
  130. webglRenderer.setSize( window.innerWidth, window.innerHeight );
  131. container.appendChild( webglRenderer.domElement );
  132. if ( statsEnabled ) {
  133. stats = new Stats();
  134. stats.domElement.style.position = 'absolute';
  135. stats.domElement.style.top = '0px';
  136. stats.domElement.style.zIndex = 100;
  137. container.appendChild( stats.domElement );
  138. }
  139. }
  140. function createScene( geometry, scale, material ) {
  141. geometry.computeTangents();
  142. mesh1 = SceneUtils.addMesh( scene, geometry, scale, 0, - 50, 0, 0, 0, 0, material );
  143. loader.statusDomElement.style.display = "none";
  144. }
  145. function onDocumentMouseMove(event) {
  146. mouseX = ( event.clientX - windowHalfX ) * 10;
  147. mouseY = ( event.clientY - windowHalfY ) * 10;
  148. }
  149. function loop() {
  150. var ry = mouseX * 0.0003, rx = mouseY * 0.0003;
  151. if( mesh1 ) {
  152. mesh1.rotation.y = ry;
  153. mesh1.rotation.x = rx;
  154. }
  155. webglRenderer.render( scene, camera );
  156. if ( statsEnabled ) stats.update();
  157. }
  158. function log( text ) {
  159. var e = document.getElementById("log");
  160. e.innerHTML = text + "<br/>" + e.innerHTML;
  161. }
  162. function is_browser_compatible() {
  163. // WebGL support
  164. try { var test = new Float32Array(1); } catch(e) { return false; }
  165. // Web workers
  166. return !!window.Worker;
  167. }
  168. </script>
  169. </body>
  170. </html>
粤ICP备19079148号