Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: inverse and transpose of matrices in glSlang state

  1. #1
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    293

    inverse and transpose of matrices in glSlang state

    thread in the suggestions forum: http://www.opengl.org/discussion_boa...ML/000453.html

    i would like to know your opinion.

    thx

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    666

    Re: inverse and transpose of matrices in glSlang state

    I agree... some of the states offered by ARB_vp are quite useful, like state.matrix.modelview[0].invtrans.row[3], which I use to implicitly extract the objectspace camerasposition. I actually miss it in GLSL :-(
    Also, ARB_vp offered a program environment where you could store data that is shared by _all_ vertex programs. Thereīs no such thing in GLSL, though :-(
    Finally I dislike that it is not possible to refer to a single row in a matrix. I really think, its more useful to have access to the rows of a matrix than its columns. Iīd also like to see built-in functionality that allows me to use:
    "attribute mat3 tangentspace;"
    but provide the ROWS for this matrix with the bound generic attribute streams.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264

    Re: inverse and transpose of matrices in glSlang state

    From the docs, you should be able to access rows and columns, but I just tested it on my machine, but it gives a compilation error.
    -----------------------
    mat3 m;
    m.00 = 1; // set the first element to 1.

    m.0_ = vec3 (1, 2, 3); // sets the first row to 1, 2, 3 .

    m._0 = vec3 (1, 2, 3); //sets the first column to 1, 2, 3 .
    --------------------
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Intern Contributor
    Join Date
    Sep 2001
    Location
    Marlboro MA
    Posts
    90

    Re: inverse and transpose of matrices in glSlang state

    V-man, you are looking at an old specification.

    mat4 foo;
    column1 = foo[0];
    row1 = vec4( foo[0][0], foo[1][0], foo[2][0], foo[3][0] );


    -mr. bill

    [This message has been edited by mrbill (edited 03-07-2004).]

    [This message has been edited by mrbill (edited 03-07-2004).]

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    666

    Re: inverse and transpose of matrices in glSlang state

    row1 = vec4( foo[0][0], foo[1][0], foo[2][0], foo[3][0] );
    smells like a very slow solution to me. I donīt know if the compiler catches the "idea" of what youīre trying to do here and is able to optimize it.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2004
    Posts
    18

    Re: inverse and transpose of matrices in glSlang state

    Originally posted by skynet:
    row1 = vec4( foo[0][0], foo[1][0], foo[2][0], foo[3][0] );
    smells like a very slow solution to me. I donīt know if the compiler catches the "idea" of what youīre trying to do here and is able to optimize it.
    Note that if a matrix really is stored in column major order (encouraged by the way OGL specs are written), then a matrix row really is 4 scattered floats. So, there is some connection between the ease of extracting a row vs. column and what's likely happening beneath the scene.

    However, in the end, this is implementation dependent, and the langauge would benefit from addition of more matrix extraction and manipulation tools.

    JohnK

  7. #7
    Advanced Member Frequent Contributor cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    913

    Re: inverse and transpose of matrices in glSlang state

    Something like this:

    inv_trans_mat = transpose( inverse( mat ) );

    should be straightforward to support if it is a purely a function of uniform variable(s).

    It could (and arguably should) be supported "for free" via constant folding at some point in the future.
    Cass Everitt -- cass@xyzw.us

  8. #8
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,932

    Re: inverse and transpose of matrices in glSlang state

    Nice idea, cass! Pure virtualisation I like it.
    If you will implement it, i will use it

  9. #9
    Advanced Member Frequent Contributor cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    913

    Re: inverse and transpose of matrices in glSlang state

    Originally posted by Zengar:
    Nice idea, cass! Pure virtualisation I like it.
    If you will implement it, i will use it
    Trust me, if developers write lots of expressions of uniforms, drivers will have to recognize them and supply them.

    Recomputing uniform expressions at every vertex or fragment is just not an option.

    Cass
    Cass Everitt -- cass@xyzw.us

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •