Materials¶
Basic Material¶
-
p5.
basic_material
(r, g, b)¶ The default material. Always displays a solid color.
Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
Normal Material¶
-
p5.
normal_material
()¶ The color is determined by the normal vector of a surface. Does not respond to lights.
Useful for debugging.
Blinn-Phong Material¶
-
p5.
blinn_phong_material
()¶ Material based on the Blinn-Phong reflection model. This is the most “realistic” material in p5py.
Blinn-Phong shading can be decomposed into three parts: ambient, diffuse, and specular.
The ambient component is essentially a constant term that is alway present. We calculate it by summing all the ambient lights in a scene and multiplying it with the normalized ambient coefficent set by ambient.
The diffuse component takes the normal vector of a surface into account and varies how much light is reflected depending on the angle that the surface makes with the incoming light.
The specular component not only accounts for the direction of the light (like the diffuse component) but also the direction of the viewer. If the viewer is not on the path of the reflected light, the specular component falls off quickly, producing the glossy reflections we see on some materials.
The color shown on the user’s screen is the sum of all three components.
-
p5.
ambient
(r, g, b)¶ Sets the ambient light color reflected by the next
blinn_phong_material
.Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
-
p5.
emissive
(r, g, b)¶ This function is the same as diffuse.
Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
-
p5.
diffuse
(r, g, b)¶ Sets the diffuse light color reflected by the next
blinn_phong_material
.Parameters: - r (float) – red channel
- g (float) – green channel
- b (float) – blue channel
-
p5.
shininess
(p)¶ Sets how glossy the next
blinn_phong_material
is. This only affects the specular term.Should be used together with
light_specular
andspecular
.Parameters: p (float) – exponent of the cosine term in the Blinn-Phong Reflection Model
-
p5.
specular
(r, g, b)¶ Sets the specular light color reflected by the next
blinn_phong_material
.Should be used together with
light_specular
.