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: quicker texture access

  1. #1
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    quicker texture access

    ok ive coded up a shader that does bumpmaping (the great advantage of doing this in a shader is the abilty to combine heights together easily)

    anyways its quite slow ~4x slower than standard bumpmaping the main reason i think is cause of the multiple texel fetchs

    in the following code i have access to the following 4 texels

    vec4 l = texture2D( tex0, gl_TexCoord[0] + vec2(-offset,0) );
    vec4 r = texture2D( tex0, gl_TexCoord[0] + vec2( offset,0) );
    vec4 t = texture2D( tex0, gl_TexCoord[0] + vec2( 0,-offset) );
    vec4 b = texture2D( tex0, gl_TexCoord[0] + vec2( 0, offset) );

    is there no way to get this data with one call?
    also its a bit of overkill returning a vec4 when all tex0 returns is a single float (the height), is there any more streamlined method?

    anyother ides
    ------------------------------------------

    also with the following warnings returned from the shader parser

    44 lines, 4 warnings, 0 errors.
    Fragment info
    -------------
    44 lines, 4 warnings, 0 errors.

    is there anyway i get find out what the warnings are? (sometimes it lists the exact warning but sometimes it doesnt)

    cheers zed

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: quicker texture access

    Preprocess the height map and put the center sample in the red channel, and the neighbors in the green, blue, and alpha channels. Then you get all four heights with a single texture lookup.

    Those warnings are probably caused by this:

    gl_TexCoord[0] + vec2(-offset,0)

    where you are adding a vec4 to a vec2. Change that code to this:

    gl_TexCoord[0].xy + vec2(-offset,0)

    and the warnings should dissapear.

  3. #3
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    Re: quicker texture access

    that would work but unfortunatly im using the RGB for the diffuse colors im using the A to store the heights

    >>where you are adding a vec4 to a vec2. Change that code to this:
    gl_TexCoord[0].xy + vec2(-offset,0)<<

    thanks for that ill try it

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: quicker texture access

    It would also use four instructions less per fragment if you do the offset calculation at the vertex level in four different texcoords and use gl_TexCoord[0] to [3] that way to do the final adjusted lookup.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: quicker texture access

    If you calculate the offsets in the vertex shader, make sure to use as few interpolators as possible.

    So if you need to output 4 vec2 texture coordinates, pack them into two interpolators:

    Code :
    gl_TexCoord[0].xy = texcoord + vec2(-offset,0);
    gl_TexCoord[0].zw = texcoord + vec2( offset,0) );
    gl_TexCoord[1].xy = texcoord + vec2( 0,-offset) );
    gl_TexCoord[1].zw = texcoord + vec2( 0, offset) );

  6. #6
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    Re: quicker texture access

    thanks guys though
    >>It would also use four instructions less per fragment if you do the offset calculation at the vertex level in four different texcoords and use gl_TexCoord[0] to [3] that way to do the final adjusted lookup<<

    im not really sure if this will work in my case, ill have a play around with it when i get home

  7. #7
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: quicker texture access

    .. hmm .. i hope i don't make me a fool .. but for bump mapping your using these texel ??? so you are generating your normal map in your shader ??? why ??? is there any advantage ???

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    SWEDEN
    Posts
    601

    Re: quicker texture access

    You could use the partial derivative instructions on a variable holding the center texel of your heightmap and then a cross product to give you a normal if that's what you need. Partial derivatives aren't supported by ATi though (shame on you ATi! :-)) and it might look slightly pixelated due to the differencing used to compute the derivatives.

  9. #9
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    Re: quicker texture access

    i done the method relic suggested (which works, ill keep it in mind) but doesnt really speed things up cause i assume its the texture fetchs that are causing the slowdown.
    '??? why ??? is there any advantage ???'
    addition of bumpmaps is the major one, also with ojne texture u can hold the colors and also the bumpmap which is neat.

Posting Permissions

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