Skip to content

Commit

Permalink
Examples: Improved webgpu_lights_custom.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed May 31, 2024
1 parent 7c1e61a commit f0f0e19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Binary file modified examples/screenshots/webgpu_lights_custom.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions examples/webgpu_lights_custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@
}

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.z = 2;
camera.position.z = 1.5;

scene = new THREE.Scene();
scene.background = new THREE.Color( 0x222222 );

// lights

const sphereGeometry = new THREE.SphereGeometry( 0.02, 16, 8 );
const sphereGeometry = new THREE.SphereGeometry( 0.01, 16, 8 );

const addLight = ( hexColor, intensity = 2, distance = 1 ) => {
const addLight = ( hexColor ) => {

const material = new MeshStandardNodeMaterial();
material.colorNode = color( hexColor );
material.lightsNode = lights(); // ignore scene lights

const mesh = new THREE.Mesh( sphereGeometry, material );

const light = new THREE.PointLight( hexColor, intensity, distance );
const light = new THREE.PointLight( hexColor, 0.1, 0.8 );
light.add( mesh );

scene.add( light );
Expand All @@ -98,7 +98,7 @@

const points = [];

for ( let i = 0; i < 3000; i ++ ) {
for ( let i = 0; i < 1_000_000; i ++ ) {

const point = new THREE.Vector3().random().subScalar( 0.5 ).multiplyScalar( 2 );
points.push( point );
Expand Down Expand Up @@ -126,7 +126,7 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.toneMappingNode = toneMapping( THREE.LinearToneMapping, 1 );
renderer.toneMappingNode = toneMapping( THREE.NeutralToneMapping, 1 );
document.body.appendChild( renderer.domElement );

// controls
Expand Down Expand Up @@ -167,6 +167,8 @@
light3.position.y = Math.cos( time * 0.3 ) * scale;
light3.position.z = Math.sin( time * 0.5 ) * scale;

scene.rotation.y = time * 0.6;

renderer.render( scene, camera );

}
Expand Down

0 comments on commit f0f0e19

Please sign in to comment.