<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.stephanschlegel.de/index.php?action=history&amp;feed=atom&amp;title=Three.js_-_Lights</id>
	<title>Three.js - Lights - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stephanschlegel.de/index.php?action=history&amp;feed=atom&amp;title=Three.js_-_Lights"/>
	<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Lights&amp;action=history"/>
	<updated>2026-05-06T15:22:04Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Wikizone</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Lights&amp;diff=25674&amp;oldid=prev</id>
		<title>Steff: Die Seite wurde neu angelegt: „ ThreeJS - Snippets  zentriert === AmbientLight === The AmbientLight applies &#039;&#039;&#039;omnidirectional lighting&#039;&#039;&#039; on…“</title>
		<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Lights&amp;diff=25674&amp;oldid=prev"/>
		<updated>2021-12-30T20:06:13Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „ &lt;a href=&quot;/index.php?title=ThreeJS_-_Snippets&quot; title=&quot;ThreeJS - Snippets&quot;&gt;ThreeJS - Snippets&lt;/a&gt;  &lt;a href=&quot;/index.php?title=Datei:Three.js-3D-Lighting.jpg&quot; title=&quot;Datei:Three.js-3D-Lighting.jpg&quot;&gt;rahmenlos|zentriert&lt;/a&gt; === AmbientLight === The AmbientLight applies &amp;#039;&amp;#039;&amp;#039;omnidirectional lighting&amp;#039;&amp;#039;&amp;#039; on…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt; [[ThreeJS - Snippets]]&lt;br /&gt;
