From 032972140542a084474a4464a65715b0767598b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 13 Mar 2020 15:38:33 +0100 Subject: [PATCH] Shaders: fix default alpha mask in a zero-light Phong on GLES. A corner case of a corner case, of a corner case. Adapted the test to check the defaults as well. --- doc/changelog.dox | 2 ++ src/Magnum/Shaders/Phong.cpp | 4 ++-- src/Magnum/Shaders/Test/PhongGLTest.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 6779a231a..71aa7b52b 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -391,6 +391,8 @@ See also: - @ref Resource was unnecessarily querying the @ref ResourceManager for updated data even in cases where no resource update was done since last check +- For a @ref Shaders::Phong with zero lights, alpha mask default value was + incorrectly @cpp 0.0f @ce instead of @cpp 0.5f @ce on OpenGL ES @subsection changelog-latest-deprecated Deprecated APIs diff --git a/src/Magnum/Shaders/Phong.cpp b/src/Magnum/Shaders/Phong.cpp index b3d3a26fe..2414dbb7a 100644 --- a/src/Magnum/Shaders/Phong.cpp +++ b/src/Magnum/Shaders/Phong.cpp @@ -191,12 +191,12 @@ Phong::Phong(const Flags flags, const UnsignedInt lightCount): _flags{flags}, _l setDiffuseColor(Magnum::Color4{1.0f}); setSpecularColor(Magnum::Color4{1.0f}); setShininess(80.0f); - if(flags & Flag::AlphaMask) setAlphaMask(0.5f); - /* Object ID is zero by default */ setLightColors(Containers::Array{Containers::DirectInit, lightCount, Magnum::Color4{1.0f}}); /* Light position is zero by default */ setNormalMatrix({}); } + if(flags & Flag::AlphaMask) setAlphaMask(0.5f); + /* Object ID is zero by default */ #endif } diff --git a/src/Magnum/Shaders/Test/PhongGLTest.cpp b/src/Magnum/Shaders/Test/PhongGLTest.cpp index 8e2b12a8b..b1f5da774 100644 --- a/src/Magnum/Shaders/Test/PhongGLTest.cpp +++ b/src/Magnum/Shaders/Test/PhongGLTest.cpp @@ -1063,7 +1063,9 @@ void PhongGLTest::renderAlpha() { .setSpecularColor(0xffffff00_rgbaf) .bindTextures(&ambient, &diffuse, nullptr, nullptr); - if(data.flags & Phong::Flag::AlphaMask) + /* Test that the default is correct by not setting the threshold if it's + equal to the default */ + if(data.flags & Phong::Flag::AlphaMask && data.threshold != 0.5f) shader.setAlphaMask(data.threshold); /* For proper Z order draw back faces first and then front faces */ @@ -1213,7 +1215,7 @@ void PhongGLTest::renderZeroLights() { Matrix4::rotationY(-15.0_degf)* Matrix4::rotationX(15.0_degf)) .setProjectionMatrix(Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f)) - .setAlphaMask(0.5f) + /* Keep alpha mask at the default 0.5 to test the default */ #ifndef MAGNUM_TARGET_GLES2 .setObjectId(65534) #endif