Skip to content

Commit 1698bec

Browse files
Fixed string replacement in metal shaders (#1537)
When we do string replacement for metal shaders we might replace the wrong substring if the original sampler name had "Texture" in the name. This is the reason why shadows currently don't work when using metal.
1 parent 2c53021 commit 1698bec

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Plugins/NativeEngine/Source/ShaderCompilerMetal.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ namespace Babylon
4949
compiler->set_name(resource.id, "_mtl_u");
5050
}
5151

52-
// rename textures without the 'texture' suffix so it's bindable from .js
52+
// WebGL shaders use a single sampler uniform, Metal separates it into a sampler and a texture, appending "Texture" and "Sampler" to the original WebGL names.
53+
// Remove 'Texture' from the uniform name to match JS expected names.
5354
for (auto& resource : resources.separate_images)
5455
{
5556
std::string imageName = resource.name;
5657
if (imageName.find("Texture") != std::string::npos)
5758
{
58-
imageName.replace(imageName.find("Texture"), std::string::npos, "");
59+
// Using rfind ensures the correct "Texture" is removed from WebGL uniforms with "texture" in their original name. (e.g., "shadowTexture1")
60+
imageName.replace(imageName.rfind("Texture"), std::string::npos, "");
5961
compiler->set_name(resource.id, imageName);
6062
}
6163
}

0 commit comments

Comments
 (0)