From 535c473103752627f1912be4b5c8d58529abcd7e Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 6 Dec 2014 22:13:31 +0100 Subject: [PATCH] Restore finalColorBlend implementation in shaders. --- .../shaders/nodes_shader/opengl_vertex.glsl | 32 +++++++++++++++++-- .../water_surface_shader/opengl_vertex.glsl | 32 +++++++++++++++++-- src/mapblock_mesh.cpp | 18 +++++++---- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index 36d29c1e5..ff310cc2f 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -49,8 +49,8 @@ void main(void) vec4 pos = gl_Vertex; vec4 pos2 = mWorld * gl_Vertex; if (gl_TexCoord[0].y < 0.05) { - pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8; - pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4; + pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8; + pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4; } gl_Position = mWorldViewProj * pos; #else @@ -97,5 +97,31 @@ void main(void) eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz; tsEyeVec = eyeVec * tbnMatrix; - gl_FrontColor = gl_BackColor = gl_Color; + vec4 color; + float day = gl_Color.r; + float night = gl_Color.g; + float light_source = gl_Color.b; + + float rg = mix(night, day, dayNightRatio); + rg += light_source * 2.5; // Make light sources brighter + float b = rg; + + // Moonlight is blue + b += (day - night) / 13.0; + rg -= (day - night) / 23.0; + + // Emphase blue a bit in darker places + // See C++ implementation in mapblock_mesh.cpp finalColorBlend() + b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025); + + // Artificial light is yellow-ish + // See C++ implementation in mapblock_mesh.cpp finalColorBlend() + rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); + + color.r = rg; + color.g = rg; + color.b = b; + + color.a = gl_Color.a; + gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0); } diff --git a/client/shaders/water_surface_shader/opengl_vertex.glsl b/client/shaders/water_surface_shader/opengl_vertex.glsl index 36d29c1e5..ad94fde32 100644 --- a/client/shaders/water_surface_shader/opengl_vertex.glsl +++ b/client/shaders/water_surface_shader/opengl_vertex.glsl @@ -49,8 +49,8 @@ void main(void) vec4 pos = gl_Vertex; vec4 pos2 = mWorld * gl_Vertex; if (gl_TexCoord[0].y < 0.05) { - pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8; - pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4; + pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8; + pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4; } gl_Position = mWorldViewProj * pos; #else @@ -97,5 +97,31 @@ void main(void) eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz; tsEyeVec = eyeVec * tbnMatrix; - gl_FrontColor = gl_BackColor = gl_Color; + vec4 color; + float day = gl_Color.r; + float night = gl_Color.g; + float light_source = gl_Color.b; + + float rg = mix(night, day, dayNightRatio); + rg += light_source * 2.5; // Make light sources brighter + float b = rg; + + // Moonlight is blue + b += (day - night) / 13.0; + rg -= (day - night) / 23.0; + + // Emphase blue a bit in darker places + // See C++ implementation in mapblock_mesh.cpp finalColorBlend() + b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025); + + // Artificial light is yellow-ish + // See C++ implementation in mapblock_mesh.cpp finalColorBlend() + rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); + + color.r = rg; + color.g = rg; + color.b = b; + + color.a = gl_Color.a; + gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0); } diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index e4c561a64..0ca24a1f9 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -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 > >::iterator i = m_daynight_diffs.begin(); -- 2.25.1