Sign in to follow this  
greyroot

Texture binding costs?

Recommended Posts

I'm working on a rough idea for a terrain system and could use some feedback from the more experienced people around here. To start out, I'm using heightmaps for the terrain and using an quad tree approach to break it up into segments. The hope was to have one large texture that merges in all the required detail. Rather than worrying about dealing with tiling and having 5 different textures blended, I wanted to use one large texture breaking up the map into blocks and use varying sizes based on distance from the camera. Terrain that is near the camera would load say a 512*512 texture while things way out in the distance might only be 64*64 to have the rough colour. I keep reading about the cost of binding textures because of various reasons, but with all the video memory in graphic cards these days I was hoping to make use of what is available. I guess the question is this. Is the only way to make use of all the memory to have large atlased textures? How bad is the cost of using possibly hundreds of smaller textures? Is there a reasonable way that I can have a map that is (for example) a 20*20 grid of textures of varying sizes without taking a huge hit for constantly swapping them in and out for varying resolutions and repeatedly changing which one is bound each frame? Hopefully I'm explaining this in a way people can follow. Any input is appreciated.

Share this post


Link to post
Share on other sites
Quote:
Original post by greyroot
I guess the question is this. Is the only way to make use of all the memory to have large atlased textures?


You could use volumetric textures.

And I think DX 10 has some sort of texture atlas support.

Quote:
Original post by greyrootHow bad is the cost of using possibly hundreds of smaller textures?


Quite bad !

Every state change hurts and having to switch that many textures means also more draw calls which also slows things down considerably (at least it does for me in dx9).

Quote:
Original post by greyrootIs there a reasonable way that I can have a map that is (for example) a 20*20 grid of textures of varying sizes without taking a huge hit for constantly swapping them in and out for varying resolutions and repeatedly changing which one is bound each frame?


Could you explain that a little more in detail ?

I don't quite understand what you mean...

Share this post


Link to post
Share on other sites
Just as an example, a few years ago I made a breakout clone. A level consisted of about 100 bricks in a 10x10 grid. In an initial attempt, I was binding the one texture I was using 100 times per frame. Performance was, well, gash. I might as well be measuring in seconds-per-frame, rather than vice versa.

As Zaph said, state changes hurt. If you really want to maintain individual textures, how about stitching them together during a level load operation? That way, you don't have to bake a massive texture manually and you get to keep a good framerate.

Share this post


Link to post
Share on other sites
Well heres what I'm doing. Using http://www.bundysoft.com/L3DT/ for terrain, I'm generating a single large map texture thats broken into a grid. This is somewhat inspired by reading about Carmack's virtualized textures. I want to use those grid pieces per quad tree node at draw time. I can either have less wasted texture space by storing a larger number of smaller textures, or fewer larger textures. I say wasted because if I have larger textures its more likely that only a portion of them are in use.
What if I were to have a handful of textures in which I swapped out individual pieces of the atlas as necessary? Perhaps at most one grid segment per frame.

I just don't understand why there is so much video ram if there's no good way to use it.

Share this post


Link to post
Share on other sites
Quote:
Original post by greyroot
I just don't understand why there is so much video ram if there's no good way to use it.


There are many good ways to use the video ram they just are not usable for every kind of application.

^_^

As for the megatexture thingy from carmack (I think thats the one you mean, right ?) I think they will all probably be about the same size (except LoD, see below) so you could try to put the texture blocks in a volume texture and adress them all without switching textures.

You can handle the size differences for LoD by also choosing the appropriate mipmap (I think in the vertex shader) and managing the swapping (in and out) of the right maps in your code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this