From 8d98f1161e5693dd632ff3b716a62dc5be52f503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 10 Jul 2019 14:46:58 +0200 Subject: [PATCH] Shaders: clamp shininess factor in Phong to minimize artifacts. I feel this makes the shader code unnecessarily slow to handle bad parameters. But eh, until I actually benchmark, I shouldn't be making assumptions. --- doc/changelog.dox | 5 +++++ src/Magnum/Shaders/Phong.frag | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 72489ec1d..ad7b82e10 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -292,6 +292,11 @@ See also: also with @ref Corrade::Containers::ArrayView, @ref Corrade::Containers::StridedArrayView and friends +@subsubsection changelog-latest-changes-shaders Shaders library + +- @ref Shaders::Phong now clamps the specular factor to minimize artifacts + when shininess is near zero + @subsubsection changelog-latest-changes-texturetools TextureTools library - @ref TextureTools::distanceField() was updated to work on ES3 SwiftShader diff --git a/src/Magnum/Shaders/Phong.frag b/src/Magnum/Shaders/Phong.frag index 34e82be94..0e0575509 100644 --- a/src/Magnum/Shaders/Phong.frag +++ b/src/Magnum/Shaders/Phong.frag @@ -181,7 +181,7 @@ void main() { /* Add specular color, if needed */ if(intensity > 0.001) { highp vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal); - mediump float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess); + mediump float specularity = clamp(pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess), 0.0, 1.0); color += vec4(finalSpecularColor.rgb*specularity, finalSpecularColor.a); } }