Make faces shading correct for all possible modes.
authorRealBadAngel <maciej.kasatkin@o2.pl>
Sun, 10 Aug 2014 21:43:26 +0000 (23:43 +0200)
committerRealBadAngel <maciej.kasatkin@o2.pl>
Thu, 14 Aug 2014 04:43:47 +0000 (06:43 +0200)
Skip shading for lightsources and top of the nodes.
Fixes liquid sources and flowing surfaces having different brightness.

client/shaders/nodes_shader/opengl_vertex.glsl
src/mapblock_mesh.cpp

index 03b682d1be40b20682befe42007a677e6cf249be..28d3e8ed828be998616e3451d1c61da6d043350b 100644 (file)
@@ -108,7 +108,7 @@ void main(void)
 \r
        // Moonlight is blue\r
        b += (day - night) / 13.0;\r
-       rg -= (day - night) / 13.0;\r
+       rg -= (day - night) / 23.0;\r
 \r
        // Emphase blue a bit in darker places\r
        // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
index b29d07319f44b09282152603412e980752642c5d..ef2c868a066a911d11b3d68329a9c9a30dd31d8c 100644 (file)
@@ -32,11 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "util/directiontables.h"
 
-static void applyContrast(video::SColor& color, float factor)
+static void applyFacesShading(video::SColor& color, float factor)
 {
        color.setRed(core::clamp(core::round32(color.getRed()*factor), 0, 255));
        color.setGreen(core::clamp(core::round32(color.getGreen()*factor), 0, 255));
-       color.setBlue(core::clamp(core::round32(color.getBlue()*factor), 0, 255));
 }
 
 /*
@@ -1142,21 +1141,22 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
 
                for(u32 j = 0; j < p.vertices.size(); j++)
                {
-                       // Note applyContrast second parameter is precalculated sqrt from original
-                       // values for speed improvement
+                       // Note applyFacesShading second parameter is precalculated sqrt
+                       // value for speed improvement
+                       // Skip it for lightsources and top faces.
                        video::SColor &vc = p.vertices[j].Color;
-                       if(p.vertices[j].Normal.Y > 0.5) {
-                               applyContrast (vc, 1.095445);
-                       } else if (p.vertices[j].Normal.Y < -0.5) {
-                               applyContrast (vc, 0.547723);
-                       } else if (p.vertices[j].Normal.X > 0.5) {
-                               applyContrast (vc, 0.707107);
-                       } else if (p.vertices[j].Normal.X < -0.5) {
-                               applyContrast (vc, 0.707107);
-                       } else if (p.vertices[j].Normal.Z > 0.5) {
-                               applyContrast (vc, 0.894427);
-                       } else if (p.vertices[j].Normal.Z < -0.5) {
-                               applyContrast (vc, 0.894427);
+                       if (!vc.getBlue()) {
+                               if (p.vertices[j].Normal.Y < -0.5) {
+                                       applyFacesShading (vc, 0.447213);
+                               } else if (p.vertices[j].Normal.X > 0.5) {
+                                       applyFacesShading (vc, 0.670820);
+                               } else if (p.vertices[j].Normal.X < -0.5) {
+                                       applyFacesShading (vc, 0.670820);
+                               } else if (p.vertices[j].Normal.Z > 0.5) {
+                                       applyFacesShading (vc, 0.836660);
+                               } else if (p.vertices[j].Normal.Z < -0.5) {
+                                       applyFacesShading (vc, 0.836660);
+                               }
                        }
                        if(!enable_shaders)
                        {