Directional Light represents light that is emitted uniformly in a certain direction, with parallel light rays. Sunlight hitting the Earth's surface can be considered directional light because the distance between the Sun and the Earth is much greater than the Earth's radius. Therefore, sunlight hitting the Earth can be seen as a set of parallel light rays coming from the same direction, i.e., directional light.
Directional light has 3 main characteristics: color (color), intensity (intensity), and direction (direction). The direction is represented by the orientation of the node where the directional light is located.
Property | Function |
---|---|
Intensity | Controls the intensity of the parallel light, the higher the value, the brighter |
Color | Controls the color of the parallel light, default is white |
Culling Mask | Controls the objects that need to be illuminated by the light, default is Everything. Needs to be used in conjunction with the Entity's Layer |
Directional light can cast shadows. For related configurations, refer to the shadow documentation.
const lightEntity = rootEntity.createChild("light");
const directLight = lightEntity.addComponent(DirectLight);
// 调整颜色
directLight.color.set(0.3, 0.3, 1, 1);
// 调整强度
directLight.intensity = 2;
// 调整方向
lightEntity.transform.setRotation(-45, -45, 0);