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

Many valid matrix constructors missing #209

Open
cbaggers opened this issue Jul 1, 2018 · 7 comments
Open

Many valid matrix constructors missing #209

cbaggers opened this issue Jul 1, 2018 · 7 comments
Assignees
Labels

Comments

@cbaggers
Copy link
Owner

cbaggers commented Jul 1, 2018

This issue is to combine the previous separate, valid issues raised by @mfiano and also to add my own issue to the pile

#207
#206
#205

Missing sized constructors

We need to add mat2x2, mat2x3, mat2x4, mat3x2, mat3x3, mat3x4, mat4x2, mat4x3, mat4x4

Matrices cannot be constructed from a single scalar

If a matrix is constructed with a single scalar value, then that value is used to initialize all the values along the diagonal of the matrix; the rest are given zeros. Therefore, mat4(1.0) is a 4x4 identity matrix.

Matrices cannot be converted to other matrices

A matrix can be constructed from another matrix A matrix can only be constructed from a single other matrix. The column and row values from the input matrix are copied to their corresponding values in the output; any values of the output not filled in are filled with the identity matrix.

Therefore:

mat3 diagMatrix = mat3(5.0); // Diagonal matrix with 5.0 on the diagonal.
mat4 otherMatrix = mat4(diagMatrix);
The otherMatrix is a diagonal matrix, where the first 3 values are 5.0, and the last diagonal value is 1.0.

There are no restrictions on size when doing matrix construction from another matrix. So you can construct a 4x2 matrix from a 2x4 matrix; only the corresponding elements are copied.

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

We are also missing the ability to do things like the following:

mat4(some-vec3, some-float, some-vec2, some-vec2, some-float, some-vec3, some-vec4)

And the reason is a limitation in varjo/glsl-spec. I am trying, over time, to remove ugly hacks that exist in varjo. One significant one is that, for some functions (which are not special forms) the return typed is computed rather than just looked up from the spec. These functions suck as they bloat the codebase with extra rules/hacks and they cant be defined in glsl-spec, aref of arrays or vectors is a good example as really this is a polymorphic function and varjo doesnt support that yet (and there is no explicit support in glsl).

In the case of the matrix constructor rules above, the number of valid permutations of argument types is huge (more than all the function overloads in the rest of the glsl spec combined iirc) so as it stands we cannot (sensibly) add all the constructors to glsl-spec.

I've been looking into supporting some kind of trait system, but regardless of the approach, without some support for polymorphism we would either have to:

  1. express matrix constructors as special forms (which means we cant pass them as first class functions) or..
  2. add another hack to varjo to support this.

Come to think of it, even with a traditional generics (ala c#) or traits system I think the permutation problem could still exist. Egh

Maybe the return type hack is the only way..what a bummer

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

The sized & single value constructors should be easy though. I also can forsee any problems with the conversions. I'll get on these soon

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

Actually size matrix types will be interesting as in varjo they are totally independent types, I have operators defined for them but mat2 is not equivalent to mat2x2. A function defined for mat3 will not take a mat3x3.

This may be fine but needs looking into

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

Making some progress cbaggers/glsl-spec@cb63e00

Will cover #206 at least. I'll look at non square matrices now

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

Ok, changes to glsl-spec will support #206 & #207 now (not merged yet though)

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

And now #205 too. Going to look at some other issues and then test this stuff before merging into master

@cbaggers
Copy link
Owner Author

cbaggers commented Jul 1, 2018

@mfiano #205 #206 & #207 should now be addressed on master. You will laos need to pull the latest master of glsl-spec.

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

No branches or pull requests

1 participant