L3DT users' community
Large 3D terrain generator

Creating vertex normals from TN map

Correspondence concerning plugins and scripts; development, use, bugs and ideas.

Creating vertex normals from TN map

Postby miko » Fri May 13, 2011 4:44 pm

Hiya there,
I'm currently trying to retrieve a pixel from the terrains TN map (normal map) and create vertex normals from its value for my exporter.
Like so:
Code: Select all
ZMAP nmMap = zproj_GetMap("TN");
float fPixel;
zmap_GetPixel(nmMap, i, j, &fPixel);
// Now, I would somehow need to convert fPixel value to a rgb value (preferably of ColourPixel type),
// so I could calculate my own normal vector from that.

Not really sure how to convert the fPixel variable.
Or - as it is 32bit (I reckon), just pass in an UINT and trim to 24bit (color value)?

You see, I'm a bit confused :mrgreen: Any help appreciated...
Contributing member
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Re: Creating vertex normals from TN map

Postby Aaron » Sun May 15, 2011 4:13 am

Hi Miko,

The pixel type for a TN map is declared in the header file thusly:

Code: Select all
typedef struct { signed char x, y, z; } vector3c;

Each vector component ranges from -128 to 127. To convert to RGB, simply add 128 to each value, i.e:

Code: Select all
vector3c v; // your terrain normal vector
zmap_GetPixel(nmMap, i, j, &v);

ColourPixel col; // your colour pixel
col.r = v.x + 128;
col.g = v.y + 128;
col.b = v.z + 128;

zmap_SetPixel(colMap, i, j, &col);

Please note however that since the TN map is usually bump-mapped, the value at a particular pixel may not be very representative of the underlying geometry. This is why the mesh browser window used by the mesh decimator generates its own vertex normals from the mesh itself. If you like, I can fairly easily modify the mesh decimator to generate the vertex normals so that you can access them too.

User avatar
Site Admin
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: Creating vertex normals from TN map

Postby miko » Sun May 15, 2011 11:39 am

Aha! Think I understand the concept now. It is all written in Zeolite_defines.h: typedef vector3c TerrainNormalPixel;
Got a bit mixed up with that void* that needs to be passed into zmap_GetPixel :) Thanks for the enlightenment, Aaron.

Actually, I have an own routine in place that would calculate vertex normals from face normals. For border tiles at mosaic export, I noticed it created some slight edges though (not considering faces of adjacent mosaic tiles). So, I thought of another "nifty" way to retrieve normal values. Did not consider the bump-mapped issue you pointed to, though.

Having the mesh decimator return vertex normals, too, would certainly be useful (along with the possibility to call it "ui-less", as discussed on the other thread :mrgreen: ).

Again, thanks.
Contributing member
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Return to Plugins and scripts

Who is online

Users browsing this forum: No registered users and 2 guests