webgl_materials_sheen.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <html lang="en">
  2. <head>
  3. <title>Sheen demo (material property)</title>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  6. <link type="text/css" rel="stylesheet" href="main.css">
  7. <style>
  8. body {
  9. color: #333;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <div id="info">Sheen demo by <a href="https://github.com/DanielSturk">DanielSturk</a></div>
  15. <div id="container"></div>
  16. <script src="js/libs/ammo.js"></script>
  17. <script type="module">
  18. import * as THREE from '../build/three.module.js';
  19. import Stats from './jsm/libs/stats.module.js';
  20. import { GUI } from './jsm/libs/dat.gui.module.js';
  21. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  22. import { FBXLoader } from './jsm/loaders/FBXLoader.js';
  23. // Graphics variables
  24. var camera, controls, scene, renderer, mesh, stats;
  25. var params = {
  26. sheen: .5,
  27. hue: 265,
  28. roughness: .9
  29. };
  30. // model
  31. new FBXLoader().load( 'models/fbx/cloth.fbx', function ( loadedModel ) {
  32. mesh = loadedModel.children[0];
  33. init();
  34. } );
  35. function init( ) {
  36. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.2, 2000 );
  37. scene = new THREE.Scene();
  38. scene.background = new THREE.Color( 0xbfd1e5 );
  39. mesh.material = new THREE.MeshPhysicalMaterial();
  40. mesh.scale.multiplyScalar( .5 );
  41. scene.add( mesh );
  42. camera.position.set( - 12, 7, 4 );
  43. var container = document.getElementById( 'container' );
  44. renderer = new THREE.WebGLRenderer();
  45. renderer.setPixelRatio( window.devicePixelRatio );
  46. renderer.setSize( window.innerWidth, window.innerHeight );
  47. renderer.shadowMap.enabled = true;
  48. container.appendChild( renderer.domElement );
  49. controls = new OrbitControls( camera, renderer.domElement );
  50. controls.target.set( 0, 2, 0 );
  51. controls.update();
  52. var ambientLight = new THREE.AmbientLight( 0x404040 );
  53. scene.add( ambientLight );
  54. var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
  55. light.position.set( - 7, 30, 15 );
  56. light.castShadow = true;
  57. var d = 10;
  58. light.shadow.camera.left = - d;
  59. light.shadow.camera.right = d;
  60. light.shadow.camera.top = d;
  61. light.shadow.camera.bottom = - d;
  62. light.shadow.camera.near = 2;
  63. light.shadow.camera.far = 50;
  64. light.shadow.mapSize.x = 1024;
  65. light.shadow.mapSize.y = 1024;
  66. light.shadow.bias = - 0.003;
  67. scene.add( light );
  68. stats = new Stats();
  69. stats.domElement.style.position = 'absolute';
  70. stats.domElement.style.top = '0px';
  71. container.appendChild( stats.dom );
  72. window.addEventListener( 'resize', onWindowResize, false );
  73. var gui = new GUI();
  74. gui.add( params, 'sheen', 0, 1 );
  75. gui.add( params, 'hue', 0, 360 );
  76. gui.add( params, 'roughness', 0, 1 );
  77. gui.open();
  78. animate();
  79. }
  80. function onWindowResize() {
  81. camera.aspect = window.innerWidth / window.innerHeight;
  82. camera.updateProjectionMatrix();
  83. renderer.setSize( window.innerWidth, window.innerHeight );
  84. }
  85. function animate() {
  86. requestAnimationFrame( animate );
  87. render();
  88. stats.update();
  89. }
  90. function render() {
  91. mesh.material.sheen = params.sheen;
  92. mesh.material.color = new THREE.Color().setHSL(params.hue / 360, 1, .5);
  93. mesh.material.roughness = params.roughness;
  94. renderer.render( scene, camera );
  95. }
  96. </script>
  97. </body>
  98. </html>