Change polygon texture dependent on elevation

Hello,

I have a heightmap describing my terrain.
Highest Polygon is located at Y: 1.0f, Lowest: 0.0f

Furthermore Let’s say I have two textures I want to apply to my terrain. A red one and a blue one.

In addition I want all polygons where at least one vertex is at Y: 1.0f to apply the red texture.
Everyone else has to apply the blue texture.

What is the easiest way in OpenGL to achieve that?

I am working on an iPhone project… so it has to be a solution that works with OpenGL ES 1.1. (3D Textures don’t).

Furthermore it is important to note that my terrain is dynamic. Meaning the Y coordinates of the vertices change all the time. But only when they hit the top level (Y: 1.0f) I want them to appear red.

I’ve read about multitexturing… but I dont know if thats the best approach to achieve what I need.

Thank you,
Kevin

If you can use shaders (definitely in ES 2.0, not sure about 1.1), this can easily be done in a fragment shader. Use multitexturing as you suggested, and bind each texture to a different texture unit. Pass the world space Y from the vertex shader to the fragment shader, then read from the appropriate texture based on the world space Y. If you don’t have shaders I’m sure this can be done with a multipass approach, or maybe even a single pass.

Regards,
Patrick

Hello,

thanks for your reply.

The solution that works for me right now is:
I have two color arrays defined.
I draw all my polygons twice. Once with texture1 and color array1 applied. Once with texture2 and color array2 applied.
The color array only defines which polygons are translucent or opaque.

It works but I am not sure about performance issues. It seems like it slowed things down a lot…

I will try to figure out how this multipass thing works. Thanks.

Best Regards,
Kevin