Shader_Minifier icon indicating copy to clipboard operation
Shader_Minifier copied to clipboard

fail: variables with a same name, ifdef preprocessor branching

Open 0b5vr opened this issue 4 years ago • 2 comments

Related: #28

Input

void main() {
#ifdef CONDITION
  vec3 col = vec3( 1.0 );
#else
  vec3 col = vec3( 0.0 );
#endif

  gl_FragColor = vec4( col, 1.0 );
}

Actual

void main(){
#ifdef CONDITION
vec3 C=vec3(1.);
#else
vec3 r=vec3(0.);
#endif
gl_FragColor=vec4(r,1.);}

Expected

void main(){
#ifdef CONDITION
vec3 C=vec3(1.);
#else
vec3 C=vec3(0.);
#endif
gl_FragColor=vec4(C,1.);}

0b5vr avatar Mar 09 '21 20:03 0b5vr

Here, the workaround can be to declare the variable before the macro:

void main() {
  vec3 col;
#ifdef CONDITION
  col = vec3( 1.0 );
#else
  col = vec3( 0.0 );
#endif
  gl_FragColor = vec4( col, 1.0 );
}

laurentlb avatar Mar 10 '21 16:03 laurentlb

yes I'm using that workaround right now.

0b5vr avatar Mar 16 '21 18:03 0b5vr