Restore finalColorBlend implementation in shaders.
authorRealBadAngel <maciej.kasatkin@o2.pl>
Sat, 6 Dec 2014 21:13:31 +0000 (22:13 +0100)
committerRealBadAngel <maciej.kasatkin@o2.pl>
Sun, 7 Dec 2014 10:05:00 +0000 (11:05 +0100)
client/shaders/nodes_shader/opengl_vertex.glsl
client/shaders/water_surface_shader/opengl_vertex.glsl
src/mapblock_mesh.cpp

index 36d29c1e58be02803c5dc3884b8b7f712595b6a0..ff310cc2f8be9332c230ac02d2f4e62dbdc223d0 100644 (file)
@@ -49,8 +49,8 @@ void main(void)
        vec4 pos = gl_Vertex;\r
        vec4 pos2 = mWorld * gl_Vertex;\r
        if (gl_TexCoord[0].y < 0.05) {\r
-       pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;\r
-                       pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;\r
+               pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;\r
+               pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;\r
        }\r
        gl_Position = mWorldViewProj * pos;\r
 #else\r
@@ -97,5 +97,31 @@ void main(void)
        eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
        tsEyeVec = eyeVec * tbnMatrix;\r
 \r
-       gl_FrontColor = gl_BackColor = gl_Color;\r
+       vec4 color;\r
+       float day = gl_Color.r;\r
+       float night = gl_Color.g;\r
+       float light_source = gl_Color.b;\r
+\r
+       float rg = mix(night, day, dayNightRatio);\r
+       rg += light_source * 2.5; // Make light sources brighter\r
+       float b = rg;\r
+\r
+       // Moonlight is blue\r
+       b += (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
+       b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);\r
+\r
+       // Artificial light is yellow-ish\r
+       // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
+       rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);\r
+\r
+       color.r = rg;\r
+       color.g = rg;\r
+       color.b = b;\r
+\r
+       color.a = gl_Color.a;\r
+       gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0);\r
 }\r
index 36d29c1e58be02803c5dc3884b8b7f712595b6a0..ad94fde325c28d1f7de214c804532a2bb351c901 100644 (file)
@@ -49,8 +49,8 @@ void main(void)
        vec4 pos = gl_Vertex;\r
        vec4 pos2 = mWorld * gl_Vertex;\r
        if (gl_TexCoord[0].y < 0.05) {\r
-       pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;\r
-                       pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;\r
+               pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;\r
+               pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4; \r
        }\r
        gl_Position = mWorldViewProj * pos;\r
 #else\r
@@ -97,5 +97,31 @@ void main(void)
        eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
        tsEyeVec = eyeVec * tbnMatrix;\r
 \r
-       gl_FrontColor = gl_BackColor = gl_Color;\r
+       vec4 color;\r
+       float day = gl_Color.r;\r
+       float night = gl_Color.g;\r
+       float light_source = gl_Color.b;\r
+\r
+       float rg = mix(night, day, dayNightRatio);\r
+       rg += light_source * 2.5; // Make light sources brighter\r
+       float b = rg;\r
+\r
+       // Moonlight is blue\r
+       b += (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
+       b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);\r
+\r
+       // Artificial light is yellow-ish\r
+       // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
+       rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);\r
+\r
+       color.r = rg;\r
+       color.g = rg;\r
+       color.b = b;\r
+\r
+       color.a = gl_Color.a;\r
+       gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0);\r
 }\r
index e4c561a64d9187c75c789e576bc507e78fcca99e..0ca24a1f919b2f847142f354198edb4a5415c4a3 100644 (file)
@@ -1162,12 +1162,16 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
                                        applyFacesShading (vc, 0.836660);
                                }
                        }
-                       // - Classic lighting
-                       // Set initial real color and store for later updates
-                       u8 day = vc.getRed();
-                       u8 night = vc.getGreen();
-                       finalColorBlend(vc, day, night, 1000);
-                       m_daynight_diffs[i][j] = std::make_pair(day, night);
+                       if(!m_enable_shaders)
+                       {
+                               // - Classic lighting (shaders handle this by themselves)
+                               // Set initial real color and store for later updates
+                               u8 day = vc.getRed();
+                               u8 night = vc.getGreen();
+                               finalColorBlend(vc, day, night, 1000);
+                               if(day != night)
+                                       m_daynight_diffs[i][j] = std::make_pair(day, night);
+                       }
                }
 
                // Create material
@@ -1331,7 +1335,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
        }
 
        // Day-night transition
-       if(daynight_ratio != m_last_daynight_ratio)
+       if(!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio))
        {
                for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
                                i = m_daynight_diffs.begin();