cpetry / NormalMap-Online

NormalMap Generator Online
MIT License
434 stars 108 forks source link

Question about the displacement and specular functions. #25

Open AeroDEmi opened 2 years ago

AeroDEmi commented 2 years ago

Hi there!

I just wanted to know the algorithm you've used in the displacement and specular functions. I want to translate into python, so I don't know much about js.

For both functions you transform to grayscale using this function: v = 0.2126*r + 0.7152*g + 0.0722*b

For the displacement map I see the this.contrastImage function but when I try to use console log inside it, it does not show anything. Can you help me clear how the displacement and the specular function works pixel-wise? Thank you.

cpetry commented 2 years ago

Hello,

I'm not completely sure what your question is. The input height image 'should' be in grayscale. Often though colored images are used. I guess many users can live with this false interpretation of the resulting normal map. The grayscale image is then altered by a few parameters: invert, contrast, blur/sharp. With these parameters you can adjust the displacement map to your liking until it fits your needs.

For professional usage/creation of specular maps you don't use a height map. This normally doesn't make sense at all. But if you 'subselect' a specific height value by adjusting strength, mean, range, this could work for some materials. Depends on what you try to achieve.