three.js (lighting)

Types of light
1. Ambient Light (AmbientLight)
●Ambient light will uniformly illuminate all objects in the scene
●Ambient light cannot be used to cast shadows because it has no direction.
2. Parallel light (DirectionalLight)
●Parallel light is the light emitted along a specific direction. This light behaves as if it is infinitely far away, and the rays of light emanating from it are all parallel. Parallel light is often used to simulate the effect of sunlight; the sun is far enough away that we can consider the sun's position to be infinitely far away, so we believe that the rays of light emitted from the sun are also parallel.
●Parallel light can cast shadows
3. Point light source (PointLight)
●The light source emitted from one point to all directions.
● A common example is to simulate the light emitted by a light bulb.
●The light source can cast shadows
4. Spotlight (SpotLight)
●The light is emitted from a point along one direction, and the size of the light cone gradually increases as the light irradiates farther away. ● The public properties and methods of
the light that can cast shadows Constructor Light( color : Integer, intensity : Float ) ●color - (optional parameter) The hexadecimal representation of the color of the light. The default value is 0xffffff (white). ● intensity - (optional parameter) light intensity. The default value is 1. Creates a new light source. Note that this is not called directly (instead using one of the derived classes).






Attribute.color
: Color
●The color of the light source. If not passed during construction, a new Color will be created and set to white by default.

.intensity : Float
●The intensity, or energy, of the light. In physically correct mode, the product of color and intensity is resolved to luminous intensity in candela. Default - 1.0

. isLight : Boolean
● A read-only flag that checks whether the given object is of type Light.
Method.copy
( source : Light ): this
●Copy the values ​​of color and intensity from source to the current light source object.

.toJSON ( meta : Object ) : Object
Return light data in JSON format.
● meta -- An object that contains metadata, such as the object's material, texture, or image. Convert the light object to three.js JSON Object/Scene format (three.js JSON object/scene format).


AmbientLight (AmbientLight)
constructor
AmbientLight( color : Integer, intensity : Float )
●color - (parameter optional) the rgb value of the color. The default value is 0xffffff.
● intensity - (parameter optional) the intensity of the light. The default value is 1.

const light = new THREE.AmbientLight( 0x404040 ); // 创建一个环境光
scene.add( light );//添加到场景中去


Attribute.castShadow
: Boolean
●This parameter is set to undefined when the object is constructed. Because ambient light cannot cast shadows.

.isAmbientLight : Boolean
● Read-only flag to check if a given object is of ambient light type.
Parallel light (DirectionalLight)
constructor
DirectionalLight( color : Integer, intensity : Float )
●color - (optional parameter) Hexadecimal represents the color of the light. The default is 0xffffff (white).
● intensity - (optional parameter) the intensity of the light. The default value is 1.

// 半强度的白色定向光从顶部闪耀。
const directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
scene.add( directionalLight );


Property.castShadow
: Boolean
●If set to true, the parallel light will generate dynamic shadows. Warning: This is expensive and requires constant tweaking until the shadows look correct. This property defaults to false.

.isDirectionalLight : Boolean
A read-only flag to check if a given object is of type "directional light".

.position : Vector3
●The position of the light
●If this value is set equal to Object3D.DEFAULT_UP (0, 1, 0), then the light will shine from top to bottom.

.shadow : DirectionalLightShadow
●This DirectionalLightShadow object is used to calculate the shadow produced by the parallel light.

.target : Object3D
●The direction of the directional light is from its position to the target position. The default target position is the origin (0,0,0).
● Note: For the target's position, to change it to anything other than the default, it must be added to the scene.

scene.add( light.target );


● This causes the matrixWorld in the attribute target to be automatically updated every frame.
●It can also set the target to other objects in the scene (any object with position property), examples are as follows:

const targetObject = new THREE.Object3D();
scene.add(targetObject);
light.target = targetObject;


After completing the above operations, the directional light can now track to the target object.
Method.copy
( source : DirectionalLight ) : this
●Copy the value of source to this directional light source object.
PointLight (PointLight)
constructor
PointLight( color : Integer, intensity : Float, distance : Number, decay : Float )
●color - (optional parameter)) Hexadecimal light color. The default value is 0xffffff (white).
● intensity - (optional parameter) light intensity. The default value is 1.
● distance - the distance from the light source to the position where the light intensity is 0. When set to 0, the light never disappears (distance is infinite). Default value is 0.
●decay - Amount of decay along light distance. The default value is 2.

const light = new THREE.PointLight( 0xff0000, 1, 100 );//创建一个点光源
light.position.set( 50, 50, 50 );//设置点光源的初始位置
scene.add( light );//添加到场景中去


