Skip to content

Commit

Permalink
#5565: Export light-related keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 26, 2021
1 parent 3fb802a commit af2e043
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
38 changes: 38 additions & 0 deletions radiantcore/shaders/MaterialSourceGenerator.cpp
Expand Up @@ -158,6 +158,44 @@ std::ostream& operator<<(std::ostream& stream, ShaderTemplate& shaderTemplate)
stream << "\trenderbumpflat " << shaderTemplate.getRenderBumpFlatArguments() << "\n";
}

// Light Flags
if (shaderTemplate.isAmbientLight() && shaderTemplate.isCubicLight())
{
stream << "\tambientCubicLight\n";
}
else
{
if (shaderTemplate.isAmbientLight())
{
stream << "\tambientLight\n";
}
else if (shaderTemplate.isCubicLight())
{
stream << "\tcubicLight\n";
}
}

if (shaderTemplate.isFogLight())
{
stream << "\tfogLight\n";
}
else if (shaderTemplate.isBlendLight())
{
stream << "\tblendLight\n";
}

if (shaderTemplate.getLightFalloff())
{
if (shaderTemplate.getLightFalloffCubeMapType() == IShaderLayer::MapType::CameraCubeMap)
{
stream << "\tlightFalloffCubeMap " << shaderTemplate.getLightFalloff()->getExpressionString() << "\n";
}
else
{
stream << "\tlightFalloffImage " << shaderTemplate.getLightFalloff()->getExpressionString() << "\n";
}
}

for (const auto& layer : shaderTemplate.getLayers())
{
stream << "\t{\n";
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -436,7 +436,8 @@ class ShaderTemplate final
void setLightFalloffExpressionFromString(const std::string& expressionString)
{
if (!_parsed) parseDefinition();
_lightFalloff = MapExpression::createForString(expressionString);
_lightFalloff = !expressionString.empty() ?
MapExpression::createForString(expressionString) : MapExpressionPtr();

onTemplateChanged();
}
Expand Down
53 changes: 53 additions & 0 deletions test/MaterialExport.cpp
Expand Up @@ -331,4 +331,57 @@ TEST_F(MaterialExportTest, RenderBumpFlat)
expectDefinitionContains(material, "renderbumpflat models/hipoly");
}

TEST_F(MaterialExportTest, LightFlags)
{
auto material = GlobalMaterialManager().getMaterial("textures/exporttest/empty");

EXPECT_EQ(string::trim_copy(material->getDefinition()), "");

material->setIsAmbientLight(true);
expectDefinitionContains(material, "ambientLight");
material->setIsAmbientLight(false);
expectDefinitionDoesNotContain(material, "ambientLight");

material->setIsBlendLight(true);
expectDefinitionContains(material, "blendLight");
material->setIsBlendLight(false);
expectDefinitionDoesNotContain(material, "blendLight");

material->setIsFogLight(true);
expectDefinitionContains(material, "fogLight");
material->setIsFogLight(false);
expectDefinitionDoesNotContain(material, "fogLight");

material->setIsCubicLight(true);
expectDefinitionContains(material, "cubicLight");
material->setIsCubicLight(false);
expectDefinitionDoesNotContain(material, "cubicLight");

material->setIsCubicLight(true);
material->setIsAmbientLight(true);
expectDefinitionContains(material, "ambientCubicLight");

material->setIsAmbientLight(false);
material->setIsCubicLight(false);
expectDefinitionDoesNotContain(material, "ambientCubicLight");
}

TEST_F(MaterialExportTest, LightFalloffImage)
{
auto material = GlobalMaterialManager().getMaterial("textures/exporttest/empty");

EXPECT_EQ(string::trim_copy(material->getDefinition()), "");

material->setLightFalloffCubeMapType(IShaderLayer::MapType::Map);
material->setLightFalloffExpressionFromString("makeintensity(lights/standard)");
expectDefinitionContains(material, "lightFalloffImage makeIntensity(lights/standard)");

material->setLightFalloffExpressionFromString("");
expectDefinitionDoesNotContain(material, "lightFalloffImage");

material->setLightFalloffCubeMapType(IShaderLayer::MapType::CameraCubeMap);
material->setLightFalloffExpressionFromString("env/standard");
expectDefinitionContains(material, "lightFalloffCubeMap env/standard");
}

}

0 comments on commit af2e043

Please sign in to comment.