Reference normal()

normal()

Sets the normal vector for vertices in a custom 3D shape.

3D shapes created with beginShape() and endShape() are made by connecting sets of points called vertices. Each vertex added with vertex() has a normal vector that points away from it. The normal vector controls how light reflects off the shape.

normal() can be called two ways with different parameters to define the normal vector's components.

The first way to call normal() has three parameters, x, y, and z. If Numbers are passed, as in normal(1, 2, 3), they set the x-, y-, and z-components of the normal vector.

The second way to call normal() has one parameter, vector. If a p5.Vector object is passed, as in normal(myVector), its components will be used to set the normal vector.

normal() changes the normal vector of vertices added to a custom shape with vertex(). normal() must be called between the beginShape() and endShape() functions, just like vertex(). The normal vector set by calling normal() will affect all following vertices until normal() is called again:

beginShape();
// Set the vertex normal.
normal(-0.4, -0.4, 0.8);
// Add a vertex.
vertex(-30, -30, 0);
// Set the vertex normal.
normal(0, 0, 1);
// Add vertices.
vertex(30, -30, 0);
vertex(30, 30, 0);
// Set the vertex normal.
normal(0.4, -0.4, 0.8);
// Add a vertex.
vertex(-30, 30, 0);
endShape(); 

Examples

Syntax

normal(vector)
normal(x, y, z)

Parameters

vector
p5.Vector:

vertex normal as a p5.Vector object.

x
Number:

x-component of the vertex normal.

y
Number:

y-component of the vertex normal.

z
Number:

z-component of the vertex normal.

Notice any errors or typos? Please let us know. Please feel free to edit src/core/shape/vertex.js and open a pull request!

Related References