materials_normalmap2.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 = 0x888888, specular = 0x080810, shininess = 2;
  105. var shader = ShaderUtils.lib[ "normal" ];
  106. var uniforms = Uniforms.clone( shader.uniforms );
  107. uniforms[ "tNormal" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
  108. uniforms[ "uNormalScale" ].value = - 0.75;
  109. uniforms[ "tDiffuse" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
  110. uniforms[ "enableAO" ].value = false;
  111. uniforms[ "enableDiffuse" ].value = true;
  112. uniforms[ "uPointLightPos" ].value = pointLight.position;
  113. uniforms[ "uPointLightColor" ].value = pointLight.color;
  114. uniforms[ "uDirLightPos" ].value = directionalLight.position;
  115. uniforms[ "uDirLightColor" ].value = directionalLight.color;
  116. uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
  117. uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
  118. uniforms[ "uSpecularColor" ].value.setHex( specular );
  119. uniforms[ "uAmbientColor" ].value.setHex( ambient );
  120. uniforms[ "uShininess" ].value = shininess;
  121. var parameters = { fragment_shader: shader.fragment_shader, vertex_shader: shader.vertex_shader, uniforms: uniforms };
  122. var material = new THREE.MeshShaderMaterial( parameters );
  123. loader = new THREE.Loader( true );
  124. document.body.appendChild( loader.statusDomElement );
  125. loader.loadAscii( "obj/leeperrysmith/LeePerrySmith.js", function( geometry ) { createScene( geometry, 100, material ) }, "obj/leeperrysmith" );
  126. webglRenderer = new THREE.WebGLRenderer();
  127. webglRenderer.setSize( window.innerWidth, window.innerHeight );
  128. container.appendChild( webglRenderer.domElement );
  129. if ( statsEnabled ) {
  130. stats = new Stats();
  131. stats.domElement.style.position = 'absolute';
  132. stats.domElement.style.top = '0px';
  133. stats.domElement.style.zIndex = 100;
  134. container.appendChild( stats.domElement );
  135. }
  136. }
  137. function createScene( geometry, scale, material ) {
  138. geometry.computeTangents();
  139. mesh1 = SceneUtils.addMesh( scene, geometry, scale, 0, - 50, 0, 0, 0, 0, material );
  140. loader.statusDomElement.style.display = "none";
  141. }
  142. function onDocumentMouseMove(event) {
  143. mouseX = ( event.clientX - windowHalfX ) * 10;
  144. mouseY = ( event.clientY - windowHalfY ) * 10;
  145. }
  146. function loop() {
  147. var ry = mouseX * 0.0003, rx = mouseY * 0.0003;
  148. if( mesh1 ) {
  149. mesh1.rotation.y = ry;
  150. mesh1.rotation.x = rx;
  151. }
  152. webglRenderer.render( scene, camera );
  153. if ( statsEnabled ) stats.update();
  154. }
  155. function log( text ) {
  156. var e = document.getElementById("log");
  157. e.innerHTML = text + "<br/>" + e.innerHTML;
  158. }
  159. function is_browser_compatible() {
  160. // WebGL support
  161. try { var test = new Float32Array(1); } catch(e) { return false; }
  162. // Web workers
  163. return !!window.Worker;
  164. }
  165. </script>
  166. </body>
  167. </html>