diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 681e7dcf7..f0159c67c 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -53,6 +53,8 @@ centroid varying float nightRatio; varying highp vec3 eyeVec; varying float nightFactor; +#define PI 3.141592653589 + #ifdef ENABLE_DYNAMIC_SHADOWS #if (MATERIAL_WAVING_LIQUID && defined(ENABLE_WATER_REFLECTIONS)) vec4 perm(vec4 x) @@ -526,7 +528,7 @@ void main(void) vec3 reflection_color = mix(vec3(max(fogColor.r, max(fogColor.g, fogColor.b))), fogColor.rgb, f_shadow_strength); // Sky reflection - col.rgb += reflection_color * pow(fresnel_factor, 2.0) * 0.5 * brightness_factor; + col.rgb += reflection_color * pow(fresnel_factor, 2.0) * 0.3 * brightness_factor; vec3 water_reflect_color = 1.5 * specular_intensity * sunTint * dayLight * fresnel_factor * max(1.0 - shadow_uncorrected, 0.0) * @@ -539,14 +541,28 @@ void main(void) #if (defined(ENABLE_NODE_SPECULAR) && !MATERIAL_WATER_REFLECTIONS) // Apply specular to blocks. if (dot(v_LightDirection, vNormal) < 0.0) { - // This intensity is a placeholder and should be replaced by proper specular maps. - float intensity = specular_intensity * min(1.0, length(varColor.rgb * base.rgb)); - const float specular_exponent = 5.0; - const float fresnel_exponent = 4.0; + // This intensity/roughness is a placeholder and should be replaced by proper specular maps. + float intensity = 0.35 * min(1.0, length(varColor.rgb * base.rgb)); + float roughness = 0.5; + + float rms = 1.0 / (1.0 - roughness) - 1.0; + vec3 half_vector = normalize(viewVec + v_LightDirection); + const float F0 = 0.04; + + float HV = dot(viewVec, half_vector); + float HN = dot(fNormal, half_vector); + float VN = dot(viewVec, normalize(fNormal)); + float LN = dot(v_LightDirection, fNormal); + + float HN2 = HN*HN; + + float beckmann = exp((HN2 - 1.0) / (rms * rms * HN2)) / (PI * rms * rms * HN2*HN2); + float geometry = min(min(1.0, 2.0 * HN * VN / HV), 2.0 * HN * LN / HV); + float fresnel_schlick = F0 + (1.0 - F0) * pow(1.0 - HV, 5.0); col.rgb += - sunTint * intensity * f_shadow_factor * dayLight * (1.0 - nightRatio) * (1.0 - shadow_uncorrected) * - pow(max(dot(reflect_ray, viewVec), 0.0), fresnel_exponent) * pow(1.0 - abs(dot(viewVec, fNormal)), specular_exponent); + sunTint * specular_intensity * f_shadow_factor * dayLight * (1.0 - nightRatio) * (1.0 - shadow_uncorrected) * + intensity * beckmann * geometry * fresnel_schlick / (VN * LN * PI); } #endif diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index cdadf92b9..e5d480f6c 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -286,7 +286,8 @@ void main(void) (1.0 - mtsmoothstep(0.762, 0.792, f_timeofday)); nightFactor = adj_shadow_strength / f_shadow_strength; #ifdef ENABLE_TINTED_SUNLIGHT - sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), adj_shadow_strength / f_shadow_strength); + float tint_strength = 1.0 - mtsmoothstep(0.792, 0.5, f_timeofday) * mtsmoothstep(0.208, 0.5, f_timeofday); + sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), nightFactor * tint_strength); #endif } } diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index 6dc1b8bda..8ed1c6f67 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -185,7 +185,10 @@ void main(void) adj_shadow_strength = f_shadow_strength * mtsmoothstep(0.208, 0.238, f_timeofday) * (1.0 - mtsmoothstep(0.762, 0.792, f_timeofday)); - sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), adj_shadow_strength / f_shadow_strength); +#ifdef ENABLE_TINTED_SUNLIGHT + float tint_strength = 1.0 - mtsmoothstep(0.792, 0.5, f_timeofday) * mtsmoothstep(0.208, 0.5, f_timeofday); + sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), nightFactor * tint_strength); +#endif } } #endif diff --git a/doc/lua_api.md b/doc/lua_api.md index 60e9705f3..8dc573c0c 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8941,9 +8941,11 @@ child will follow movement and rotation of that bone. (eg. -1 and 1 is the same saturation and luma, but different hues) * This value has no effect on clients who have shaders or post-processing disabled. * `foliage_translucency` controls the intensity of the foliage translucency effect (default: `1.5`). + * Subject to change and can be removed at any time. * This has no effect when dynamic shadows are disabled and on clients who have the "Translucent foliage" effect disabled. - * `specular_intensity` controls the intensity of specular highlights on nodes and liquids (default: `1.5`). - * This has no effect when dynamic shadows are disabled and on clients who have the "Translucent foliage" effect disabled. + * `specular_intensity` controls the intensity of specular highlights on nodes and liquids (default: `0.0`). + * Subject to change and can be removed at any time. + * This has no effect when dynamic shadows are disabled. * `shadows` is a table that controls ambient shadows * This has no effect on clients who have the "Dynamic Shadows" effect disabled. * `intensity` sets the intensity of the shadows from 0 (no shadows, default) to 1 (blackness) diff --git a/src/lighting.h b/src/lighting.h index 216bbfb59..864262aa3 100644 --- a/src/lighting.h +++ b/src/lighting.h @@ -77,7 +77,7 @@ struct Lighting float saturation {1.0f}; float volumetric_light_strength {0.0f}; float foliage_translucency{1.5f}; - float specular_intensity{1.5f}; + float specular_intensity{0.0f}; // These factors are calculated based on expected value of scattering factor of 1e-5 // for Nitrogen at 532nm (green), 2e25 molecules/m3 in atmosphere v3f volumetric_beta_r0{ 3.3362176e-01f, 8.753783e-01f, 1.9534237f };