Lights¶
Light Creation¶
-
p5.lights()¶ Sets the default ambient light, directional light, falloff, and specular values.
The defaults are ambientLight(128, 128, 128), directionalLight(128, 128, 128, 0, 0, -1), and lightFalloff(1, 0, 0).
-
p5.ambient_light(r, g, b)¶ Adds an ambient light.
Ambient light comes from all directions towards all directions. Ambient lights are almost always used in combination with other types of lights.
Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
-
p5.directional_light(r, g, b, x, y, z)¶ Adds a directional light. Directional light comes from one direction: it is stronger when hitting a surface squarely, and weaker if it hits at a gentle angle. After hitting a surface, directional light scatters in all directions.
Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
- x (float) – x component of the direction vector
- y (float) – y component of the direction vector
- z (float) – z component of the direction vector
-
p5.point_light(r, g, b, x, y, z)¶ Adds a point light. Point light comes from one location and emits to all directions.
Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
- x (float) – x component of the location vector
- y (float) – y component of the location vector
- z (float) – z component of the location vector
Light Effects¶
-
p5.light_falloff(constant, linear, quadratic)¶ Sets the falloff rates for point lights. Affects only the elements which are created after it in the code.
d = distance from light position to vertex position
falloff = 1 / (constant + d * linear + (d*d) * quadratic)
If the coefficient is 0, then that term is ignored. The P3D renderer defaults to (0, 0, 0), i.e. no falloff.
Parameters: - constant (float) – coefficient for the constant term
- linear (float) – coefficient for the linear term
- quadratic (float) – coefficient for the quadratic term
light_specular()¶
-
p5.light_specular(r, g, b)¶ Sets the specular color for lights. Only visible with
p5.blinn_phong_material. Is set to (0 ,0, 0) by default. Affects only the elements which are created after it in the code.Specular refers to light which bounces off a surface in a preferred direction (rather than bouncing in all directions like a diffuse light) and is used for creating highlights. The specular quality of a light interacts with the specular material qualities set through the specular() and shininess() functions.
Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel