I have made a program that samples uniformly an environment map and computes the lighting using the GGX BRDF.
I have made a small example that reproduces the issue I'm having. You can check it out online: shorturl.at/tvzGY
The algorithm works as follows:
- We compute
V, the unit vector that points from the surface to the camera.
FPositionis the position of the fragment in camera space so we can use that to compute
- We will take a few sample directions
Lin uniform random directions. These samples are taken inside a hemisphere in the direction of the normal
- In the real program, we would use
Lto sample the environment map but, for simplicity, in the provided example, I'm just assuming a complitely white environment (the issue happens anyways).
- For each of these samples we compute the rendering equation with the GGX BRDF, and we accumulate that into a variable.
- And finally we divide by the number of samples.
I'm using the formulas for GGX I found in this site: http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
The problem I'm having is that it doesn't look right. If you open the link you will see this.
That's with roughness = 0.1, metallic = 1.0, and numSamples = 10.
In the top right corner, switch to the sphere. And you will see this.
You see those bright spots, the number of them correlates with the number of samples. That could make sense, maybe. But when I increment the number of samples to 100, we get this.
There are more spots but they are also smaller and blurrier. I think I must be doing something wrong because it doesn't look like a metal. Or is it just because of the uniform sampling? Even with 1000 samples per pixel it doesn't look right to me.