Prefab does this too...  

principle is to calculate the angle between pixel colors and average to get a 
smoother or rougher surface.
as its on 2 plans, you need to define the normals to get started with.

I have no algo ready for you as I do have it spreaded over Prefab raytracer 
class,
but here's a snippet of it. 

                                                                bcol1x = 
(256/(_bumpmap.getPixel(pminX, ly)& 0xFF));
                                                                bcol2x = 
(256/(_bumpmap.getPixel(pmaxX, ly)& 0xFF));
                                                                bcol1y = 
(256/(_bumpmap.getPixel(lx, pminY)& 0xFF));
                                                                bcol2y = 
(256/(_bumpmap.getPixel(lx, pmaxY)& 0xFF));
                                                                
                                                                nbump.x = 
Math.atan2(bcol1x, pminX)-Math.atan2(bcol2x, pmaxX);
                                                                nbump.y = 
Math.atan2(bcol1y, pminY)-Math.atan2(bcol2y, pmaxY);
                                                                
nbump.normalize();

of course in your case you will have to consider the base colors as x,z plane 
represented with 0,1,0 normal
which is basically a green 0x00FF00 map. so in the above snippet, simply 
replace the color picking used for the diffuse map
by this green and average with the bump normal. that should give you a 
normalmap from a black and white map. 

you can also work per 9 grids to get smoother results, same as above but each 
block 3x3 is averaged for a single pixel.
I got back then, nice results but were not fast enough.

Fabrice
 

On Jul 2, 2011, at 6:13 PM, richardolsson wrote:

> Hi,
> 
> I don't know the name of any existing algorithms to do it, but the
> procedure is fairly simple. First of all, you need a normal map of the
> actual geometry (without bump-mapping) and then you need to calculate
> a normal map for the bump map on a flat plane. The former should
> probably be done by some tool, e.g. Blender (and you could probably
> use the same tool for both.) But if you want to do the later
> procedurally then it's a matter of understanding that a bump map
> defines the offset of geometry per pixel along the existing normal.
> That means that if you want to calculate a new normal, you can't just
> do it per-pixel, but you have to do it from the angle between two (or
> more) adjacent pixels' offset.
> 
> If you don't need to do it procedurally (i.e. if your geometry and/or
> bump map does not change dynamically) then I would simply advise you
> to use a 3D tool, and apply the bump map to your geometry and render a
> normal map of that geometry including bump map.
> 
> 
> Cheers
> /R
> 
> 
> On Jul 1, 7:20 pm, jamie655321 <[email protected]> wrote:
>> Hi,
>> 
>> Does anyone know of any code/algorithms to create Normal Maps from
>> greyscale Bump/Height Maps?
>> 
>> Thanks,
>> 
>> Jamie

Reply via email to