Description
ShaderLab compiler does not expand #define macros used after . (dot) in swizzle positions.
Reproduction
#define OCCLUSION_CHANNEL r
#define ROUGHNESS_CHANNEL g
#define METALLIC_CHANNEL b
vec4 pbrRes = texture2D(pbrMap, uv);
pbr.x *= pbrRes.OCCLUSION_CHANNEL; // Expected: pbrRes.r, actual: compile error
pbr.y *= pbrRes.ROUGHNESS_CHANNEL;
pbr.z *= pbrRes.METALLIC_CHANNEL;
Error
CompilationError: Unexpected token OCCLUSION_CHANNEL
|··· pbr.x *= pbrRes.OCCLUSION_CHANNEL; ^^^^^^^^^^^^^^^^^
Expected
Standard GLSL preprocessors expand macros before parsing, so pbrRes.OCCLUSION_CHANNEL should be expanded to pbrRes.r and compile normally. This is a common pattern in Cocos Creator shaders.
Workaround
Inline the swizzle directly: pbrRes.r instead of pbrRes.OCCLUSION_CHANNEL.
Description
ShaderLab compiler does not expand
#definemacros used after.(dot) in swizzle positions.Reproduction
Error
Expected
Standard GLSL preprocessors expand macros before parsing, so
pbrRes.OCCLUSION_CHANNELshould be expanded topbrRes.rand compile normally. This is a common pattern in Cocos Creator shaders.Workaround
Inline the swizzle directly:
pbrRes.rinstead ofpbrRes.OCCLUSION_CHANNEL.