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

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.

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

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.

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:

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) );

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

… 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 ???

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.

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.