View Full Version : mix( matrix, matrix, float )

Dark Photon

06-07-2012, 09:46 AM

mat /= float and mat *= float are defined for matrices. But its unclear why other component-wise built-in functions like mix aren't. Seems like they easily could be. Would be useful and shorten shader code.

mat3 m1 = mat3(1);

mat3 m2 = mat3(1);

mat3 m3 = mix( m1, m2, 0.5 );

yields:

tst_vert.glsl(100) : error C1115: unable to find compatible overloaded function "mix(mat3, mat3, float)"

Ilian Dinev

06-07-2012, 10:38 AM

mat3 m3;

m3.x = mix( m1.x, m2.x, 0.5 );

m3.y = mix( m1.y, m2.y, 0.5 );

m3.z = mix( m1.z, m2.z, 0.5 );

Focus for most ops (eg sqrt,sin,floor, min) generally is on vectors. Having them also support matrices seems redundant to me. Though interaction of matrices and floats doesn't seem important enough, either.

Dark Photon

06-07-2012, 03:28 PM

Focus for most ops (eg sqrt,sin,floor, min) generally is on vectors. Having them also support matrices seems redundant to me. Though interaction of matrices and floats doesn't seem important enough, either.

Right. It's not a huge deal. Just noticed while coding up some DQ skinning I had to break out the individual vectors and mix separately, but only for functions not operators.

mhagain

06-07-2012, 04:49 PM

mat3 m1;

mat3 m2;

mat3 m3 = (m1 * (1.0 - mixfactor)) + (m2 * mixfactor);

Compiles without error for me, should work.

Dark Photon

06-07-2012, 06:04 PM

mat3 m1;

mat3 m2;

mat3 m3 = (m1 * (1.0 - mixfactor)) + (m2 * mixfactor);

Compiles without error for me, should work.

Definitely an option. And that's a perfect example of what seems odd to me. The built-in operators all support component-wise operation on matrices, but the built-in functions (that do component-wise operation on vectors) don't do component-wise operation on matrices. Cg is like that too, so it's not like GLSL needs to catch-up there. Also, the expression you provide above is the exact definition of mix(), and it works for matrices, ...so why shouldn't mix() "just work" in this case (aside from the language currently precludes it)? Anyway...

mhagain

06-08-2012, 04:08 AM

Seems odd for sure; HLSL specifies that it's equivalent (lerp (matrix1, matrix2, factor)) is acceptable too (and has been since SM1 days), so while it's not a show-stopper it would definitely be nice to clean up the GLSL spec with this.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.