Property.castShadow
: Boolean
●If it is set to real light, it will cast dynamic shadow.
● NOTE: This is expensive and requires tweaking to get the shadows to look right.
● The default value is false.

.decay : Float
The amount by which the ray fades along the ray distance. The default value is 2.
● In the context of physically correct rendering, the default should not be changed.
.distance : Float
●If non-zero, then the light intensity will decay linearly from the maximum current light position to 0 according to the distance. The default value is 0.0.

.power : Float
●Optical power
●In physically correct mode, it indicates the optical power in the unit of "lumen (luminous flux unit)". Default - 4Math.PI.
●This value is directly related to intensity
power = intensity * 4π
●Modifying this value will also lead to changes in light intensity.

.shadow : PointLightShadow
●PointLightShadow is used to calculate the shadow of this light.
●The camera of this object is set as PerspectiveCamera with fov as 90 degrees, aspect as 1, near as 0 and far as 500.
Method.copy
( source : PointLight ) : this
●Copy all property values ​​from source to this point light object.
Spotlight (Spotlight)
constructor
SpotLight( color : Integer, intensity : Float, distance : Float, angle : Radians, penumbra : Float, decay : Float ) ●
color - (optional parameter) Hexadecimal light color. The default value is 0xffffff (white).
● intensity - (optional parameter) light intensity. The default value is 1.
● distance - the maximum distance from the light source to emit light, whose intensity decays linearly with the distance from the light source.
● angle - angle of light scattering, up to Math.PI/2.
● penumbra - Penumbra attenuation percentage of the spot cone. A value between 0 and 1. The default is 0.
●decay - Amount of decay along light distance.

//白色聚光灯从侧面照射,由纹理调制,投射阴影

const spotLight = new THREE.SpotLight( 0xffffff ); //创建一个聚光灯的实例
spotLight.position.set( 100, 1000, 100 );//初始化灯光的位置
spotLight.map = new THREE.TextureLoader().load( url );//创建一个纹理实例

spotLight.castShadow = true;//开启投影

//计算阴影的大小
spotLight.shadow.mapSize.width = 1024;
spotLight.shadow.mapSize.height = 1024;

//聚光源设置
spotLight.shadow.camera.near = 500;//设置阴影的近端面
spotLight.shadow.camera.far = 4000;//设置阴影的远端面
spotLight.shadow.camera.fov = 30;//设置阴影的角度

scene.add( spotLight );//把灯光添加到场景中


Attribute.angle
: Float
●The maximum range of the spotlight is expressed in radians from the position of the spotlight. The maximum does not exceed Math.PI/2. The default is Math.PI/3.

.castShadow : Boolean
●Set this property to true and the spotlight will cast shadows.
● The default value is false

.decay : Float
●The amount by which the ray fades along the ray distance. The default value is 2.
● In the context of physically correct rendering, the default should not be changed.

.distance : Float
●If non-zero, then the light intensity will decay linearly from the maximum current light position to 0 according to the distance. The default value is 0.0.

.isSpotLight : Boolean
● A read-only flag to check if a given object is of type spotlight.

.penumbra : Float
Penumbra attenuation percentage of the spot cone. A value between 0 and 1. Default value—0.0.

.position : Vector3
●Light source position
●If this value is set equal to Object3D.DEFAULT_UP (0, 1, 0), then the light will shine from top to bottom.

.power : Float
●Optical power
●In physically correct mode, it indicates the optical power in "lumen (luminous flux unit)". Default - 4Math.PI.
●This value is directly related to intensity
power = intensity * 4π
● Modifying this value will also result in a change in light intensity.

.shadow : SpotLightShadow
●SpotLightShadow is used to calculate the shadow of this light.

.target : Object3D
●The direction of the spotlight is from its position to the target position. The default target position is the origin (0,0,0).
●Note: For the target's position, to change it to anything other than the default, it must be added to the scene.
scene.add( light.target );
● This causes the matrixWorld in the attribute target to be automatically updated every frame.
●It can also set the target to other objects in the scene (any object with position property), examples are as follows:

const targetObject = new THREE.Object3D();
scene.add(targetObject);

light.target = targetObject


After completing the above operations, the spotlight can now track the target object.

.map : Texture
●The texture used to modulate the color of the light. ,
● The spotlight color is mixed with this texture's RGB value at a ratio corresponding to its alpha value. Reproduces a cookie-like masking effect using pixel values ​​(0, 0, 0, 1-cookie_value).
● Note: map: If cast shadows: spotlight is false, spotlight is disabled.
Method.copy
( source : SpotLight ) : this
● Copies the values ​​of all properties from the source source to this spotlight light source object.

 

Guess you like

Origin blog.csdn.net/w418856/article/details/130859208