patriciogonzalezvivo / glslViewer

Console-based GLSL Sandbox for 2D/3D shaders
BSD 3-Clause "New" or "Revised" License
4.57k stars 352 forks source link

[BUG] macro expansion causes syntax error #351

Open slaimon opened 8 months ago

slaimon commented 8 months ago

This is the minimum code that reproduces the error on my platform:

uniform vec2 u_resolution;
#define A(a,b,x)  abs(x-b-a)

void main() {
     vec2 pt = gl_FragCoord.xy/u_resolution.xy;  
     float a = A(-1.0, 1.0, pt.x);

     gl_FragColor = vec4(a);
}

glslViewer produces the following error message:

Found error while compiling fragment shader
0:6(26): error: syntax error, unexpected FLOATCONSTANT, expecting ')' or ','

Note that line 6 is the one with the macro expansion in it, and column 26 would be the closing parenthesis. Of course I tested the above code with glslangValidator and it compiles without any errors. It even works on the website editor.thebookofshaders.com.