Shader_Minifier
Shader_Minifier copied to clipboard
Make unused variable removal safer
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.