Skip to content

Commit

Permalink
Add both long and short sampler names for random textures.
Browse files Browse the repository at this point in the history
If a preset uses different long-form samplers for a single random slot, this will result in a failure, e.g. using both "sampler_rand00_something" and "sampler_rand00_else". As this also isn't supported by Milkdrop and would create a conflict situation, we don't care.
  • Loading branch information
kblaschke committed Dec 16, 2024
1 parent a77df53 commit 9f47262
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit 9f47262

Please sign in to comment.