Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add both long and short sampler names for random textures. #860

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/libprojectM/MilkdropPreset/MilkdropShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,33 @@ void MilkdropShader::GetReferencedSamplers(const std::string& program)
found = program.find("texsize_", found);
}

{
// Remove duplicate mentions or "randXX" names, keeping the long forms only (first one will determine the actual texture loaded).
auto samplerName = m_samplerNames.begin();
std::locale loc;
while (samplerName != m_samplerNames.end())
{
std::string lowerCaseName = Utils::ToLower(*samplerName);
if (lowerCaseName.length() == 6 &&
lowerCaseName.substr(0, 4) == "rand" && std::isdigit(lowerCaseName.at(4), loc) && std::isdigit(lowerCaseName.at(5), loc))
{
auto additionalName = samplerName;
additionalName++;
if (additionalName != m_samplerNames.end())
{
std::string addLowerCaseName = Utils::ToLower(*additionalName);
if (addLowerCaseName.length() > 7 &&
addLowerCaseName.substr(0, 6) == lowerCaseName &&
addLowerCaseName[6] == '_')
{
samplerName = m_samplerNames.erase(samplerName);
}
}
}
samplerName++;
}
}

if (program.find("GetBlur3") != std::string::npos)
{
UpdateMaxBlurLevel(BlurTexture::BlurLevel::Blur3);
Expand Down
9 changes: 9 additions & 0 deletions src/libprojectM/Renderer/TextureSamplerDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ auto TextureSamplerDescriptor::SamplerDeclaration() const -> std::string
declaration.append(m_samplerName);
declaration.append(";\n");

// Add short sampler name for prefixed random textures.
// E.g. "sampler_rand00" if a sampler "sampler_rand00_smalltiled" was declared
if (m_samplerName.substr(0, 4) == "rand" && m_samplerName.length() > 7 && m_samplerName.at(6) == '_')
{
declaration.append("uniform sampler2D sampler_");
declaration.append(m_samplerName.substr(0, 6));
declaration.append(";\n");
}

return declaration;
}

Expand Down
Loading