1
0

webgpu_lights_ies_spotlight.html 4.0 KB

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