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 ?
Computer Graphics Stack Exchange is a question and answer site for computer graphics researchers and programmers. It only takes a minute to sign up.
Sign up to join this communityIn 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 ?
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.
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