Skip to content

Commit

Permalink
#6212: MaterialSourceGenerator can export frobstage syntax now
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 2, 2023
1 parent a399a0e commit 9d13df4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libs/materials/ParseLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ inline std::string getStringForClampType(ClampType type)
return std::string();
}

constexpr std::pair<Material::FrobStageType, const char*> FrobStageTypeNames[]
{
{ Material::FrobStageType::Default, "" },
{ Material::FrobStageType::Diffuse, "frobstage_diffuse" },
{ Material::FrobStageType::Texture, "frobstage_texture" },
{ Material::FrobStageType::None, "frobstage_none" },
};

inline std::string getStringForFrobStageType(Material::FrobStageType type)
{
for (const auto& pair : FrobStageTypeNames)
{
if (type == pair.first)
{
return pair.second;
}
}

return std::string();
}

constexpr int NUM_MAX_VERTEX_PARMS = 4;
constexpr int NUM_MAX_FRAGMENT_MAPS = 8;

Expand Down
36 changes: 36 additions & 0 deletions radiantcore/shaders/MaterialSourceGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ std::ostream& operator<<(std::ostream& stream, Doom3ShaderLayer& layer)
return stream;
}

// Writes (x y z) or just a single number without parentheses if the vector has uniform values
void writeScalarOrVector3(std::ostream& stream, const Vector3& vec)
{
if (vec.x() == vec.y() && vec.y() == vec.z())
{
stream << vec.x();
}
else
{
stream << "(" << vec.x() << " " << vec.y() << " " << vec.z() << ")";
}
}

// Write the material to the given stream (one tab indentation)
std::ostream& operator<<(std::ostream& stream, ShaderTemplate& shaderTemplate)
{
Expand Down Expand Up @@ -676,6 +689,29 @@ std::ostream& operator<<(std::ostream& stream, ShaderTemplate& shaderTemplate)
stream << *layer;
}

// FrobStage keywords
if (shaderTemplate.getFrobStageType() != Material::FrobStageType::Default)
{
stream << "\n";
stream << getStringForFrobStageType(shaderTemplate.getFrobStageType());

if (shaderTemplate.getFrobStageType() == Material::FrobStageType::Texture)
{
stream << " ";
const auto& expr = shaderTemplate.getFrobStageMapExpression();
stream << (expr ? expr->getExpressionString() : "_white"); // don't export invalid syntax
}

if (shaderTemplate.getFrobStageType() == Material::FrobStageType::Diffuse ||
shaderTemplate.getFrobStageType() == Material::FrobStageType::Texture)
{
stream << " ";
writeScalarOrVector3(stream, shaderTemplate.getFrobStageRgbParameter(0));
stream << " ";
writeScalarOrVector3(stream, shaderTemplate.getFrobStageRgbParameter(1));
}
}

return stream;
}

Expand Down

0 comments on commit 9d13df4

Please sign in to comment.