PHP 7.4.33
Preview: LightProbeHelperGPU.js Size: 1.27 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/three/examples/jsm/helpers/LightProbeHelperGPU.js
import {
	Mesh,
	NodeMaterial,
	SphereGeometry
} from 'three';
import { float, Fn, getShIrradianceAt, normalWorld, uniformArray, uniform, vec4 } from 'three/tsl';

class LightProbeHelper extends Mesh {

	constructor( lightProbe, size = 1 ) {

		const sh = uniformArray( lightProbe.sh.coefficients );
		const intensity = uniform( lightProbe.intensity );

		const RECIPROCAL_PI = float( 1 / Math.PI );

		const fragmentNode = Fn( () => {

			const irradiance = getShIrradianceAt( normalWorld, sh );

			const outgoingLight = RECIPROCAL_PI.mul( irradiance ).mul( intensity );

			return vec4( outgoingLight, 1.0 );

		} )();

		const material = new NodeMaterial();
		material.fragmentNode = fragmentNode;

		const geometry = new SphereGeometry( 1, 32, 16 );

		super( geometry, material );

		this.lightProbe = lightProbe;
		this.size = size;
		this.type = 'LightProbeHelper';

		this._intensity = intensity;
		this._sh = sh;

		this.onBeforeRender();

	}

	dispose() {

		this.geometry.dispose();
		this.material.dispose();

	}

	onBeforeRender() {

		this.position.copy( this.lightProbe.position );

		this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );

		this._intensity.value = this.lightProbe.intensity;
		this._sh.array = this.lightProbe.sh.coefficients;

	}

}

export { LightProbeHelper };

Directory Contents

Dirs: 0 × Files: 10
Name Size Perms Modified Actions
2.64 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.27 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.93 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
2.65 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.00 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.33 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.63 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.81 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.62 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
8.41 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).