   Just want to get your ideas on simple terrain/shader.
  My game I am working on is a top down rpg game. The terrain will mostly be flat although I want to allow height in case during design I think of some good ideas that could use height and add to the game.Right now I have a shader that is primarily used for texturing the terrain. It seems to be working fine. I am now about to make the terrain move for walking or moving around the map. Anyways since my game will only ever have a small square chunk of it on screen at any point I have been trying to think about how I want to handle it. I really would like to allow my terrain to be of infinite size (width/length). So here are my ideas... If you guys have any better ideas or ways to improve on this let me know. :)A) I can just load the height map containing only the data for my current location and build the vertices every time I move and pass those to the shader for rendering textures. The downside of this is that since the terrain basically changes every time I move it becomes a performance hit. I don't think its too big of one as my terrain in screen is very small. Probably 20x20 vertices max. B) The other idea I can do is load the entire terrain and pass it to the shader. Then the vertices never change because the shader gets a flat 20x20 plane and modifies the height of the vertices/textures the terrain all in one pass based on location of the player. This should be good for performance but it limits the size of my terrain because well I cant pass in too much data to the card.C) I probably could combine A and B if the terrain becomes too big. I could pass in a big chunk of the terrain and only update it when I come to the edge of the currently loaded chunk. I am going to also throw in a shader question... If you load something like a texture to the video card through a shader and it doesn't change each frame does the video card somehow cache this? Do I specifically have to tell it to cache something? If so that would be the only way I could think the shader doing the height manipulation would be a performance boost.   
Quote:Original post by valleyman86A) I can just load the height map containing only the data for my current location and build the vertices every time I move and pass those to the shader for rendering textures. The downside of this is that since the terrain basically changes every time I move it becomes a performance hit. I don't think its too big of one as my terrain in screen is very small. Probably 20x20 vertices max. B) The other idea I can do is load the entire terrain and pass it to the shader. Then the vertices never change because the shader gets a flat 20x20 plane and modifies the height of the vertices/textures the terrain all in one pass based on location of the player. This should be good for performance but it limits the size of my terrain because well I cant pass in too much data to the card.C) I probably could combine A and B if the terrain becomes too big. I could pass in a big chunk of the terrain and only update it when I come to the edge of the currently loaded chunk. Take the best of A, B and C :-)1. Devide your terrain into tiles.2. Create a cache of X tiles (for texture and/or geometry).3. Each time you render your world, first lookup in your cache if your tile has already been loaded, if not , load it now.4. If the cache is overrunning, discard tiles (suggestion: LRU - least resent used).This way you can handle large terrains with minimal loading/updating costs. If your cache is large enough, you can walk around a town without reloading a tile a second time.Some extenions:Use a secondary thread to load and cache tiles near the edge of your visible view. This way, once the player moves in range of a new tile, the tile is most probably already loaded avoiding a short break while loading.Quote:I am going to also throw in a shader question... If you load something like a texture to the video card through a shader and it doesn't change each frame does the video card somehow cache this? Do I specifically have to tell it to cache something? If so that would be the only way I could think the shader doing the height manipulation would be a performance boost.You don't need to tell the video card to cache something, the driver will handle this for you. Just load the texture you need. There're still something you can consider to increase performance, like texture cache trashing or texture fetch coherence etc., but this is an more or less advanced topic. I I would sugguest to get your terrain rendering done first, then try to optimize it if you encounter low performance.;  Thank you for the awesome reply. You have been rated. :)   