Is there an tutorial about how to do bump mapping with metal?
bump mapping with metal
Anyone knows?
The MetalShaderShowcase sample includes an implementation of bump mapping using a normal map.
This is for surface, is there any code for apply bump mapping to a image? I found this page https://web.cs.wpi.edu/~matt/courses/cs563/talks/bump/bumpmap.html. However the quality of the bump mapping is very poor. I am wondering if Meta has something better...
From the look of it this is bump mapping as usual (in Metal that could be bump mapping a surface textured with image, or blend, or something like that), the only difference being that normal map is generated from image. "The partial derivatives of i(u,v) can be estimated by convolving the bump map image with the following masks" - what they do here is, in essence, setting normal to perpendicular (=flat surface) where rate of change of original image is zero (areas with same color) and perturbing normals where rate of change is nonzero.
What this has to do with Metal is that you can use code from Metal Performance Shaders to compute above mentioned convolution for you. Or you can use Sobel gradient operator (also available in MPS) for slightly different effect. You take original image (or grayscale version), apply filter, take convolved image and convert it to normal map (for example, horizontal operator value maps to x member of vector, and vertical operator value maps to y member of vector, perhaps with some scaling, then normalize). After that you do bump-mapping as usual.
No, I don't have code for this at hand.
And that quality issue is mostly due to low resolution of normal map and/or image that normal map is generated from. Metal will allow you to do much better than that, because with the power of modern GPUs you can easily compute/render high resolution bump mapped surface in fraction of frame.
Hope that helps
Michal
I wrote some code using Metal shading language but the performance was really poor. I do not think Metal can handel this kind of mapping well...