2012年4月16日 星期一

Aliasing generating normal map from height map

I'm doing bump mapping with webGL shaders. Everything was fine until I was generating normal map from the height map. I generated the height map with another shader and rendered it as a texture. Then read the texture (heigh map) and generate normal map from it with the way described in this thread
http://stackoverflow.com/questions/5281261/generating-a-normal-map-from-a-height-map

The normal map looks fine except it has pretty serious aliasing problem!



The aliasing problem should come from the size of the texture doesn't match the canvas's size but since The texture came from the previous rendering, they should have the same size. And the texture parameters were set with gl.NEAREST (turn off the mipmap) and gl.CLAMP_TO_EDGE (turn off the repeating) so even it's not power of two, it should be alright. The offset in the shader is like [1.0/canvas.width, 1.0/canvas.height]

Could anyone have any idea what causes the aliasing? Thank you so much,

Yi