Rendering 3D terrain with more than one texture

I want to render a 3D terrain with more than one textures, say 2. One texture will be used for all the terrain except for a rectangular area in the middle of the terrain that will use the second texture.
Now the point is that I don’t want to change the geometry (split triangles and so on). I want it to be rendered on a per fragment basis. Is there an efficient way to do it besides using shaders? One pass redering? :confused:
Hope the question is clear enough…
Thanks

You could have a third texture to specify which areas of the terrain should have which texture (or even blend between the two), using the INTERPOLATE_ARB texture combiner (see http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt )
Having said that, for the problem you describe splitting the geometry would be far more efficient.

Originally posted by yossi:
I want to render a 3D terrain with more than one textures, say 2. One texture will be used for all the terrain except for a rectangular area in the middle of the terrain that will use the second texture.
Now the point is that I don’t want to change the geometry (split triangles and so on). I want it to be rendered on a per fragment basis. Is there an efficient way to do it besides using shaders? One pass redering? :confused:
Hope the question is clear enough…
Thanks

The way I typically do this type of insert work is the use an eye linear texgen to generate the tex coords for the second texture unit, and have this texture unit be the insert.

You could do all this with standard OpenGL, there isn’t any need for shaders.

Robert.

Thanks guys for your answers.
Robert, can you be more specific. Didn’t quite understand the method. No need for a third texture?

you don’t need a third texture - you can use the alpha channel of either of the two textures.

It depends on how many textures you need put on your surface. You can always use multipass techniques, but it will get slow for a large number of textures. If you only want a few textures you can use the multitexturing technique and render them in one pass. With multitexturing you are limited to 32 textures by the language and probably some other lesser amount by your card. If you want to render more than 32 textures and you want to do it in one pass you can load all your textures into one texture and write your own fragment shader to access the right pixels. You need a card that can do dynamic loops or you won’t have enough memory for the fragment shader.

I’m still trying to figure the best way to do this myself.

Thanks again guys.
wgl000, I guess that accessing (binding) a different texture in a shader for each fragment has quite a big overhead.
I don’t get close to the OGL limitation. need only as much as four textures.

I would probably use multipass - if in each pass you will render only these polygons that use given material you won’t have that much of a performance drop. It would be very rare to mix more than two materials at one polygon, so each polygon will be drawn averagely less than 2 times.

It depends on how long it takes you to draw it with one texture. If you get 120 frames per second with one texture than you should be able to get 30 frames per second with four textures using multipass and you’re fine. If it’s slower than that then you might want to look at multitexturing. It’s not much of a change in your code if you already have multipass written. You set which texture you want to use (glActiveTexture), knock out the blend functions, and draw only once after all the textures have been set up. I don’t know for sure, but I suspect that all cards being made today support at least 4 textures.