• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

# Calculating normals between heightmaps

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Zaoshi Kaba  Crossbones+   -  Reputation: 4426

Like
0Likes
Like

Posted 23 May 2013 - 12:56 PM

Hello,

First of all I wasn't sure whether to post here or in graphics forums; it's related to graphics but problem is general programming.

I need to calculate normals for heightmap (I know how it's done), however my heightmaps are stored separately (a lot of 128x128), so if I calculate normals individually they won't connect well where heightmaps join. I store heightmap data in this structure:

struct HeightmapData {
XMVECTOR positions[constant][constant];
XMVECTOR triangleNormals[constant][constant];
XMVECTOR vertexNormals[constant][constant];
};


Currently I have function vector<Vertex*> getVertex(int x, int z) which loops through all heightmaps, finds all vertexes at (x,z) (they duplicate where heightmaps connect) and returns them, allowing me to basically unite all heightmaps into one big one. However that's extremely slow. Can anyone suggest a better way to correctly calculate normals between heightmaps?

### #2phil_t  Crossbones+   -  Reputation: 3945

Like
1Likes
Like

Posted 23 May 2013 - 01:44 PM

Maybe you can implement a "virtual heightmap" class which has the the needed operations on it (e.g. "get me the height at (x, y)"), and internally delegates to the appropriate 128x128 height map. Then perform your normal calculations using that.

The one problem with that is that you have duplicated vertices along the edges. This shouldn't matter for retrieving the height (just pick any of them, since they should all have the same height). For setting back the normals at a particular location though, you'd need to set it for possibly multiple heightmaps.

Alternately, much easier would be to calculate your normals before you split your world into 128x128 chunks. Is that possible? In what form is the data originally?

### #3Zaoshi Kaba  Crossbones+   -  Reputation: 4426

Like
0Likes
Like

Posted 23 May 2013 - 02:29 PM

I think I understand what you're trying to say, sounds like it's going to work, I'll give it a try, thanks!

Originally it is in 128x128 chunks, currently I have stupidly large map, which results in 14 million triangles. Splitting it was the only option (or maybe just easiest).

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS