Chris Normal Map Converter Code (nm16)

Tips for creating and manipulating planet textures for Celestia.
Buzz
Posts: 264
Joined: 31.01.2002
With us: 22 years 5 months
Location: The Netherlands

Post #21by Buzz » 05.01.2004, 23:47

Update: I just found out that Chris' script works almost perfectly with the GTOPO elevation data you can find here:
http://edcdaac.usgs.gov/gtopo30/gtopo30.html
They use the "big-endian" byte order too! Now I just have to find a way to make sure the edges of the land masses are not always shown as steep walls (they took -9999 for the sea level :evil: ) And the right edge of the generated normalmaps shows a 1-pixel artefact :(

timcrews
Posts: 118
Joined: 27.11.2002
With us: 21 years 7 months
Location: Chandler, Arizona

Post #22by timcrews » 06.01.2004, 04:07

Buzz wrote:Good to hear you have lots of C experience! Fridger wrote earlier in this thread:

"you changed the conventions in your readS16() relative to Chris , e.g. for MSB (big endian)

Chris would use in your notation:
return (short) (b) * (1.0f / 65535.0f);

You used:
return (32767-b) * (1.0f / 65535.0f);

which reverts the normal map relative to Chris. "

I hope this helps!


Alas, I made the above change, and generated a 64K normal map on the optimistic assumption that this would fix everything, but it didn't. When the earth is lit from the east, the mountains are illuminated as if from the west (or, alternatively, they have become canyons). [LATER EDIT: I was wrong about this. The shadows are right. With the suggested (32767-b) fix, the windows version of nm16 works fine.]

On further thought, it really doesn't make sense that a (b) vs. (32767-b) could have addressed an endian issue.

The windows version of the nm16 executable already had provisions for big vs. little endian anyway, in the form of a command-line option. The documentation for that option specifically addressed the data set I was working with, so I'm pretty sure the endian-ness of the data has been properly accounted for.

Since I know nothing about the theory of normal maps, it's going to be pretty hard to debug this problem. Can any normal map gurus take a look at the nm16win code from Pixel's link above, and tell me what to fix?

Thanks,

Tim Crews

P.S. In addition to the fact that it's inverted, the 64K normal map does show more flaws than the 32K map did. In part, this may be because 64K really exceeds the native resolution of the (43K) raw data. But it might also be because I skipped the two-step resizing procedure. I'll re-write my scripts to do that, but I'll wait to run them until I'm pretty sure I know how to use nm16.
Last edited by timcrews on 06.01.2004, 22:28, edited 1 time in total.

Buzz
Posts: 264
Joined: 31.01.2002
With us: 22 years 5 months
Location: The Netherlands

Post #23by Buzz » 06.01.2004, 13:57

Hi Tim,

I don't think the b sign reversal was meant to do something with the bigendian numbers, but with reversal of height values. I don't know if you would like to try the GTOPO data in combination with Chris' nm16, but in that case it would be nice if it had the option to change any -9999 value to 0 to prevent steep continent edges. Do you think you could change this easily? (A more general solution of course would be the option to indicate an "unknown" like Pixel did).

And I have to dive into the details of normal maps too...

Buzz

timcrews
Posts: 118
Joined: 27.11.2002
With us: 21 years 7 months
Location: Chandler, Arizona

Post #24by timcrews » 06.01.2004, 22:36

Hello:

I re-edited my previous post, which stated that the (32767-b) change did not fix the normal-map inversion problem. It did fix the problem.

I do not have a web site to host the modified .exe. If you want a copy, e-mail me and I will send it to you. It is small, 162K, zips to 86K.

[LATER EDIT: I found some web space. The .exe can be found here: http://www.crews-family.org/nm16.zip]


Tim Crews

Avatar
John Van Vliet
Posts: 2940
Joined: 28.08.2002
With us: 21 years 10 months

re

Post #25by John Van Vliet » 21.01.2004, 21:09

hi i have a work around for the "big clifs at sea level" using GTOPO30 tiles
#
convert -depth 16 -size 4800x6000 E060N40.gray -depth 16 E060N40.fits
#
then i am using cinepaint "http://cinepaint.sourceforge.net/" to open the .fits ang ajust the gama and size to 4k,2k,1k,
# then
convert -depth 16 4kE060N40.fits -depth 16 -size 4096x5120 4kE060N40.gray
convert -depth 16 2kE060N40.fits -depth 16 -size 2048x2560 2kE060N40.gray
convert -depth 16 1kE060N40.fits -depth 16 -size 1024x1280 1kE060N40.gray
# then
nm16 4096 5120 80 0 4kE060N40.gray msb 0 4knm
nm16 2048 2560 80 0 2kE060N40.gray msb 0 2knm
nm16 1024 1280 80 0 1kE060N40.gray msb 0 1knm


Return to “Textures”