Jump to content
  • Advertisement
Sign in to follow this  

Heightmap Texturing Methods

This topic is 3471 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm building a heightmap that loads a given height (texture) file and generates the vertex array and index array for the vertices generated from the heightmap. Furthermore, each vertex is coloured based on height and angle (e.g. blue for water, green for grass, etc.) and then lit according to the global light position/direction and light colour & ambience. So far so good. Now, I've done a lot of background reading on the matter of various techniques to texture terrain (multitexturing or otherwise) but there's one thing that's stumping me that doesn't seem to to be explained in these sources: how to store/draw the data. My problem is thus: currently, the terrain is being drawn from an indexed array spanning the entire heightmap. What I plan to do is implement a quad/octree for frustum culling and aiding in (future implemented) UI such as slecting terrain, elevating it etc. How do I store my data for use with multitexturing? If each tile can have up to x textures (thus I need to use n texture stages for texture + blending), I would have to setup texture stages per triangle rendered, like so: DrawTerrain() { ActivateTex0(); /// stuff ActivateStage1(); // stuff .... ActivateStageN() // Stuff Begin(Triangles); TexCoord(u,v); Colour(r,g,b); Vertex(x,y,z); TexCoord(u,v); Colour(r,g,b); Vertex(x,y,z); and so on... End(); // Shutdown texture stages etc. } I guess what I'm trying to say is, what options so I have available? Currently my untextured terrain rendering is something like follows: DrawTerrain() { SetupVertexArray(); SetupColourArray(); DrawIndexedArray(Triangles, numTriangles, indices); // Shutdown arrays etc. } The DrawIndexedArray() literally draws the entire contents of the vertex/colour arrays. Clearly this will be broken down into more managable tiles for use in the quad/tree, and maybe put in a VBO or something. Am I right in saying that this approach isn't an option for blending multiple textures per triangle? Hope that makes sense :D

Share this post

Link to post
Share on other sites
I'm having a little trouble deciphering your question since you went off in so many directions, but I guess you are just trying to multi-texture.

If you are using DirectX, read on. If not, just ignore me.

The Direct3D texture cascade is really just a chain of calculations that each use two small pipelines for color and alpha. You specify up to 3 arguments for each pipeline, labeled as Argument0, 1 and 2. Most operations done in a "stage" or a single calculation in the cascade use 1 and 2.

Only one stage in the cascade (stage 0) is active by default, and it makes use of the texture, UVs it's given if you don't touch anything.

As for storing and drawing? It's easy. Just make sure you set the device's textures to the appropriate order in their stages and draw your primitives.
Justmake sure for storage, you have the correct number of textures loaded and accessible. That's based on your app.

pDev->SetTexture(0, &TerrTex);
pDev->SetTexture(1, &DetailTex);

You won't be able to accomplish this since I'm guessing you are not storing texure coordinates in your FVF, just color components. You would want to make sure the UVs for your terrain over stage 0 are beyond texture space if you are going to be applying detail maps, so make sure you declare the FVF you use with D3DFVF_TEX2 or higher.

Honestly, I cannot go any further without diving into the different operations and how you must check device capabilities, so I would recommend you research this topic yourself. All I've really done here is blab off some facts in semi-random order. I don't think anyone else here could really help you with the code you provided, since it's really, really vague. I don't meant to offend, but please rephrase your question and maybe you'll get a better answer.

Share this post

Link to post
Share on other sites
Ok, after some more research on the net I have crytalised my thoughts a bit more. Here's currently what I've got going on:

* vertex and index data for heightmap generated from image file
* vertex normals for each vertex and face normals for each tri (not really used)
* colour data for each vertex generate from vertex height (and slope factor)
* luminance data generated from light pos/colour and vertex normal
* final lit vertex colour data generated from luminance and vertex colour

Currently I am doing something like this (in openGL):

> Enable vertex array
> Enable colour array
> Draw triangle list from supplied index data
> Disable vertex array
> Disable colour array

This give me a lit and coloured terrain as follows (ignore the height shading, basic prototype at the moment):


What I want to do is instead of colouring the terrain per vertex, I want to texture the terrain based on height and angle (like the colour is currently calculated).
Hi zyrolasting, thanks for the reply!

I've read that I could use 3d textures (which seems the most simple solution), or I could multi texture the terrain a la splatting.

So, currently my vertex RGB data contains the lit vertex colour. For splatting, I believe I need some textures and an associated blend map per texture. This is the new source of my confusion...

With the blend maps, I could use the 4 colour components (colour + alpha) in one texture to blend between 4 textures. Does this texture map have to be generated for each triangle, or would it make more sense to group triangles into tiles of, say, 32x32 in size and then create a blend map for that batch of tiles? or would I do one for the whole terrain (e.g. 512x512 terrain = 512x512 blend map)? This way, each texel in the map corresponds to each vertex in the height map, and the r,g,b,a components contain the blend info for 4 textures)?

Alternatively, I guess I could use the vertex r,g,b,a components as my blend values and then light the terrain via a terrain-sized lightmap.

I'm just tossing ideas around as this topic is new to me so I'm trying to digest my thoughts and see what other people are doing with regards to texturing terrain :D

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!