POV-Ray : Newsgroups : povray.advanced-users : Convert a normal map to a height field? : Re: Convert a normal map to a height field? Server Time
28 Jul 2024 10:21:19 EDT (-0400)
  Re: Convert a normal map to a height field?  
From: Chris B
Date: 14 Mar 2006 18:08:35
Message: <44174cf3$1@news.povray.org>
<Mienai> wrote in message 
news:web.44170d7a925a6bc093db03e80@news.povray.org...
> "Chris B" <c_b### [at] btconnectcomnospam> wrote:
>> Hi Mienai,
>>
>> I think there are a few problems with this approach.
>>
>> One biggy is that the images won't contain some of the information you 
>> would
>> need in order to create a height field - In particular the height.
>> ... snip ...
>>
>> Regards,
>> Chris B.
>
> The way I was thinking of it was that the normal is providing the delta in
> height (slope) that's why I was thinking that I could just run the image
> through a derivative to get an approximate height based of some +c value
> (or maybe I need to integrate I forget, should be basic calculus though,
> right?).
> ... snip ...
>
> I'm still looking of a good way to convert this.
>

OK. Well given all the caveats and the implicit innacuracies and the get-out 
clause that says I wouldn't do it this way, here's how you might be able to 
do it.

The information you've given isn't all that comprehensive, but I'm assuming 
that the object is something akin to a height field to start with and that 
the objects surface is smooth and of a colour that is uniformly reflective 
to green and red light. Also I assume parallel light rays falling on the 
surface (i.e. a distant light source where the falloff of light with 
distance becomes insignificant in the calculation ). I'm assuming the camera 
is above the object looking down from a great distance so that you get an 
image where the pixels will map correctly onto the height field you want to 
create.

If you process the image pixel-by-pixel you can work out an approximate 
x-elevation and a z-elevation across a pixel based upon a normal that is 
calculated from the Red and Green colour components of the pixel.

If my thinking on this is correct (based on a quick sketch and a little 
paper-based trigonometry) I think the following would give you the normal 
<X,Y,Z> of the surface :
X=Red/255,
Z=Green/255,
Y = square root of  (1 - X squared - Z squared)

The rise from one side of the pixel to the other in the x-direction would be 
Y/X pixel-widths and the rise in the z-direction would be Y/Z pixel-widths.

Note. This is untested and someone with more maths skills than me may be 
able to advise if it's not correct.

Regards,
Chris B.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.