Leadwerks
12-08-2007, 05:23 PM
This is an old problem that has bugged me for a long time.
It isn't difficult to figure out how to render layered terrain, but it is difficult to render it efficiently.
Right now I am thinking about doing this:
First render or calculate a top-down low-res texture of the entire terrain, maybe 1024x1024. Beyond a certain distance, render the terrain with this low-res texture instead of doing any blending.
Terrain that is nearer can be rendered in one pass by using a shader that blends as many as four textures together. The texture alpha values can be stored in a single RGBA texture with a linear filter and no mipmaps. The red channel indicates the first texture alpha level, the green channel indicates the second, and so on.
Terrain sectors can be calculated so that if only 2 texture appear on a sector, it will use a version of the shader that only does lookups for two textures. This can be handled using GLSL defines. If more than four textures appear on any one sector, the engine will only use four.
This seems like a pretty good setup, but I was wondering if anyone had any other ideas on this. I have read lots of articles on how to do the basics, but it is harder to make it fast. I have been thinking about either texture arrays or atlases, but the parts where two or more texture blend together makes those ideas very complicated.
It isn't difficult to figure out how to render layered terrain, but it is difficult to render it efficiently.
Right now I am thinking about doing this:
First render or calculate a top-down low-res texture of the entire terrain, maybe 1024x1024. Beyond a certain distance, render the terrain with this low-res texture instead of doing any blending.
Terrain that is nearer can be rendered in one pass by using a shader that blends as many as four textures together. The texture alpha values can be stored in a single RGBA texture with a linear filter and no mipmaps. The red channel indicates the first texture alpha level, the green channel indicates the second, and so on.
Terrain sectors can be calculated so that if only 2 texture appear on a sector, it will use a version of the shader that only does lookups for two textures. This can be handled using GLSL defines. If more than four textures appear on any one sector, the engine will only use four.
This seems like a pretty good setup, but I was wondering if anyone had any other ideas on this. I have read lots of articles on how to do the basics, but it is harder to make it fast. I have been thinking about either texture arrays or atlases, but the parts where two or more texture blend together makes those ideas very complicated.