<p>In a polygon mesh, all the faces that meet at a point don't have to share the same vertex. They can each have their own vertex, and those vertices can all have the same position but different normals.</p>

<p>In meshes with smooth edges (such as on a sphere, where you want to hide the edges), you want all the vertices at the same point to have the same normal. Generally this will be close to the average of the normals of the faces that share the vertex. That way, Lambertian shading computes the same colour for each, and you don't get a discontinuity on the edge.</p>

<p>In meshes where you want a deliberate sharp edge (such as your cube example), you want the vertices to have their own normals. In the cube case, each face has its own four vertices, and those vertices all have the same normal (the face normal). Each corner of the cube has three (or six, depending on the triangulation) vertices, with three normals perpendicular to each other. This way, Lambertian shading gives each face the same colour (because all the normals for one face point in the same direction), and adjacent faces don't affect each other.</p>

<p>A mesh with some rounded parts and some sharp edges can have both. Some vertices can be merged (i.e. each triangle meeting at the same point has the same vertex normal) and others can be split (i.e. each triangle meeting at the same point has its own normal for that vertex). One triangle can have some smooth vertices (shared with its neighbours) and some sharp vertices (with the face normal, not an averaged normal). It's best if the vertices on one edge are all the same, otherwise the results look unphysical.</p>

<p>Generally, the 3D modelling tool you use to create the mesh will give you the choice: you can make the whole mesh smooth or sharp, or you can select some edges and make them individually smooth or sharp.</p>

CC BY-SA 3.0
2016-10-21T11:27:35.610Z
2016-10-21T11:27:35.610Z
Dan Hulme
<p>Each cube face is made up of a quad, or two triangles.  Let's take 3 points from either the quad, or one of the triangles, and call them $A,B,C$.</p>

<p>You can get the normal to this surface by normalizing the cross product of $\overline{AB}$ and $\overline{BC}$.  You can then use that surface normal to calculate lighting.</p>

<p>You can do similar calculations to get the tangent and bitangent to then calculate $u,v$ values for texture mapping.</p>

<p>I'm not sure why the edges not having normals makes you think you can't calculate lighting for the cube faces, but you totally can.</p>

<p>You could even use the vertices to calculate a normal for the edges if you wanted, but I'm not sure why you would want to do that :P</p>

CC BY-SA 3.0
2016-10-20T22:31:50.500Z
2016-10-20T22:31:50.500Z
Alan Wolfe
<p>In theory I can't use a lambertian shader on a cube, because there aren't surface normals on the edges.</p>

<p>Is this correct ?</p>

<p>Why is this always possible in software applications ?</p>

CC BY-SA 3.0
2016-10-20T20:55:30.627Z
I'm going to go out on a limb and say that it's because the edges are infinitely thin (which follows from the fact that the flat surfaces on each side of the cube are infinitely thin), therefore they have zero surface area, therefore they don't need normals.
IneQuation
CC BY-SA 3.0
2016-10-21T06:04:38.600Z
Could you detail what makes you think you cannot use lambertian shading on a cube?
Julien Guertault
CC BY-SA 3.0
2016-10-21T11:56:52.870Z
@ Julien Guertault    I mean that for a mathematical cube there aren't normals on the edge points. The formula of Lambertian shading needs a surface with normals on every point. I know that software applications use some tricks, but with this view pratical computer graphics is not an approximation of theoric computer graphics.
Valerio
CC BY-SA 3.0
2016-10-25T01:06:25.817Z
Ah ok. So, pixels are infinitely small sample points on a grid.  The edge of a cube is infinitely thin - a line segment.  Because of this, we don't often see edges in rendering. When we do, they show up as holes in the cube, z fighting at the edge and similar. In practice though, you aren't ever shading the edge, just the faces.
Alan Wolfe
<shading>
Lambertian Shading of a cube
Valerio
# Lambertian Shading of a cube

(Asked by: username_0 on 2016-10-20)

In theory I can't use a lambertian shader on a cube, because there aren't surface normals on the edges.

Is this correct ?

Why is this always possible in software applications ?

**Tags:** shading

> **Comments:**
> **username_1**: I'm going to go out on a limb and say that it's because the edges are infinitely thin (which follows from the fact that the flat surfaces on each side of the cube are infinitely thin), therefore they have zero surface area, therefore they don't need normals.  
> **username_2**: Could you detail what makes you think you cannot use lambertian shading on a cube?  
> **username_0**: @ username_2 username_2    I mean that for a mathematical cube there aren't normals on the edge points. The formula of Lambertian shading needs a surface with normals on every point. I know that software applications use some tricks, but with this view pratical computer graphics is not an approximation of theoric computer graphics.  
> **username_3**: Ah ok. So, pixels are infinitely small sample points on a grid.  The edge of a cube is infinitely thin - a line segment.  Because of this, we don't often see edges in rendering. When we do, they show up as holes in the cube, z fighting at the edge and similar. In practice though, you aren't ever shading the edge, just the faces.  

---

## 2 answers

### Answer by username_4 on 2016-10-21. Score: 2

In a polygon mesh, all the faces that meet at a point don't have to share the same vertex. They can each have their own vertex, and those vertices can all have the same position but different normals.

In meshes with smooth edges (such as on a sphere, where you want to hide the edges), you want all the vertices at the same point to have the same normal. Generally this will be close to the average of the normals of the faces that share the vertex. That way, Lambertian shading computes the same colour for each, and you don't get a discontinuity on the edge.

In meshes where you want a deliberate sharp edge (such as your cube example), you want the vertices to have their own normals. In the cube case, each face has its own four vertices, and those vertices all have the same normal (the face normal). Each corner of the cube has three (or six, depending on the triangulation) vertices, with three normals perpendicular to each other. This way, Lambertian shading gives each face the same colour (because all the normals for one face point in the same direction), and adjacent faces don't affect each other.

A mesh with some rounded parts and some sharp edges can have both. Some vertices can be merged (i.e. each triangle meeting at the same point has the same vertex normal) and others can be split (i.e. each triangle meeting at the same point has its own normal for that vertex). One triangle can have some smooth vertices (shared with its neighbours) and some sharp vertices (with the face normal, not an averaged normal). It's best if the vertices on one edge are all the same, otherwise the results look unphysical.

Generally, the 3D modelling tool you use to create the mesh will give you the choice: you can make the whole mesh smooth or sharp, or you can select some edges and make them individually smooth or sharp.


---

### Answer by username_3 on 2016-10-20. Score: 1

Each cube face is made up of a quad, or two triangles. Let's take 3 points from either the quad, or one of the triangles, and call them $A,B,C$.

You can get the normal to this surface by normalizing the cross product of $\overline{AB}$ and $\overline{BC}$. You can then use that surface normal to calculate lighting.

You can do similar calculations to get the tangent and bitangent to then calculate $u,v$ values for texture mapping.

I'm not sure why the edges not having normals makes you think you can't calculate lighting for the cube faces, but you totally can.

You could even use the vertices to calculate a normal for the edges if you wanted, but I'm not sure why you would want to do that :P


---

