How to use the DirectionalLight function from three

Find comprehensive JavaScript three.DirectionalLight code examples handpicked from public code repositorys.

590
591
592
593
594
595
596
597
598
// The two back lights, one on the left of the object as seen from the observer and one on the right, fill on
// the high-contrast areas behind the object. To enforce the relationship between the different lights, the
// intensity of the fill, back and headlights are set as a ratio to the key light brightness. Thus, the
// brightness of all the lights in the scene can be changed by changing the key light intensity.

this.keyLight = new THREE.DirectionalLight(0xffffff); // key
this.headLight = new THREE.DirectionalLight(0xffffff); // head
this.fillLight = new THREE.DirectionalLight(0xffffff); // fill
this.backLight = new THREE.DirectionalLight(0xffffff); // back
fork icon116
star icon804
watch icon0

+ 3 other calls in file

52
53
54
55
56
57
58
59
60
this.scene.fog = new THREE.FogExp2(background);

var directionalLight1 = new THREE.DirectionalLight(0xFFFFFF, 1.2);
directionalLight1.position.set(0.2, 0.2, -1).normalize();

var directionalLight2 = new THREE.DirectionalLight(0xFFFFFF, 1.2);
directionalLight2.position.set(0.2, 0.2, 1).normalize();

var ambientLight = new THREE.AmbientLight(0x202020);
fork icon17
star icon78
watch icon8

+ 41 other calls in file

14
15
16
17
18
19
20
21
22
    
// Basic Lambert white
var lambertWhite = new THREE.MeshLambertMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide });

// Set light
var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
directionalLight.color.setHSL(0.1, 1, 0.95);
directionalLight.position.set(1, 3, 2);
directionalLight.position.multiplyScalar(10);
fork icon31
star icon0
watch icon2

+ 15 other calls in file

99
100
101
102
103
104
105
106
107
108
createLevel();

// lighting
hemisphereLight = new THREE.HemisphereLight('#004570', someColors['pink'], 0.8);

shadowLight = new THREE.DirectionalLight('#4ECDC4', 0.3);

shadowLight.castShadow = true;

shadowLight.shadow.camera.left = -400;
fork icon15
star icon47
watch icon10

+ 15 other calls in file

186
187
188
189
190
191
192
193
194
195




// light
var light = new THREE.DirectionalLight(0xffffff);
light.position.set(1, 1, 1);
this.scene.add(light);
// var light = new THREE.DirectionalLight(0x002288);
// light.position.set(-1, -1, -1);
fork icon13
star icon28
watch icon7

+ 3 other calls in file

53
54
55
56
57
58
59
60
61
62
controls.domElement = container;
controls.rollSpeed = Math.PI / 24;
controls.autoForward = false;
controls.dragToLook = false;

dirLight = new THREE.DirectionalLight( 0xffffff );
dirLight.position.set( -1, 0, 1 ).normalize();
scene.add( dirLight );

