3 Replies Latest reply on Jun 28, 2010 12:20 AM by frali

    GLSL mat3 contructor fails (produces wrong result)

    lizardq

      The mat3 contructor fails (produces a wrong matrix) inside the fragment shader if passed a variable argument at particular positions. See following code...


      mat3 pitchMat( const float angle )
      {
          float s = sin( angle ), c = cos( angle );

      // does not work:
      // return mat3(1, 0, 0, 0, c, -s, 0, s, c );

      // workaround:
          mat3 m = mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1 );
          m[1][1] = c; m[2][2] = c; m[1][2] = -s; m[2][1] = s;
          return m;

      // interstingly, this works:
      // return mat3( c, 0, -s, 0, 1, 0, s, 0, c );
      }


      Catalyst 10.5 on a Mobility Radeon HD 4350 inside an HP notebook.

      (I've been pointed to this forum by AMD tech support with the following "explanation": AMD Customer Care does not currently offer support or troubleshooting in OpenGL development software. ?!?)

        • GLSL mat3 contructor fails (produces wrong result)
          frali

          Could you please tell me which value is wrong? I did a test on your function by making the value of "angle" to 0, the returned matrix is
          1   0   0
          0   1   0
          0   0   1

          That's as expected. 

            • GLSL mat3 contructor fails (produces wrong result)
              lizardq

              Unfortunately I don't have the actual numbers that ended up in the matrix. This function is part of a larger shader that does some texture lookup tasks in a panoramic imaging context. The broken image result had some kind of "spiral"-effect (instead of beeing simply rotated).

              The weired thing was, that my very simmilar yawMat and rollMat functions work flowlessly.

              It looks like you simply can't reproduce the problem, since I witnessed the "spiral" also using the following code:

                  float c = 1.0;
                  return mat3(1, 0, 0, 0, c, 0, 0, 0, c );

              So the only thing that mattered was whether there is a variable argument at a particular position of the constructor.

              Unfortunately, this happened on a client's machine, where I can only get remote access to involving the client...