webgpu_lights_ies_spotlight.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - ies spotlight</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. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - ies spotlight<br />
  12. </div>
  13. <script type="importmap">
  14. {
  15. "imports": {
  16. "three": "../build/three.webgpu.js",
  17. "three/tsl": "../build/three.webgpu.js",
  18. "three/addons/": "./jsm/"
  19. }
  20. }
  21. </script>
  22. <script type="module">
  23. import * as THREE from 'three';
  24. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  25. import { IESLoader } from 'three/addons/loaders/IESLoader.js';
  26. let renderer, scene, camera;
  27. let lights;
  28. async function init() {
  29. const iesLoader = new IESLoader().setPath( './ies/' );
  30. //iesLoader.type = THREE.UnsignedByteType; // LDR
  31. const [ iesTexture1, iesTexture2, iesTexture3, iesTexture4 ] = await Promise.all( [
  32. iesLoader.loadAsync( '007cfb11e343e2f42e3b476be4ab684e.ies' ),
  33. iesLoader.loadAsync( '06b4cfdc8805709e767b5e2e904be8ad.ies' ),
  34. iesLoader.loadAsync( '02a7562c650498ebb301153dbbf59207.ies' ),
  35. iesLoader.loadAsync( '1a936937a49c63374e6d4fbed9252b29.ies' )
  36. ] );
  37. //
  38. scene = new THREE.Scene();
  39. //
  40. const spotLight = new THREE.IESSpotLight( 0xff0000, 500 );
  41. spotLight.position.set( 6.5, 1.5, 6.5 );
  42. spotLight.angle = Math.PI / 8;
  43. spotLight.penumbra = 0.7;
  44. spotLight.distance = 20;
  45. spotLight.iesMap = iesTexture1;
  46. scene.add( spotLight );
  47. //
  48. const spotLight2 = new THREE.IESSpotLight( 0x00ff00, 500 );
  49. spotLight2.position.set( 6.5, 1.5, - 6.5 );
  50. spotLight2.angle = Math.PI / 8;
  51. spotLight2.penumbra = 0.7;
  52. spotLight2.distance = 20;
  53. spotLight2.iesMap = iesTexture2;
  54. scene.add( spotLight2 );
  55. //
  56. const spotLight3 = new THREE.IESSpotLight( 0x0000ff, 500 );
  57. spotLight3.position.set( - 6.5, 1.5, - 6.5 );
  58. spotLight3.angle = Math.PI / 8;
  59. spotLight3.penumbra = 0.7;
  60. spotLight3.distance = 20;
  61. spotLight3.iesMap = iesTexture3;
  62. scene.add( spotLight3 );
  63. //
  64. const spotLight4 = new THREE.IESSpotLight( 0xffffff, 500 );
  65. spotLight4.position.set( - 6.5, 1.5, 6.5 );
  66. spotLight4.angle = Math.PI / 8;
  67. spotLight4.penumbra = 0.7;
  68. spotLight4.distance = 20;
  69. spotLight4.iesMap = iesTexture4;
  70. scene.add( spotLight4 );
  71. //
  72. lights = [ spotLight, spotLight2, spotLight3, spotLight4 ];
  73. //
  74. const material = new THREE.MeshPhongMaterial( { color: 0x808080/*, dithering: true*/ } );
  75. const geometry = new THREE.PlaneGeometry( 200, 200 );
  76. const mesh = new THREE.Mesh( geometry, material );
  77. mesh.rotation.x = - Math.PI * 0.5;
  78. scene.add( mesh );
  79. //
  80. renderer = new THREE.WebGPURenderer( { antialias: true } );
  81. renderer.setPixelRatio( window.devicePixelRatio );
  82. renderer.setSize( window.innerWidth, window.innerHeight );
  83. renderer.setAnimationLoop( render );
  84. document.body.appendChild( renderer.domElement );
  85. camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, .1, 100 );
  86. camera.position.set( 16, 4, 1 );
  87. const controls = new OrbitControls( camera, renderer.domElement );
  88. controls.minDistance = 2;
  89. controls.maxDistance = 50;
  90. controls.enablePan = false;
  91. //
  92. window.addEventListener( 'resize', onWindowResize );
  93. }
  94. function onWindowResize() {
  95. camera.aspect = window.innerWidth / window.innerHeight;
  96. camera.updateProjectionMatrix();
  97. renderer.setSize( window.innerWidth, window.innerHeight );
  98. }
  99. function render( time ) {
  100. time = ( time / 1000 ) * 2.0;
  101. for ( let i = 0; i < lights.length; i ++ ) {
  102. lights[ i ].position.y = Math.sin( time + i ) + 0.97;
  103. }
  104. renderer.render( scene, camera );
  105. }
  106. init();
  107. </script>
  108. </body>
  109. </html>