Meshes: Make object mesh face shading consistent
authorparamat <mat.gregory@virginmedia.com>
Sat, 24 Dec 2016 06:40:57 +0000 (06:40 +0000)
committerparamat <mat.gregory@virginmedia.com>
Fri, 13 Jan 2017 02:42:18 +0000 (02:42 +0000)
Previously, object meshes had their North and South faces darker than
East and West faces, the opposite of nodes and meshnodes. This commit
corrects this.
State constants as float-literals not double-literals.
Simplify code.
Add comment.

src/mesh.cpp

index b68862d22ef3ff3738a91907abe73a117070737f..50465748cabec9739b4f1fe28eadb334c8e6247b 100644 (file)
@@ -186,17 +186,14 @@ void shadeMeshFaces(scene::IMesh *mesh)
                for (u32 i = 0; i < vertex_count; i++) {
                        video::S3DVertex *vertex = (video::S3DVertex *)(vertices + i * stride);
                        video::SColor &vc = vertex->Color;
-                       if (vertex->Normal.Y < -0.5) {
-                               applyFacesShading (vc, 0.447213);
-                       } else if (vertex->Normal.Z > 0.5) {
-                               applyFacesShading (vc, 0.670820);
-                       } else if (vertex->Normal.Z < -0.5) {
-                               applyFacesShading (vc, 0.670820);
-                       } else if (vertex->Normal.X > 0.5) {
-                               applyFacesShading (vc, 0.836660);
-                       } else if (vertex->Normal.X < -0.5) {
-                               applyFacesShading (vc, 0.836660);
-                       }
+                       // Many special drawtypes have normals set to 0,0,0 and this
+                       // must result in maximum brightness (no face shadng).
+                       if (vertex->Normal.Y < -0.5f)
+                               applyFacesShading (vc, 0.447213f);
+                       else if (vertex->Normal.X > 0.5f || vertex->Normal.X < -0.5f)
+                               applyFacesShading (vc, 0.670820f);
+                       else if (vertex->Normal.Z > 0.5f || vertex->Normal.Z < -0.5f)
+                               applyFacesShading (vc, 0.836660f);
                }
        }
 }