&lt;br /&gt;
[[Datei:Three.js-3D-Lighting.jpg|rahmenlos|zentriert]]&lt;br /&gt;
=== AmbientLight ===&lt;br /&gt;
The AmbientLight applies &amp;#039;&amp;#039;&amp;#039;omnidirectional lighting&amp;#039;&amp;#039;&amp;#039; on all geometries of the scene. Therefore no shadows thrown.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// AmbientLight - color, intensity&lt;br /&gt;
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5)&lt;br /&gt;
scene.add(ambientLight)&lt;br /&gt;
gui.add(ambientLight,&amp;#039;intensity&amp;#039;,0,1).name(&amp;#039;AmbientLight&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DirectionalLight ===&lt;br /&gt;
The DirectionalLight will have a &amp;#039;&amp;#039;&amp;#039;sun-like effect&amp;#039;&amp;#039;&amp;#039; as if the sun rays were traveling in parallel.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// DirectionalLight - color, intensity&lt;br /&gt;
const directionalLight = new THREE.DirectionalLight(0x00fffc, 0.3)&lt;br /&gt;
directionalLight.position.set(1, 0.25, 0)&lt;br /&gt;
scene.add(directionalLight)&lt;br /&gt;
gui.add(directionalLight,&amp;#039;intensity&amp;#039;,0,1).name(&amp;#039;DirectionalLight&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HemisphereLight ===&lt;br /&gt;
The HemisphereLight is similar to the AmbientLight but with a &amp;#039;&amp;#039;&amp;#039;different color from the sky than the color coming from the ground&amp;#039;&amp;#039;&amp;#039;. Faces facing the sky will be lit by one color while another color will lit faces facing the ground.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// HemisphereLight - color top, color bottom, intensity&lt;br /&gt;
const hemisphereLight = new THREE.HemisphereLight(0xff0000, 0x0000ff, 0.3)&lt;br /&gt;
scene.add(hemisphereLight)&lt;br /&gt;
gui.add(hemisphereLight,&amp;#039;intensity&amp;#039;,0,1).name(&amp;#039;HemisphereLight&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PointLight ===&lt;br /&gt;
The PointLight is almost &amp;#039;&amp;#039;&amp;#039;like a lighter&amp;#039;&amp;#039;&amp;#039;. The light source is infinitely small, and the light spreads uniformly in every direction. You can control that &amp;#039;&amp;#039;&amp;#039;fade distance and how fast it is fading&amp;#039;&amp;#039;&amp;#039; using the &amp;#039;&amp;#039;&amp;#039;distance&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;decay&amp;#039;&amp;#039;&amp;#039; properties. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// PointLight - color, intensity, distance, decay&lt;br /&gt;
const pointLight = new THREE.PointLight(0xff9000, 0.5, 10, 2)&lt;br /&gt;
pointLight.position.set(1, - 0.5, 1)&lt;br /&gt;
scene.add(pointLight)&lt;br /&gt;
gui.add(pointLight,&amp;#039;intensity&amp;#039;,0,1).name(&amp;#039;PointLight&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RectAreaLight ===&lt;br /&gt;
The RectAreaLight works like the &amp;#039;&amp;#039;&amp;#039;big rectangle lights&amp;#039;&amp;#039;&amp;#039; you can see on the photoshoot set. It&amp;#039;s a &amp;#039;&amp;#039;&amp;#039;mix between a directional light and a diffuse light&amp;#039;&amp;#039;&amp;#039;. You can then move the light and rotate it. To ease the rotation, you can use the lookAt(...) method &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// RectAreaLight - color, intensity, width, height&lt;br /&gt;
const rectAreaLight = new THREE.RectAreaLight(0x4e00ff, 2, 1, 1)&lt;br /&gt;
rectAreaLight.position.set(- 1.5, 0, 1.5)&lt;br /&gt;
rectAreaLight.lookAt(new THREE.Vector3())&lt;br /&gt;
scene.add(rectAreaLight)&lt;br /&gt;
gui.add(rectAreaLight,&amp;#039;intensity&amp;#039;,0,5).name(&amp;#039;RectAreaLight&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SpotLight ===&lt;br /&gt;
The SpotLight works &amp;#039;&amp;#039;&amp;#039;like a flashlight&amp;#039;&amp;#039;&amp;#039;. It&amp;#039;s a cone of light starting at a point and oriented in a direction.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Rotating&amp;#039;&amp;#039;&amp;#039; our SpotLight is a little harder. The instance has a &amp;#039;&amp;#039;&amp;#039;property named target, which is an Object3D&amp;#039;&amp;#039;&amp;#039;. The SpotLight is always looking at that target object. Simply create the target and do not forget to add it to the scene, and it should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// SpotLight - color, intensity, distance, angle (of beam), penumbra (contour diffusion),decay&lt;br /&gt;
const spotLight = new THREE.SpotLight(0x78ff00, 0.5, 10, Math.PI * 0.1, 0.25, 1)&lt;br /&gt;
spotLight.position.set(0, 2, 3)&lt;br /&gt;
spotLight.target.position.x = - 0.75 &lt;br /&gt;
scene.add(spotLight.target)&lt;br /&gt;
scene.add(spotLight)&lt;br /&gt;
gui.add(spotLight,&amp;#039;intensity&amp;#039;,0,1).name(&amp;#039;SpotLight&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Light Helpers ===&lt;br /&gt;
Positioning and orienting the lights is hard. To assist us, we can use helpers. Only the following helpers are supported:&lt;br /&gt;
* HemisphereLightHelper&lt;br /&gt;
* DirectionalLightHelper&lt;br /&gt;
* PointLightHelper&lt;br /&gt;
* RectAreaLightHelper&lt;br /&gt;
* SpotLightHelper&lt;br /&gt;
&lt;br /&gt;
To use them, simply instantiate those classes. Use the corresponding light as a parameter, and add them to the scene. The second parameter enables you to change the helper&amp;#039;s size:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
const hemisphereLightHelper = new THREE.HemisphereLightHelper(hemisphereLight, 0.2)&lt;br /&gt;
scene.add(hemisphereLightHelper)&lt;br /&gt;
&lt;br /&gt;
const directionalLightHelper = new THREE.DirectionalLightHelper(directionalLight, 0.2)&lt;br /&gt;
scene.add(directionalLightHelper)&lt;br /&gt;
&lt;br /&gt;
const pointLightHelper = new THREE.PointLightHelper(pointLight, 0.2)&lt;br /&gt;
scene.add(pointLightHelper)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
For the SpotLightHelper, there is no size parameter. Also, after moving the target, you need to call the update(...) method but on the next frame:&lt;br /&gt;
&lt;br /&gt;
For the &amp;#039;&amp;#039;&amp;#039;SpotLightHelper&amp;#039;&amp;#039;&amp;#039;, there is &amp;#039;&amp;#039;&amp;#039;no size&amp;#039;&amp;#039;&amp;#039; parameter. Also, after &amp;#039;&amp;#039;&amp;#039;moving the target&amp;#039;&amp;#039;&amp;#039;, you need to call the update(...) method but on the next frame:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
const spotLightHelper = new THREE.SpotLightHelper(spotLight)&lt;br /&gt;
scene.add(spotLightHelper)&lt;br /&gt;
window.requestAnimationFrame(() =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    spotLightHelper.update()&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;RectAreaLightHelper&amp;#039;&amp;#039;&amp;#039; is even harder to use. Right now, the class isn&amp;#039;t part of the THREE variable. &amp;#039;&amp;#039;&amp;#039;You must import it&amp;#039;&amp;#039;&amp;#039; from the examples dependencies as we did with OrbitControls:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
import { RectAreaLightHelper } from &amp;#039;three/examples/jsm/helpers/RectAreaLightHelper.js&amp;#039;&lt;br /&gt;
//...&lt;br /&gt;
const rectAreaLightHelper = new RectAreaLightHelper(rectAreaLight)&lt;br /&gt;
scene.add(rectAreaLightHelper)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Performance ===&lt;br /&gt;
Lights can cost a lot when it comes to performance.&lt;br /&gt;
&lt;br /&gt;
Try to add as few lights as possible and try to use the lights that cost less.&lt;br /&gt;
&lt;br /&gt;
Minimal cost:&lt;br /&gt;
* AmbientLight&lt;br /&gt;
* HemisphereLight&lt;br /&gt;
&lt;br /&gt;
Moderate cost:&lt;br /&gt;
* DirectionalLight&lt;br /&gt;
* PointLight&lt;br /&gt;
&lt;br /&gt;
High cost:&lt;br /&gt;
* SpotLight&lt;br /&gt;
* RectAreaLight&lt;br /&gt;
&lt;br /&gt;
=== Baking Light ===&lt;br /&gt;
A good technique for lighting is called baking. The idea is that you bake the light into the texture. This can be done in a 3D software. Unfortunately, you won&amp;#039;t be able to move the lights, because there are none and you&amp;#039;ll probably need a lot of textures.&lt;/div&gt;</summary>
		<author><name>Steff</name></author>
	</entry>
</feed>