Closed niklasharrysson closed 2 years ago
The "mix" keyword has been added to the reserved list for GLSL, so I think it makes sense to close out this issue for now. It's still worthwhile to consider the idea of obfuscated identifiers in generated code, though this change would come with its own set of tradeoffs, especially with respect to the clarity of generated shading code for developers aiming to understand it.
When validating names for identifiers in GLSL codegen they are allowed to take on names equal to GLSL standard functions.
Here's an example document for which a uniform gets generated with the name "mix", colliding with the standard function mix(), which makes the resulting shader not compile:
A quick fix is to add the names of all standard GLSL functions to the list of reserved words here: https://github.com/materialx/MaterialX/blob/main/source/MaterialXGenGlsl/GlslSyntax.cpp#L158
But a better solution might be to make the generated identifiers more unique by obfuscating them a bit, for example appending some number to their name. The "mix" uniform in the example above would in code be generated as something like "mix_372". We already keep a separate record of parameter names (in UI) vs identifier names (in code), so the obfuscated names would not need to be displayed anywhere.