I am in need of a shader that will convert a grayscale image (bumpmap) into a normal map. It seems that this would be theoretically possible… at least… I can’t think of any reasons with my limited shader knowledge why this wouldn’t be possible in unity.
Has anyone here done any work to this affect or have any ideas for accomplishing it? I tried a conversion method listed here:
… using javascript but it was slow enough to be impractical for what I’m looking for. the shader method listed at the same url is incomplete… unfortunately.
Weeeellll… that is certainly a start! I’ll have to go into the shader and play around a bit until it looks right, but it is certainly starting to approximate a normal map.
Just make sure your source image isn’t DXT compressed, that will completely destroy the normal effect Also, you should get a better result if you get sample more points around the center instead of only right and up.
ToreTank, all I can say is that you are my hero of the month!
Was able to incorporate your code into my existing shaders and get the exact functionality I was looking for. I actually didn’t really notice much difference between compressed and uncompressed textures, which is a big plus.
Well now this shader seems to be broken in Unity 3.2 I’m glad I saved my old project before upgrading, but If I can’t get this to work properly I may have to figure out a different method. ugh. 2 steps forward, one step back.
I know this is an old thread but I wanna ask just in case. Do you by any chance still have access to the shader you made with this @chingwa ? Would you mind sharing it?
Thanks!
An other answer for a zombie thread : If you need a normal map but only have a greyscale bump map, instead of creating a custom shader you can set your bump map to import as a normal map, and enable “Create from Grayscale”, and tweek the bumpiness and filtering setting. You’ll then have a normal map that suits to a lot of the shaders provided by Unity.
@Remy_Unity In most cases this is what you would want to do , but the original question was asking for a way to do this on-the-fly, rather than as an editor setting. I was using a generated grayscale texture and wanting to extract the normal info from grayscale directly in the shader.
@opponent019_unity The solution from @ToreTank above still works. I’ve put it into a modern Unity PBR shader below. Do note that you do lose some quality in the normal rendering by doing it this way. If you need the best quality then you should do it in the editor if possible.