View Full Version : Height -> Normal?
kogi04
January 27th, 2010, 22:42
Is there viable a way to convert a b/w bitmap with height information to a tangent space normal bitmap? Similar to what a "normal map filter" in photoshop would do.
Been searching the existing threads here but with no results so far.
Thanks
ruediger
January 29th, 2010, 17:51
Hi Kogi,
if you take a look at the projects folder that comes with mental mill (look under <MILLINSTALL_DIR>/projects/) you will find a project called bump_map.xmsl.
This project contains a Phenomenon called bump_map which does exactly what you want: It computes a bump mapped normal from a height map.
And that is how the bumpmapped normal is computed: The UV coordinates are slightly offset in the U and V direction, computing a gradient value at the offset positions. Using these three different values a perturbed normal can be generated which is done by the
Depending on your texture size you must set the appropriate value for the offset. Typically you will offset by one pixel. The offset value is given in UV coordinates however which are resolution independent and adress the image within a coordinate range from 0 to 1. You must calculate the offset correctly which is 1.0 / imagesize
The correct offset for a 512 x 512 texture would be 1.0 / 512.0 whiile for a 2048 x 2048 texture it would be 1.0 / 2048.0
Note: If you are working with non-square images then the offsets for U and V are different... But we don't bother about this new. As a homework you can modify the bump_map Phenomenon to support individual offsets for U and V.
So much for the thery. Normal maps have become very popular as they have more advantages compared to the technique mentioned above:
normal maps only require one single texture lookup instead of three.
The user needn't make calculations to offset anything as he can use the current texture coordinate.
A normal maps stores all these precalculations that you would need to do over and over again, each time that you ask the shader to give you the bump mapped normal. If you just want to generate a bump map because you don't have a normal texture this technique works fine.
I hope that answers your question,
Best Regards,
Ruediger
ruediger
January 29th, 2010, 18:14
I am not sure whether that helps you or you are interested in that, but I am showing you how this technique works with procedural textures as well.
The shader will be slow since evaluating a procedural shader three times is really expensive, however it is an interesting example of how procedural bump mapping works.
Best Regards,
Ruediger
kogi04
February 1st, 2010, 08:54
Ah, very cool. Thank you Ruediger.
I'm working on this Eye shader with an Iris Size attribute you can animate. Planning on trying this method out to further refine it.
kogi04
February 1st, 2010, 10:22
I have a follow up question.
I'm generating a b/w mask already in my shading network and it's this mask which I want to make a bump map for. It's of type "color" and not "texture2D" as in your examples. How do I associate a texture UV attribute for this specific color output?
Thanks
ruediger
February 1st, 2010, 13:51
That's the common dilemma with the b/w color maps: One single b/w value does not do the trick. You always need two more lookups which are slightly offset so that the perturb normal shader can derive the right information. That's why doing bump mapping that way is slower due to that fact.
In a normal map the neighbourhood calculation has already been taken into account because the application has already preprocessed the texture. Ssometimes doing even more complicated neighbourhood analysation to compute the normal map value for a given pixel, but that's out of scope here ;) Just take a look at the NVidia Photoshop plugin for normal map generation, for example. You will see that you have several filtering options available.
Long story short, you must check the neighbourhood at least twice to derive a proper normal from a b/w color map.
Best Regards,
Ruediger
ruediger
February 1st, 2010, 17:28
In order to make this work, you will need to do the same as in the examples of the post above: You must perform two more lookup ups into that mask (texture) to derive the normal. If you can share some information about your project I might be able to help you on this one.
Best Regards,
Ruediger
kogi04
February 2nd, 2010, 09:09
I'm doing an Eye Shader with an Iris Size value you can animate. You use a pre-defined b/w gradient like texture for the iris shape. Then you at a certain level of grey you clamp and thereby get a mask you can use in order to display where to use the Eye textures and where to use the Iris textures. What I need now is to get a normal mapped effect where the eye/iris textures meet.
Have a look at this YouTube clip to see my progress so far.
http://www.youtube.com/watch?v=Y6Sh9_pqZro
Here's how the mask look:
http://img33.imageshack.us/img33/438/maskg.th.png (http://img33.imageshack.us/i/maskg.png/) http://img407.imageshack.us/img407/2152/maskcat.th.png (http://img407.imageshack.us/i/maskcat.png/) http://img46.imageshack.us/img46/4059/maskcyborg.th.jpg (http://img46.imageshack.us/i/maskcyborg.jpg/)
dima.david
February 2nd, 2010, 10:16
attached is my way to make Alpha as bump, by ruediger tips.
If you wrap into phenomenon you can you same texture to all lookups
ruediger, does it slow the shader if same texture goes into few lookups within phenomenon?
kogi04
February 2nd, 2010, 10:28
Ruediger thank you for being persistant regarding pre-calculating the normal map. I was very convinced that it could not be done since I had a mask which would vary in shape and size, but your comments made me think twice and give it a try. Worked out just fine.
Here's what I accomplished:
http://www.youtube.com/watch?v=CN9alIFB-d4
dima.david> Thanks for the tip, got it working with pre-calculated normal map solution though.
ruediger
February 8th, 2010, 13:08
Hi Kogi,
I am glad that it worked out! Nice video, looks like you are going to create some interesting shaders there...
Cheers,
Ruediger
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.