var materialNormalMap = new THREE.MeshPhongMaterial( {
fork icon0
star icon3
watch icon5

16
17
18
19
20
21
22
23
24
25
point.position.y = 80;
scene.add(point);

var hemi = new THREE.HemisphereLight(0x5babc2, 0x8d5f2e, 1);

var dir = new THREE.DirectionalLight(0x5babc2, 0.5);
dir.position.y = 50;
dir.position.x = 10;
dir.position.z = -10;
dir.castShadow = true;
fork icon2
star icon51
watch icon7

164
165
166
167
168
169
170
171
172
173
scene = new THREE.Scene();
sceneCube = new THREE.Scene();
// Lights
var ambient = new THREE.AmbientLight( 0xffffff, 0.3 );
scene.add( ambient );
var sunlight = new THREE.DirectionalLight( 0xffffff, 1 )
sunlight.position.set(50, 100, 300); // Approximate vector towards sun in background image
scene.add( sunlight );
// Textures
var urls = [ 
fork icon75
star icon0
watch icon1

31
32
33
34
35
36
37
38
39
40
let clock = new THREE.Clock();
let loader = new THREE.TextureLoader();
let material = new THREE.MeshStandardMaterial({ vertexColors: THREE.VertexColors, map: new THREE.DataTexture(new Uint8Array(3).fill(255), 1, 1, THREE.RGBFormat) });

let ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.8);
let directionalLight = new THREE.DirectionalLight(0xFFFFFF, 0.5);
let pointLight = new THREE.PointLight(0xFFFFFF, 0.5);

let cube = new THREE.Mesh(new THREE.BoxBufferGeometry(0.2, 0.2, 0.2), material.clone());
let sphere = new THREE.Mesh(initColors(new THREE.SphereBufferGeometry(0.1, 20, 20)), material.clone());
fork icon10
star icon53
watch icon4

217
218
219
220
221
222
223
224
225
226
    //camera.lookAt( scene.position );
}

function createLights(){
          /* doesn't do anything //var light = new THREE.PointLight( 0xFFFF00 );
   var light = new THREE.DirectionalLight( 0xffffff, 0.5 );
   light.position.set( 10, 10, 10 );
   scene.add( light );
   */
//renderer.setClearColor( 0xdddddd, 1); //makes a gray background color instead of black
fork icon24
star icon38
watch icon12

169
170
171
172
173
174
175
176
177
178
scene = new THREE.Scene();

// var ambient = new THREE.AmbientLight( 0x444444 );
// scene.add( ambient );

// var directionalLight = new THREE.DirectionalLight( 0xffeedd );
// directionalLight.position.set( 0, 0, 1 ).normalize();
// scene.add( directionalLight );

// var sphereBufferGeometry = new THREE.SphereBufferGeometry( 5, 10, 10 );
fork icon5
star icon23
watch icon3

+ 5 other calls in file

48
49
50
51
52
53
54
55
56
57
  controls.noPan = false;
}

function addShadowedLight( x, y, z, color, intensity ) {

        var directionalLight = new THREE.DirectionalLight( color, intensity );
        directionalLight.position.set( x, y, z );
        scene.add( directionalLight );

        directionalLight.castShadow = true;
fork icon2
star icon13
watch icon1

106
107
108
109
110
111
112
113
114
115
 * @param {THREE.Scene} scene - the scene where to add lights
 * @returns {{directionalLight:THREE.DirectionalLight, ambientLight:THREE.AmbientLight}} - lights added
 */
addLights: function (scene) {
  // Lights
  const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
  directionalLight.position.set(100, 100, 500);
  directionalLight.target.position.set(0, 0, 0);
  directionalLight.updateMatrixWorld();
  scene.add(directionalLight);
fork icon15
star icon10
watch icon0

+ 4 other calls in file

172
173
174
175
176
177
178
179
180
initLight() {
  const frontLight = new THREE.DirectionalLight(0xffffff, 1.25);
  frontLight.position.set(0, 0.5, 2);
  this.scene.add(frontLight);

  const backLight = new THREE.DirectionalLight(0xffffff, 1.25);
  backLight.position.set(0, 0.5, -2);
  this.scene.add(backLight);
}
fork icon2
star icon3
watch icon2

+ 11 other calls in file

217
218
219
220
221
222
223
224
225
226
this.camera.position.set(0, 0, 35);
this.camera.lookAt(new THREE.Vector3(0, 0, 0));
this.scene.add(this.camera);

// Our key light is at a 3/4 angle from our subject.
this.directionalLight = new THREE.DirectionalLight(0xffffff, .75);
this.directionalLight.position.set(-1, 1, 0);
this.scene.add(this.directionalLight);

// Our fill light normalizes the colors, making white 100% white.
fork icon1
star icon11
watch icon1

+ 3 other calls in file

47
48
49
50
51
52
53
54
55
56
}

gui.add(options, 'strategy', ['Proxy Geometry', 'Ray Marching']);

scene.add(new THREE.AxisHelper(20));
scene.add(new THREE.DirectionalLight(0xffffff, 1));

var proxyGeometry = new ProxyGeometry();

var boxMesh = new THREE.Mesh(BoxGeometry, ProxyMaterial);
fork icon11
star icon3
watch icon6

282
283
284
285
286
287
288
289
290

var range = lightDef.range !== undefined ? lightDef.range : 0;

switch (lightDef.type) {
  case "directional":
    lightNode = new THREE.DirectionalLight(color);
    lightNode.target.position.set(0, 0, -1);
    lightNode.add(lightNode.target);
    break;
fork icon3
star icon7
watch icon8

+ 14 other calls in file

3396
3397
3398
3399
3400
3401
3402
3403
3404
    
    
    let light = new THREE.AmbientLight( 0xffffff, 0.5 ); // soft white light
    this.scene.add( light );
    
    const directionalLight = new THREE.DirectionalLight( 0xffffff, .5 );
    directionalLight.position.set( 1, 1, 1 );
    this.scene.add( directionalLight );
}
fork icon3
star icon7
watch icon0

+ 17 other calls in file

143
144
145
146
147
148
149
150
151
152

let light = new THREE.DirectionalLight(0xfff0dd, 1);
light.position.set(0, 5, 10);
this.scene.add(light);

let directionalLight = new THREE.DirectionalLight( 0xffffff, .5 );
directionalLight.position.set( 1, 1, 1 );
this.scene.add( directionalLight );

//let alight = new THREE.AmbientLight( 0x202020, 5 ); // soft white light
fork icon3
star icon7
watch icon0

+ 3 other calls in file

35
36
37
38
39
40
41
42
43
44
45


}
let numLayers = 0
let canvas = document.getElementById('canvas')
let camera, scene, renderer, controls
let camLight = new THREE.DirectionalLight(0xffffff, 0.75)
let mainObj
let wireframeObj
let normalsHelper
let mainGeom
fork icon2
star icon14
watch icon0

+ 5 other calls in file

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)