Shader_Minifier icon indicating copy to clipboard operation
Shader_Minifier copied to clipboard

Incorrect parsing behavior in multi-if scrope

Open lemoon opened this issue 2 years ago • 3 comments

input shader

varying vec2 v_texcoordOut;
uniform sampler2D s_texture;
uniform float u_degree;
uniform float u_degree2;

void main(void)
{
    vec2 texcoord = v_texcoordOut;
    if(u_degree > 0.001)
    {
        if(u_degree2 > 0.8)
        {
            texcoord.x += 0.1;
        }
        else if(u_degree2 >0.5)
        {
            texcoord.y += 0.1;
        }
    }
    gl_FragColor = texture2D(s_texture, texcoord);
}

after command

mono "$script_dir/shader_minifier.exe" -v --preserve-externals --field-names stpq -o res.h input.frag

// Generated with Shader Minifier 1.3.6 (https://github.com/laurentlb/Shader_Minifier/)
#ifndef RES_H_
# define RES_H_

const char *Basic_frag =
 "precision highp float;varying vec2 v_texcoordOut;"
 "uniform sampler2D s_texture;"
 "uniform float u_degree,u_degree2;"
 "void main()"
 "{"
   "vec2 f=v_texcoordOut;"
   "if(u_degree>.001)"
     "if(u_degree2>.8)"
       "f.s+=.1;"
     "else if(u_degree2>.5)"
       "f.t+=.1;"
   "gl_FragColor=texture2D(s_texture,f);"
 "}";

#endif // RES_H_

missing scrope in ""if(u_degree>.001)""

lemoon avatar Jul 12 '23 01:07 lemoon

I think the output is correct, the curly braces are not needed here.

laurentlb avatar Jul 12 '23 08:07 laurentlb

Some machines produce compilation errors because of this approach image

lemoon avatar Jul 12 '23 09:07 lemoon

Can you give more information on your setup? What tool is compiling the code? Have you considered filing a bug against that tool?

As far as I can tell, the syntax is not ambiguous, it's properly defined in the spec (at least for GLSL).

laurentlb avatar Jul 12 '23 09:07 laurentlb