From fdc878d766c33b889d1cc74b413fb7830bf04df7 Mon Sep 17 00:00:00 2001 From: epochwon Date: Wed, 25 Jun 2025 17:04:21 -0400 Subject: [PATCH 1/4] elongate specular highlight --- files/shaders/compatibility/water.frag | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/files/shaders/compatibility/water.frag b/files/shaders/compatibility/water.frag index 749dcf27cd..6e447daad5 100644 --- a/files/shaders/compatibility/water.frag +++ b/files/shaders/compatibility/water.frag @@ -40,6 +40,8 @@ const vec3 SUN_EXT = vec3(0.45, 0.55, 0.68); // sunlight extinction const float SUN_SPEC_FADING_THRESHOLD = 0.15; // visibility at which sun specularity starts to fade const float SPEC_HARDNESS = 256.0; // specular highlights hardness +const float SPEC_BUMPINESS = 5.0; // surface bumpiness boost for specular +const float SPEC_BRIGHTNESS = 1.5; // boosts the brightness of the specular highlights const float BUMP_SUPPRESS_DEPTH = 300.0; // at what water depth bumpmap will be suppressed for reflections and refractions (prevents artifacts at shores) const float REFR_FOG_DISTORT_DISTANCE = 3000.0; // at what distance refraction fog will be calculated using real water depth instead of distorted depth (prevents splotchy shores) @@ -161,7 +163,8 @@ void main(void) sunSpec.a = min(1.0, sunSpec.a / SUN_SPEC_FADING_THRESHOLD); // specular - float specular = pow(max(dot(reflect(viewDir, normal), sunWorldDir), 0.0), SPEC_HARDNESS) * shadow * sunSpec.a; + vec3 R = reflect(viewDir, normalize(vec3(normal.x * SPEC_BUMPINESS, normal.y * SPEC_BUMPINESS, normal.z))); + float specular = clamp(pow(atan(max(dot(R, sunWorldDir), 0.0) * 1.55), SPEC_HARDNESS) * SPEC_BRIGHTNESS, 0.0, 1.0) * shadow * sunSpec.a; // artificial specularity to make rain ripples more noticeable vec3 skyColorEstimate = vec3(max(0.0, mix(-0.3, 1.0, sunFade))); From 13f1b76a25b0c56aa919a544e88566cc1e5c9287 Mon Sep 17 00:00:00 2001 From: epochwon Date: Wed, 25 Jun 2025 17:23:04 -0400 Subject: [PATCH 2/4] tabs to spaces --- files/shaders/compatibility/water.frag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/shaders/compatibility/water.frag b/files/shaders/compatibility/water.frag index 6e447daad5..33b6fe1163 100644 --- a/files/shaders/compatibility/water.frag +++ b/files/shaders/compatibility/water.frag @@ -40,8 +40,8 @@ const vec3 SUN_EXT = vec3(0.45, 0.55, 0.68); // sunlight extinction const float SUN_SPEC_FADING_THRESHOLD = 0.15; // visibility at which sun specularity starts to fade const float SPEC_HARDNESS = 256.0; // specular highlights hardness -const float SPEC_BUMPINESS = 5.0; // surface bumpiness boost for specular -const float SPEC_BRIGHTNESS = 1.5; // boosts the brightness of the specular highlights +const float SPEC_BUMPINESS = 5.0; // surface bumpiness boost for specular +const float SPEC_BRIGHTNESS = 1.5; // boosts the brightness of the specular highlights const float BUMP_SUPPRESS_DEPTH = 300.0; // at what water depth bumpmap will be suppressed for reflections and refractions (prevents artifacts at shores) const float REFR_FOG_DISTORT_DISTANCE = 3000.0; // at what distance refraction fog will be calculated using real water depth instead of distorted depth (prevents splotchy shores) From c89b2b0c600a4715a08f457daefb8bc350bb25e1 Mon Sep 17 00:00:00 2001 From: epochwon Date: Tue, 1 Jul 2025 10:42:42 -0400 Subject: [PATCH 3/4] fix indenting --- files/shaders/compatibility/water.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/shaders/compatibility/water.frag b/files/shaders/compatibility/water.frag index 33b6fe1163..81abdc094f 100644 --- a/files/shaders/compatibility/water.frag +++ b/files/shaders/compatibility/water.frag @@ -164,7 +164,7 @@ void main(void) // specular vec3 R = reflect(viewDir, normalize(vec3(normal.x * SPEC_BUMPINESS, normal.y * SPEC_BUMPINESS, normal.z))); - float specular = clamp(pow(atan(max(dot(R, sunWorldDir), 0.0) * 1.55), SPEC_HARDNESS) * SPEC_BRIGHTNESS, 0.0, 1.0) * shadow * sunSpec.a; + float specular = clamp(pow(atan(max(dot(R, sunWorldDir), 0.0) * 1.55), SPEC_HARDNESS) * SPEC_BRIGHTNESS, 0.0, 1.0) * shadow * sunSpec.a; // artificial specularity to make rain ripples more noticeable vec3 skyColorEstimate = vec3(max(0.0, mix(-0.3, 1.0, sunFade))); From 0027a5bcab250cc785fa77fdc1e69edbfc1d6d16 Mon Sep 17 00:00:00 2001 From: epochwon Date: Wed, 2 Jul 2025 10:49:27 -0400 Subject: [PATCH 4/4] make the specular terms easier to read, turn the magic number into a const --- files/shaders/compatibility/water.frag | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/files/shaders/compatibility/water.frag b/files/shaders/compatibility/water.frag index 81abdc094f..dbf36560b3 100644 --- a/files/shaders/compatibility/water.frag +++ b/files/shaders/compatibility/water.frag @@ -163,8 +163,13 @@ void main(void) sunSpec.a = min(1.0, sunSpec.a / SUN_SPEC_FADING_THRESHOLD); // specular - vec3 R = reflect(viewDir, normalize(vec3(normal.x * SPEC_BUMPINESS, normal.y * SPEC_BUMPINESS, normal.z))); - float specular = clamp(pow(atan(max(dot(R, sunWorldDir), 0.0) * 1.55), SPEC_HARDNESS) * SPEC_BRIGHTNESS, 0.0, 1.0) * shadow * sunSpec.a; + const float SPEC_MAGIC = 1.55; // from the original blender shader, changing it makes the spec vanish or become too bright + + vec3 specNormal = normalize(vec3(normal.x * SPEC_BUMPINESS, normal.y * SPEC_BUMPINESS, normal.z)); + vec3 viewReflectDir = reflect(viewDir, specNormal); + float phongTerm = max(dot(viewReflectDir, sunWorldDir), 0.0); + float specular = pow(atan(phongTerm * SPEC_MAGIC), SPEC_HARDNESS) * SPEC_BRIGHTNESS; + specular = clamp(specular, 0.0, 1.0) * shadow * sunSpec.a; // artificial specularity to make rain ripples more noticeable vec3 skyColorEstimate = vec3(max(0.0, mix(-0.3, 1.0, sunFade)));