Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 33

Thread: Quaternion functions for GLSL

  1. #11
    Junior Member Regular Contributor oc2k1's Avatar
    Join Date
    Jan 2007
    Location
    germany
    Posts
    171

    Re: Quaternion functions for GLSL

    OK bad description. It's no problem to convert a quaternion to a matrix. Sometimes, it isn't needed to calculate the full matrix, because only the 3rd vector (Normal) is needed. Calculating this vectors directly is faster than the rotating function.

    Converting a vector to a quaternion is not possible without a second vector, because a quaternion describes a rotation around a vector. (One value is missing).

  2. #12
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: Quaternion functions for GLSL

    Sometimes, it isn't needed to calculate the full matrix, because only the 3rd vector (Normal) is needed.
    Forgetting the question of when these times are, the "third vector" of a matrix does not have a name. You can give it a name, but only because your specific application gives that particular vector meaning.

    As such, this is not a very generalized use of quaternions. Furthermore, you can get this value easily enough by rotating the unit z-axis by the quaternion.

  3. #13
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: Quaternion functions for GLSL

    I saw a paper once that suggested using quaternions instead of normals for per-pixel lighting. That is, the vector shader will output a quaternions instead of a vector and teh pixel shader will turn the interpolated quaternion back to a vector. They claimed this will result in a better image quality (If I got it right, I just flew it over).

  4. #14
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: Quaternion functions for GLSL

    That is, the vector shader will output a quaternions instead of a vector and teh pixel shader will turn the interpolated quaternion back to a vector.
    For pure per-pixel, that might work. However, bump mapping requires a matrix, as the normal/binormal/tangent triple is not necessarily orthogonal to one another.

    I'm not really sure what you'd get for using a quat, though. The only approximation that per-pixel lighting makes is linearly interpolating the normal between the 3 vertices. A quaternion could be SLERP-ed between the 3 verts, but that would require a specialized interpolated. Otherwise, I don't see what this buys you in terms of image quality.

  5. #15
    Junior Member Regular Contributor oc2k1's Avatar
    Join Date
    Jan 2007
    Location
    germany
    Posts
    171

    Re: Quaternion functions for GLSL

    In many cases SLERP is an overkill. Examples with meaningful used quaternions are BRDFs combined with bumpmapping or deferred rendering with BRDFs.
    The problem with BRDFs or other advanced lighning modles is, that some vectors have to be projected into the texture space. In all that cases the needed 3x3 rotation matrix has some disadvantages:
    For deferred shading are 6 components (3 can be drooped) for a matrix much more bandwith intensive than 4.
    for Bumpmapping with BRDFs the normalmap wouldn't be enough, an additional Tangentmap would be required to create a new full texturespace. A quaternionmap is much easier to handle.
    Another gain is that quaternion based bonesystems needs less uniform variables than matrix based systems and the quaternion multiplications are cheaper than the (sometimes hidden) matrix multiplications.

    Here is a screenshot from a bumpmapped BRDF material:
    http://img205.imageshack.us/img205/693/lumina97zs1.jpg

  6. #16
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: Quaternion functions for GLSL

    Actually I find it much cheaper to project the normal to the world space. Or even better, quit using the normal maps, they are a hack anyway. I like perturbation maps for displacing the normals

  7. #17
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: Quaternion functions for GLSL

    For deferred shading are 6 components (3 can be drooped) for a matrix much more bandwith intensive than 4.
    As I pointed out, the NBT matrix for transformation into texture space is not necessarily orthonormal. As such, it cannot be expressed as a quaternion.

    Another gain is that quaternion based bonesystems needs less uniform variables than matrix based systems and the quaternion multiplications are cheaper than the (sometimes hidden) matrix multiplications.
    I'm not against using quaternions at all. I was specifically talking about what it means for a quaternion to replace a normal.

    Or even better, quit using the normal maps, they are a hack anyway.
    A "hack"? No more than "perturbation maps". Indeed, normal maps are less of a hack than that; at least they're modelling something real.

  8. #18
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Quaternion functions for GLSL

    Actually I find it much cheaper to project the normal to the world space. Or even better, quit using the normal maps, they are a hack anyway. I like perturbation maps for displacing the normals
    I find that it's cheaper to do calculations in tangent space because you do some more work in the vs and pass varying to the fs.
    It balances out better.

    How is pertubation map better?

    They are all hacks.
    The true solution is to use a high detail model. Then your depth values in your z-buffer will be more correct and even your physics will be more accurate if you use the same high detail model.
    ------------------------------
    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);

  9. #19
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Quaternion functions for GLSL

    are "perturbation maps" what I think they are?
    Knackered

  10. #20
    Junior Member Regular Contributor oc2k1's Avatar
    Join Date
    Jan 2007
    Location
    germany
    Posts
    171

    Re: Quaternion functions for GLSL

    We can't read your brain.... and we should go back to quaternion functions for GLSL...

Posting Permissions

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