laurentlb / shader-minifier

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

Matrix multiply is not commutative #472

Open Elektraglide opened 2 hours ago

Elektraglide commented 2 hours ago

you cannot swap order of multiplies for matrices; it changes the meaning. I have vec4 v = mat33 (vec3 float) which is transformed into: vec4 v = (vec3 float) mat33

Is rewriter.fs:240 the problem?

laurentlb commented 2 hours ago

Which version of Shader Minifier are you using? I think we fixed some instances of the bug.

Can you share the line of code that triggers the bug?

eldritchconundrum commented 2 hours ago

My guess is, it's this rewrite: x*(y*z) -> y*z*x How to reproduce: mat2 f(){ return mat3x2(1) * (mat4x3(1) * mat2x4(1)); } becomes mat2 f(){return mat4x3(1)*mat2x4(1)*mat3x2(1);}

Elektraglide commented 2 hours ago

Damn, thats a quick response! I had edited my post having looked atthe source code. Is rewriter.fs:240 the problem?

eldritchconundrum commented 2 hours ago

No, but commenting out lines 198-200 of rewriter.fs should fix it

Elektraglide commented 2 hours ago

yep, that works. cheers

laurentlb commented 2 hours ago

Good point, we need a --version flag. :)

The version number is included in (some of) the generated outputs, but you can also run .\shader_minifier.exe --help and look at the first line.