PDA

View Full Version : quicker texture access



zed
05-31-2004, 06:09 PM
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

jra101
05-31-2004, 06:27 PM
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.

zed
05-31-2004, 06:37 PM
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

Relic
06-01-2004, 12:27 AM
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.

jra101
06-01-2004, 08:14 AM
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) );

zed
06-01-2004, 08:26 PM
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

andreasMank
06-01-2004, 09:38 PM
.. 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 ???

harsman
06-01-2004, 11:01 PM
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.

zed
06-02-2004, 07:56 PM
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.