2

I was trying to convert GLSL to GLSL ES and got this problem: transpose function isn't available in GLSL ES.

mat3 yuv = transpose(yuv_matrix);

So how I can use it? Is there any alternative?

younyokel
  • 327
  • 2
  • 15
  • 1
    Duplicate of [Transpose a mat4 in OpenGL ES 2.0 GLSL](https://stackoverflow.com/questions/18034677/transpose-a-mat4-in-opengl-es-2-0-glsl) – Andrea May 19 '19 at 19:10

1 Answers1

3

A 3x3 matrix can be transposed as follows:

mat3 yuv = mat3(
    vec3(yuv_matrix[0].x, yuv_matrix[1].x, yuv_matrix[2].x),
    vec3(yuv_matrix[0].y, yuv_matrix[1].y, yuv_matrix[2].y),
    vec3(yuv_matrix[0].z, yuv_matrix[1].z, yuv_matrix[2].z));

Note, the transposed matrix is a matrix which is flipped over its diagonal.

(a  b  c) T    (a  d  g)
(d  e  f)    = (b  e  h)
(g  h  i)      (c  f  i)

Matrices consist of column vectors. So a matrix can be initialized by vectors, e.g.:

vec3 a, b, c;
mat3 m = mat3(a, b, c); 

And the vectors of the matrix can be accessed by the index operator, e.g.:

mat3 m;
vec3 v = m[1];
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Thanks for reply. I'll try the first code tomorrow. – younyokel May 19 '19 at 20:13
  • By the way, I see bvec2, bvec3, etc. classes and I don't know should I change them to basis vec, vec2, vec3 classes? GLSL ES doesn't have such. – younyokel May 19 '19 at 20:16
  • 1
    @EadwineYoun GLSL ES has `bvec2`, `bvec3` and `bvec4` since version 1.0, see [The OpenGL® ES Shading Language Version: 1.00 - 4.1 Basic Types](https://www.khronos.org/registry/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf) page 18. – Rabbid76 May 19 '19 at 20:19
  • bvec is boolean vector, not basis – Andrea May 19 '19 at 20:56
  • It seems that I don't have it, somewhy. bvec just don't shows as build-in variable. – younyokel May 20 '19 at 08:28
  • @EadwineYoun `bvec` is a type rather than a variable. Anyway you can use an integral data type instead, `ivec2`, `ivec3` ... – Rabbid76 May 20 '19 at 08:35
  • Thanks, GLSL ES doesn't support mat4x3 like matrixes. What should I do with them? – younyokel May 20 '19 at 08:52
  • @EadwineYoun How should I know? For what reason do you need them? Probably you've to use 4x4 matrices. – Rabbid76 May 20 '19 at 09:03
  • @Andrea I didn't mean the type of vector, basis like usual/normal. – younyokel May 22 '19 at 12:57
  • @EadwineYoun then why are bvec2, bvec3 etc relevant to you here? – Andrea May 24 '19 at 08:59
  • @Andrea GameMaker's GLSL ES doesn't support these vectors. – younyokel May 25 '19 at 03:52
  • 1
    @EadwineYoun Please consider that this has nothing to do with this question. If you have a further issue, then pleas ask a new question. The reason is, that noone will read this comments here, but a new question will be read by many user, which may help you. – Rabbid76 May 25 '19 at 06:31