Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unused variable removal safer #240

Open
laurentlb opened this issue Mar 3, 2023 · 0 comments
Open

Make unused variable removal safer #240

laurentlb opened this issue Mar 3, 2023 · 0 comments

Comments

@laurentlb
Copy link
Owner

The behavior is documented (https://github.com/laurentlb/Shader_Minifier#unused-local-variables), but it can be risky to remove the initialization code of a variable that is not used.

Code example:

out vec4 outcolor;
float glow = 0.;

vec2 map (in vec3 p) {
  glow = 1.;
  // ...
  return vec2(1);
}

vec2 march(vec3 ro, vec3 rd) {
  vec2 t = map(p);
  return vec2(1);
}

void main()
{    
    vec3 rd = vec3(1);
    vec3 ro = vec3(0);
    vec2 t = march(ro,rd);        
    //vec3 col = t.y*0 + abs(vec3(glow)*.65);        
    vec3 col = abs(vec3(glow)*.65);        
    outcolor = vec4(col,1.0);            
}

The user commented a use of the variable t, which deleted the call to march although it has a side-effect and modifies glow. We'd need a proper way to track side-effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant