Slow preformance when textures are scaled down

Hello,

When using texture splatting on my terrain i wrap the texture, of for instance grass, multiple times on top of the terrain to get a more detailed terrain. In the custom shader i then get the correct pixel from the texture by simply multiplying texcoord0 by the scale factor (k_wrap):

float4 tex1=tex2D(k_texgrass,l_texcoord0*k_wrap);

For some reason the computer runs very slow when i use a large number for the scale factor. I do not see why; the graphics card still only has to run this function once for every pixel (or fragment), and it will physically not even notice whether the texture is wrapped on the terrain 10 or 20 times (or 50 for that matter).

The only thing i can think of is that for some reason the graphics card calculates for each pixel multiple texture colors and then takes the average. When the texture is wrapped more often, it will, for some reason, take more texture colors per pixel which takes more computing time. The problem may lie in a pixel beeing build up out of multiple (shader)fragments.

If i am correct, how can i counter this, and if i am incorrect then what is the problem?

Thanks in advance!
Stein

There are usually (small) performance differences in downscaling a texture considerably, because the fragment shader then has to consult wildly divergent parts of texture memory, blowing memory cache performance. You can generally solve this by enabling mipmapping on your texture.

I wouldn’t expect it to suddenly run “very slow” because of this effect, though.

David

wow that worked like a charm, thanks a lot! Could you please explain to me the fundamental difference between the automatic way of rendering and with the use of:

setMinfilter(Texture.FTLinearMipmapLinear)

(im still expreciencing a very small latency in some extreme cases though i am using a total of 18 textures on the terrain, 10 of which are scaled (and 8 are alpha maps). I realise that is not going to be realistic, but i’m just testing the limits)

Mipmapping is a complex subject that is well-documented in many places on the web–you could start with Wikipedia for a good introduction. :slight_smile:

In a nutshell, mipmapping means the graphics driver keeps several different copies of the texture resident, one at each of several different sizes. When it looks up the texture color, it looks it up in the copy that is the closest match to the required scale (to oversimplify a bit). This means that adjacent pixels on the screen are drawn from physically adjacent locations in memory, which is important for good performance. It also tends to look better. :wink:

David

Ok, thanks again!