laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code
https://ctrl-alt-test.fr/minifier/
Apache License 2.0
430 stars 29 forks source link

Inlining of global floats in vec3 #315

Open heyjuvi opened 9 months ago

heyjuvi commented 9 months ago

When using (global) variables like

float a = 4;
vec3 b = vec3(a / 8, a / 8, 0);

the variable a gets inlined, but the information that it was a float seems to be lost, it appears as if an integer division is performed and the result is

vec3 b = vec3(0);
laurentlb commented 9 months ago

Thanks for the report! Using 4. should fix it.

Can you check if your GLSL compiler throws a type error when you write float a = 4; (without running Shader Minifier)?

heyjuvi commented 9 months ago

Yes. I checked it with using 8., but I’m sure 4. fixes this as well.

During development I'm using a non-minified version and it compiles fine (Nvidia driver for Linux). I think I also checked it with glslangValidator at some point as well and it didn't complain.