Skip to content

Commit

Permalink
#6041: Setting the "translucent" keyword implies noshadows
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 4, 2022
1 parent 7734ee8 commit 7092105
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -193,6 +193,9 @@ class ShaderTemplate final :

if (flag & Material::FLAG_TRANSLUCENT)
{
// Translucent implies noshadows
_materialFlags |= Material::FLAG_NOSHADOWS;

// Re-evaluate the material coverage
_coverage = Material::MC_UNDETERMINED;
determineCoverage();
Expand Down
21 changes: 21 additions & 0 deletions test/Materials.cpp
Expand Up @@ -1800,4 +1800,25 @@ TEST_F(MaterialsTest, ChangingTranslucentFlagSetsCoverage)
EXPECT_EQ(material->getCoverage(), Material::MC_TRANSLUCENT) << "Material should be translucent again";
}

TEST_F(MaterialsTest, ChangingTranslucentFlagAffectsNoShadows)
{
auto material = GlobalMaterialManager().getMaterial("textures/parsertest/coverage2");

EXPECT_TRUE(material) << "Could not find the material textures/parsertest/coverage2";
EXPECT_EQ(material->getCoverage(), Material::MC_TRANSLUCENT) << "Material should be translucent";
EXPECT_EQ(material->surfaceCastsShadow(), false) << "Material should not cast shadows";
EXPECT_TRUE(material->getMaterialFlags() & Material::FLAG_NOSHADOWS) << "Material should have the noshadows flag set";

material->clearMaterialFlag(Material::FLAG_TRANSLUCENT);
material->clearMaterialFlag(Material::FLAG_NOSHADOWS); // clearing translucent doesn't remove noshadows
EXPECT_EQ(material->getCoverage(), Material::MC_OPAQUE) << "Material should be opaque now";
EXPECT_FALSE(material->getMaterialFlags() & Material::FLAG_NOSHADOWS) << "Material should not have the noshadows flag set";
EXPECT_EQ(material->surfaceCastsShadow(), true) << "Material should cast shadows now";

material->setMaterialFlag(Material::FLAG_TRANSLUCENT);
EXPECT_EQ(material->getCoverage(), Material::MC_TRANSLUCENT) << "Material should be translucent again";
EXPECT_EQ(material->surfaceCastsShadow(), false) << "Material should not cast shadows anymore";
EXPECT_TRUE(material->getMaterialFlags() & Material::FLAG_NOSHADOWS) << "Material should have the noshadows flag set automatically";
}

}

0 comments on commit 7092105

Please sign in to comment.