Skip to content

Shaders refuse dot, det and the rest of a name beside a written matrix, though every shader variable is a number #2561

Description

@Rafael-SOWNet

MathS.Shaders.Hlsl and Glsl refuse a dot, cross, det, transpose, trace or entry whose operand has a name beside a written matrix. Their own reason for refusing is that "every variable of the shader is a number", and that is exactly why these can be computed: with x a number, dot(x * [1, 2], [3, 4]) is 11 x.

Measured on master b02ab06ff, with each expression the one output o:

Expression Refused at Reason given Value with every name a number
dot(x * [1, 2], [3, 4]) the dot taken of vectors, and every variable of the shader is a number 11 x
dot([0, 0, 1], cos(p) * [x, y, z]) the dot the same cos(p) z
det(x * [[1, 2], [3, 4]]) the det taken of a matrix, and every variable of the shader is a number -2 x^2
trace(x * [[1, 2], [3, 4]]) the trace the same 5 x
[0, 0, 1]T * cross(x * [1, 0, 0], [0, y, 0]) [[0, 0, 1]] a matrix, and each output is a number x y

The shader already carries out these operations when every operand is a matrix written out (ShaderSource.Prepared). It does not do so when a name stands beside one, because simplification keeps such an operation in case the name is a matrix (#105). In a shader no name can be a matrix.

#2558 makes both compilers carry these out wherever every name is compiled as a number, in the new MatrixOperationsOverNumbers. It does not touch ShaderSource. Calling the same rewrite from ShaderSource.Prepared should answer every row above, which would keep the shader in agreement with Compile, as #2254 set out to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions