Creating heightmap of an existing terrain-mesh?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Robat
Posts: 10
Joined: Tue May 16, 2006 7:51 am
Location: Hamburg

Creating heightmap of an existing terrain-mesh?

Post by Robat »

Hi all,

I don't know if this is the right topic for the advanced forum. I have an existing terrain-mesh modeled in max and exported to a directx-file. I want to use the cool grass node system presented by bitplane and tried to create a heightmap from my terrain.
So far i have written the height of all vertices to an image, translating it to greyscale values. but I don't know how to interpolate the greyscale values between the vertices positions. Is there any other plan how to sample the height of a mesh? I mean, not sampling the vertex positions, but the triangles heights at the sampling point. Can this be done with the triangleselector? Didn't find any function for that.

Thanks

Robert

This is my code so far:

Code: Select all

		aabbox3d<float> myBB = pTrackMesh->getBoundingBox();
		const u16 WIDTH = 512;
		const u16 HEIGHT = 512;
		float minEdgeX_terrain = myBB.MinEdge.X;
		float minEdgeZ_terrain = myBB.MinEdge.Z;
		float minEdgeY_terrain = myBB.MinEdge.Y;
		float maxEdgeX_terrain = myBB.MaxEdge.X;
		float maxEdgeZ_terrain = myBB.MaxEdge.Z;
		float maxEdgeY_terrain = myBB.MaxEdge.Y;
		float dimX_terrain = maxEdgeX_terrain - minEdgeX_terrain;
		float dimY_terrain = maxEdgeY_terrain - minEdgeY_terrain;
		float dimZ_terrain = maxEdgeZ_terrain - minEdgeZ_terrain;
		float indexX_map, indexZ_map;
		vector3df vertexPos;
		float greyValue;
		int index;
		dimension2d<s32> size; 
		size = dimension2d<s32>(WIDTH, HEIGHT);
		RGB_PIXEL pixels[WIDTH*HEIGHT];
		for (int b = 0; b < pTrackMesh->getMeshBufferCount(); b++)
		{
			IMeshBuffer* pMeshBuffer = pTrackMesh->getMeshBuffer(b);
			void* vertices = pMeshBuffer->getVertices();
			for(int a = 0; a < pMeshBuffer->getVertexCount(); a++)
			{
				//get Pos of a single vertex
				vertexPos = ((S3DVertex*)vertices)[a].Pos;
				//get Pos on height map
				indexX_map = u16((vertexPos.X - minEdgeX_terrain) * WIDTH / dimX_terrain);
				indexZ_map = u16((vertexPos.Z - minEdgeZ_terrain) * HEIGHT / dimZ_terrain);
				greyValue =  (vertexPos.Y - minEdgeY_terrain) * 256 / dimY_terrain;
				index = int(indexZ_map * WIDTH + indexX_map);
				pixels[index].r = u8(greyValue);
				pixels[index].g = u8(greyValue);
				pixels[index].b = u8(greyValue);

			}
		}

		IImage* myImage = pDriver->createImageFromData(ECF_R8G8B8, size, pixels, true);
		pGuienv->addImage(pDriver->addTexture("TEST", myImage), position2d<s32>(50, 50));
In Spain rain falls mainly on the plain.
MarkusBergqvist
Posts: 5
Joined: Mon Apr 10, 2006 9:48 pm

Post by MarkusBergqvist »

Maybe you can just render a z-depth pass from Max?
Post Reply