aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornumberZero <silverunicorn2011@yandex.ru>2017-02-05 13:27:58 +0400
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-02-05 10:27:58 +0100
commit80c75272a6ffff34069ed470e959f7ff007e6c06 (patch)
treebf7769e6accb2ea018145382ec5a6fc0fe265a92 /src
parentf2f9a923515386d787a245fac52f78e815b3a839 (diff)
downloadminetest-80c75272a6ffff34069ed470e959f7ff007e6c06.tar.gz
minetest-80c75272a6ffff34069ed470e959f7ff007e6c06.tar.bz2
minetest-80c75272a6ffff34069ed470e959f7ff007e6c06.zip
Improve mesh shading (#5172)
Diffstat (limited to 'src')
-rw-r--r--src/mesh.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mesh.cpp b/src/mesh.cpp
index 84689b631..6a055abb2 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -44,12 +44,13 @@ void applyFacesShading(video::SColor &color, const v3f &normal)
{
// Many special drawtypes have normals set to 0,0,0 and this
// must result in maximum brightness (no face shadng).
- if (normal.Y < -0.5f)
- applyShadeFactor (color, 0.447213f);
- else if (normal.X > 0.5f || normal.X < -0.5f)
- applyShadeFactor (color, 0.670820f);
- else if (normal.Z > 0.5f || normal.Z < -0.5f)
- applyShadeFactor (color, 0.836660f);
+ float x2 = normal.X * normal.X;
+ float y2 = normal.Y * normal.Y;
+ float z2 = normal.Z * normal.Z;
+ if (normal.Y < 0)
+ applyShadeFactor(color, 0.670820f * x2 + 0.447213f * y2 + 0.836660f * z2);
+ else if ((x2 > 1e-3) || (z2 > 1e-3))
+ applyShadeFactor(color, 0.670820f * x2 + 1.000000f * y2 + 0.836660f * z2);
}
scene::IAnimatedMesh* createCubeMesh(v3f scale)