heightmap from normalmap

Started by
9 comments, last by Fingers_ 16 years, 11 months ago
is there anyway to recreate a heightmap from a normalmap? is there any programs you can use?
Advertisement
you can do it yourself... a normal map represents the surface normal... which would represent the gradient at that point... so start at one corner and based on the gradients figure out what angle the surface lies at... and calculate the values at the adjacent edges. You will most likely be half a pixel off and need to correct somehow, but this most likely makes no difference. Once you have the values... you'll have to normalize the values to some specific range. Assuming you know what a normal map is this should be a fairly simple task to work out for yourself.
Hope this helps,

Dan

EDIT: I didn't make it clear that the result is correct to a constant, which is why you need to normalize the values in some appropriate way for your proposed use of the map.
Quote:Original post by mrcheesewheel
you can do it yourself... a normal map represents the surface normal... which would represent the gradient at that point... so start at one corner and based on the gradients figure out what angle the surface lies at... and calculate the values at the adjacent edges. You will most likely be half a pixel off and need to correct somehow, but this most likely makes no difference. Once you have the values... you'll have to normalize the values to some specific range. Assuming you know what a normal map is this should be a fairly simple task to work out for yourself.
Hope this helps,

Dan

EDIT: I didn't make it clear that the result is correct to a constant, which is why you need to normalize the values in some appropriate way for your proposed use of the map.


thx.. that should be quite simple...
It's not at all that simple...
This has been discussed here before and it took alot of tweaking to get things look semi ok (and still it failed on many maps).
One of the reason is quantization. Another is the fact that the normal map doesn't need to represent a heightmap at all!
I.e the normal map wasn't created from a heightmap.
There we're other issues as well that I can't remember, I coded a small app that took a .tga normal map and converted to a height map.
It did fairly ok on some maps but failed really bad on others...

The Nvidia photoshop plugin also have this feature.

Just my2c


I dug up my old code, here's one of the good examples:
=>
Here's one that's wrong, but still not to bad:
=>
A total screwup (most of my ingame normalmaps, becomes something like this, or worse...):
=>
Well I've not actually tried this... but I given sufficient point density any function can be arbitrarily well approximated by a piecewise polynomial interpolant. Clearly the quantization will be an issue, I think one has to be sure to consider all axis in parallel as opposed to considering them individually. I think another issue is the neccessity for a half pixel offset. If one places a grid over the normal map... with a pixel placed at the centre of each normal mapped valued quad... you have effectively 2 degrees of freedom for each normal (if we consider them normalised). That means 8 pieces of information. You thus need a meaningful interpolant with 8 degrees of freedom. Since the result can only be accurate to a constant, you can remove and constant factor from the choice. The first thing that sprang to mind was a cubic surface...
a*x^3+b*x^2*y+c*x*y^2+d*y^3+e*x^2+f*x*y+g*y^2+h*x+i*y+j
taking out the constant we unfortunately are left with one degree of freedom... so we need a further constraint (which I can't think of) or another interpolant. In this way though, you could calculate the relative position of each new grid centre compared to the surrounding ones. Based on arbitrary placement of a single point you could then calculate the position of the next point. Having thought about this a little more carefully that might result in an ambiguity as to where the point should be measured relative to... I think in order to solve this generally you need to calculate the entire polynomial field and solve simultaneously. As you said, if it's not generated from a height map you could have some issues... eg a roughly left pointing normal followed by a roughly right pointing normal might not be generatable... unless you multisampled. In fact that's quite an interesting proposition... calculate the resulting heightmap at double the resolution of the original in that case you could represent arbitrary normal map with a heightmap. Also you lose the edge pixels with the general scheme, but with the multisampling you could regenerate them... I'm starting to get quite interested in this problem as in the course of writing this reply, it's not as straightforward as I thought it might have been... if I have some time I might give it a go :).
Bye for now,

Dan
well ive looked into it and its not that quite easy as i thought.. however i founda program called crazy bump that works great for this purpose...
Quote:crazy bump

I tried it out too, but unless you tweaked alot with some parameters that I didn't find, I can't agree that it worked great or worked at all for that matter.
The lion head map for instance became some blurred mess, the brick wall to.
Please enlighten me where that magic option is...
If you do a little googling I seem to remember there being a GIMP plugin that could do this. Again, I don't think it gave perfect results, but it was free & easy.
well it never will become perfect.. i simply photoshop the rest and then calculate a new nomrlmap from that.. not perfect but it works...

This topic is closed to new replies.

Advertisement