Skip to content

Commit 9f47262

Browse files
committedDec 16, 2024··
Add both long and short sampler names for random textures.
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.
1 parent a77df53 commit 9f47262

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎src/libprojectM/MilkdropPreset/MilkdropShader.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,33 @@ void MilkdropShader::GetReferencedSamplers(const std::string& program)
517517
found = program.find("texsize_", found);
518518
}
519519

520+
{
521+
// Remove duplicate mentions or "randXX" names, keeping the long forms only (first one will determine the actual texture loaded).
522+
auto samplerName = m_samplerNames.begin();
523+
std::locale loc;
524+
while (samplerName != m_samplerNames.end())
525+
{
526+
std::string lowerCaseName = Utils::ToLower(*samplerName);
527+
if (lowerCaseName.length() == 6 &&
528+
lowerCaseName.substr(0, 4) == "rand" && std::isdigit(lowerCaseName.at(4), loc) && std::isdigit(lowerCaseName.at(5), loc))
529+
{
530+
auto additionalName = samplerName;
531+
additionalName++;
532+
if (additionalName != m_samplerNames.end())
533+
{
534+
std::string addLowerCaseName = Utils::ToLower(*additionalName);
535+
if (addLowerCaseName.length() > 7 &&
536+
addLowerCaseName.substr(0, 6) == lowerCaseName &&
537+
addLowerCaseName[6] == '_')
538+
{
539+
samplerName = m_samplerNames.erase(samplerName);
540+
}
541+
}
542+
}
543+
samplerName++;
544+
}
545+
}
546+
520547
if (program.find("GetBlur3") != std::string::npos)
521548
{
522549
UpdateMaxBlurLevel(BlurTexture::BlurLevel::Blur3);

‎src/libprojectM/Renderer/TextureSamplerDescriptor.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ auto TextureSamplerDescriptor::SamplerDeclaration() const -> std::string
9595
declaration.append(m_samplerName);
9696
declaration.append(";\n");
9797

98+
// Add short sampler name for prefixed random textures.
99+
// E.g. "sampler_rand00" if a sampler "sampler_rand00_smalltiled" was declared
100+
if (m_samplerName.substr(0, 4) == "rand" && m_samplerName.length() > 7 && m_samplerName.at(6) == '_')
101+
{
102+
declaration.append("uniform sampler2D sampler_");
103+
declaration.append(m_samplerName.substr(0, 6));
104+
declaration.append(";\n");
105+
}
106+
98107
return declaration;
99108
}
100109

0 commit comments

Comments
 (0)
Please sign in to comment.