123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgpu - ies spotlight</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - ies spotlight<br />
- </div>
- <script type="importmap">
- {
- "imports": {
- "three": "../build/three.webgpu.js",
- "three/tsl": "../build/three.webgpu.js",
- "three/addons/": "./jsm/"
- }
- }
- </script>
- <script type="module">
- import * as THREE from 'three';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { IESLoader } from 'three/addons/loaders/IESLoader.js';
- let renderer, scene, camera;
- let lights;
- async function init() {
- const iesLoader = new IESLoader().setPath( './ies/' );
- //iesLoader.type = THREE.UnsignedByteType; // LDR
- const [ iesTexture1, iesTexture2, iesTexture3, iesTexture4 ] = await Promise.all( [
- iesLoader.loadAsync( '007cfb11e343e2f42e3b476be4ab684e.ies' ),
- iesLoader.loadAsync( '06b4cfdc8805709e767b5e2e904be8ad.ies' ),
- iesLoader.loadAsync( '02a7562c650498ebb301153dbbf59207.ies' ),
- iesLoader.loadAsync( '1a936937a49c63374e6d4fbed9252b29.ies' )
- ] );
- //
- scene = new THREE.Scene();
- //
- const spotLight = new THREE.IESSpotLight( 0xff0000, 500 );
- spotLight.position.set( 6.5, 1.5, 6.5 );
- spotLight.angle = Math.PI / 8;
- spotLight.penumbra = 0.7;
- spotLight.distance = 20;
- spotLight.iesMap = iesTexture1;
- scene.add( spotLight );
- //
- const spotLight2 = new THREE.IESSpotLight( 0x00ff00, 500 );
- spotLight2.position.set( 6.5, 1.5, - 6.5 );
- spotLight2.angle = Math.PI / 8;
- spotLight2.penumbra = 0.7;
- spotLight2.distance = 20;
- spotLight2.iesMap = iesTexture2;
- scene.add( spotLight2 );
- //
- const spotLight3 = new THREE.IESSpotLight( 0x0000ff, 500 );
- spotLight3.position.set( - 6.5, 1.5, - 6.5 );
- spotLight3.angle = Math.PI / 8;
- spotLight3.penumbra = 0.7;
- spotLight3.distance = 20;
- spotLight3.iesMap = iesTexture3;
- scene.add( spotLight3 );
- //
- const spotLight4 = new THREE.IESSpotLight( 0xffffff, 500 );
- spotLight4.position.set( - 6.5, 1.5, 6.5 );
- spotLight4.angle = Math.PI / 8;
- spotLight4.penumbra = 0.7;
- spotLight4.distance = 20;
- spotLight4.iesMap = iesTexture4;
- scene.add( spotLight4 );
- //
- lights = [ spotLight, spotLight2, spotLight3, spotLight4 ];
- //
- const material = new THREE.MeshPhongMaterial( { color: 0x808080/*, dithering: true*/ } );
- const geometry = new THREE.PlaneGeometry( 200, 200 );
- const mesh = new THREE.Mesh( geometry, material );
- mesh.rotation.x = - Math.PI * 0.5;
- scene.add( mesh );
- //
- renderer = new THREE.WebGPURenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.setAnimationLoop( render );
- document.body.appendChild( renderer.domElement );
- camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, .1, 100 );
- camera.position.set( 16, 4, 1 );
- const controls = new OrbitControls( camera, renderer.domElement );
- controls.minDistance = 2;
- controls.maxDistance = 50;
- controls.enablePan = false;
- //
- window.addEventListener( 'resize', onWindowResize );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function render( time ) {
- time = ( time / 1000 ) * 2.0;
- for ( let i = 0; i < lights.length; i ++ ) {
- lights[ i ].position.y = Math.sin( time + i ) + 0.97;
- }
- renderer.render( scene, camera );
- }
- init();
- </script>
- </body>
- </html>
|