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 4 of 4

Thread: normalize, textureXD textureXDProj

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

    normalize, textureXD textureXDProj

    This might be a stupid question but what is the defined behavior of normalize?

    I'm assuming

    normalize(float thing) = 1.0
    normalize(vec2 thing) = thing/length
    normalize(vec3 thing) = thing/length
    normalize(vec4 thing) = thing/length or maybe
    normalize(vec4 thing) = vec4(vec3(thing)/length_of_vec3, 1.0)

    and if a vector is of length = 0.0, result is a NULL vector.

    =================================
    Part deux

    What about textureXD vs textureXDProj.

    In ARBfp, I used TXP to take the effect of projection into account. TEX gave incorrect results.

    In GLSL, texture2D works.

    Which to use and when?
    ------------------------------
    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);

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

    Re: normalize, textureXD textureXDProj

    Originally posted by V-man:
    This might be a stupid question but what is the defined behavior of normalize?
    Not a stupid question. Normalizing a zero length vector is undefined.

    I'm looking at the documentation (even of several shading languages) and all are ambiguous here. I thought I'd get bailed out on inversesqrt( 0.0 ), but no....

    Which to use (texture2D or texture2Dproj) and when?
    Perhaps the best way to think of it is this way:
    Code :
    vec4 texture2DProj( sampler2D sampler, vec3 coord )
    {
        return texture2D( sampler, coord.st/coord.p );
    }
    // Or...
    vec4 texture2DProj( sampler2D sampler, vec4 coord )
    {
        // coord.p is ignored!
        return texture2D( sampler, coord.st/coord.q )
    }
    Which do you need? Well, that depends.

    If you know your q component is always 1.0, you might as well do the non-projective fetch. And you often *do* know this. For example, in fixed function if you are providing texture coordinates with glMultiTexCoord2f[v] or glMultiTexCoord3f[v], you are not using texgen, and your texture matrix is identity.

    Otherwise, it still depends. What does your algorithm require? A projective or non-projective fetch?

    -mr. bill

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

    Re: normalize, textureXD textureXDProj

    I think your pseudo code for normalize is correct.

    vec4 thing;
    normalize(thing);

    is done like so

    r *= invsqrt(dot4(thing, thing));

    so one has to be careful on the type of "thing".

    =============================================

    I guess I was mistaken about ARB_fragment_program.

    If tex coord is (x, y, 0, 1) then
    TEX and TXP give the same results.
    I'm talking about plain 2D texturing a la glTexCoord2f

    I could have sweared TEX and TXP didn't give the same result when I was learning that stuff... hmmm

    and it looks like it's the same with texture2D and texture2DProj

    So the effect of the projection matrix is taken into account automatically I suppose.
    Just to be clear, I'm talking about perspective correct texturing here.
    ------------------------------
    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
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,345

    Re: normalize, textureXD textureXDProj

    Originally posted by V-man:
    normalize(vec4 thing) = thing/length or maybe
    normalize(vec4 thing) = vec4(vec3(thing)/length_of_vec3, 1.0)
    I haven't read up in the spec, but it should definitely be the first one. It just makes more sense, plus that normalizing a four-component vector is useful functionality that there's no reason to leave out from the spec. The second normalizing behavior can be done anyway with vec4(normalize(thing.xyz), 1.0);

Posting Permissions

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