Post

Replies

Boosts

Views

Activity

Reply to Initialize metal shading language 3x3 matrix
Nowadays the metal shading language specification states that it's possible, but still it doesn't specify the order, section 2.3.2 Matrix Constructors says: Since Metal 2, a matrix of type T with n columns and m rows > can also be constructed from n * m scalars of type T. The following examples are legal constructors: float2x2(float, float, float, float); float3x2(float, float, float, float, float, float); I'm too lazy to bounce data to the shader and back just to check, but I'd appreciate if anybody who knows would answer to the initial question, and even better would make a clarification in that document BTW the document: https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf
Topic: Graphics & Games SubTopic: General Tags:
Feb ’25
Reply to Invert a 3x3 matrix in a Metal compute kernel
the function if somebody needs it see https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3_%C3%97_3_matrices static float3x3 inverse(float3x3 const m) { float const A = m[1][1] * m[2][2] - m[2][1] * m[1][2]; float const B = -(m[0][1] * m[2][2] - m[2][1] * m[0][2]); float const C = m[0][1] * m[1][2] - m[1][1] * m[0][2]; float const D = -(m[1][0] * m[2][2] - m[2][0] * m[1][2]); float const E = m[0][0] * m[2][2] - m[2][0] * m[0][2]; float const F = -(m[0][0] * m[1][2] - m[1][0] * m[0][2]); float const G = m[1][0] * m[2][1] - m[2][0] * m[1][1]; float const H = -(m[0][0] * m[2][1] - m[2][0] * m[0][1]); float const I = m[0][0] * m[1][1] - m[1][0] * m[0][1]; float const det = m[0][0] * A + m[1][0] * B + m[2][0] * C; float const inv_det = 1.f / det; return inv_det * float3x3{ float3{A, B, C}, float3{D, E, F}, float3{G, H, I} }; }
Topic: Graphics & Games SubTopic: General Tags:
Feb ’25