So I'm writing a small game using Direct3D 9 and I'm using multitexturing for the terrain. All I'm doing is sampling 3 textures and a blend map and getting the overall color from the three textures based on the color channels from the blend map. Anyway, I am getting a massive frame rate drop when I sample more than 1 texture, I'm going from 120+ fps to just under 50.

This is the HLSL code responsible for the slow down:

float3 ground = tex2D(GroundTex, multiTex).rgb;
float3 stone  = tex2D(StoneTex, multiTex).rgb;
float3 grass  = tex2D(GrassTex, multiTex).rgb;
float3 blend  = tex2D(BlendMapTex, blendMap).rgb;

Am I doing it wrong ? If anyone has any info or tips about texture sampling or anything, that would be nice.


  • \$\begingroup\$ What hardware do you have? Four texture samples shouldn't be a problem on any new hardware. \$\endgroup\$ – Axel Gneiting Oct 27 '10 at 13:20
  • \$\begingroup\$ I have a Radeon X1950, yeah it's a couple years old, if not more. I'm guessing it's maybe not the best hardware. What do you think ? \$\endgroup\$ – dotminic Oct 27 '10 at 16:26

If you want to speed things up you can use something called a texture atlas.

Wikipedia — A texture atlas is a large image, or "atlas" which contains many smaller sub-images, each of which is a texture for some part of a 3D object. The sub-textures can be rendered by modifying the texture coordinates of the object's uvmap on the atlas, essentially telling it which part of the image its texture is in. In an application where many small textures are used frequently, it is often more efficient to store the textures in a texture atlas which is treated as a unit by the graphics hardware.

It is more efficient for a GPU to sample a single large texture 4 times versus 4 images sampled once each. Here is an example of a terrain texture atlas.

alt text

  • 1
    \$\begingroup\$ Thanks for the advice, I've implemented my shader using a texture atlas, I'm "only" getting a 109fps now, but it's a neat improvement from the 55fps I was getting. Thanks! \$\endgroup\$ – dotminic Oct 23 '10 at 2:21
  • 1
    \$\begingroup\$ +1 for a good answer. May I ask where you got that texture atlas image? Is it proprietary or free for any use? \$\endgroup\$ – Cameron Jul 5 '12 at 19:38
  • \$\begingroup\$ One disadvantage of texture atlases is that you must be very careful when calculating texture coordinates. The situations where you got decent picture with normal textures and GL_CLAMP_TO_EDGE sampler mode may bite you when you switch to texture atlases: you may get ugly borders containing texels from neighboring textures blended in. The problem becomes even worse if your sub-textures are non-power-of-two in size and you use MIP mapping. In this case being careful with texture coordinates won't help you, since the MIP levels themselves will be contaminated with neighboring textures. \$\endgroup\$ – Ruslan Jun 2 '20 at 8:14

Another thing to consider is the texture format. Is it a raw 32bpp texture? If so, consider using a compressed DXT1 texture, which is 4 bits/pixel (taking 1/8th of the space), or DXT5 if you need the alpha channel, at 8 bits/pixel.

Reducing the size of the texture data should result in reduced texture memory bandwidth requirements, and improved texture cache performance.

Also, check that you've not setting maximum quality anisotropic filtering - that can add a fair bit of cost.

  • \$\begingroup\$ thx for the advice, I'll give that a try next time. \$\endgroup\$ – dotminic Jan 5 '11 at 13:50

Do your textures have mipmaps?

Without mipmapping, texture sampling can be particularly expensive (loads of cache misses)

  • \$\begingroup\$ Yep the textures have mipmaps, I exported them as a *.dds from the DirectX texture tool. But how do they use textures in commercial games where there are loads of high def textures all over the place ? I'm just sampling 1 texture atlas and getting a frame rate of 109 fps while rendering a terrain, all on the gpu. \$\endgroup\$ – dotminic Oct 27 '10 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.