The problem seems to be numerical issues in the **sqrt** function when its arguments are very near zero. The code that causes this symptom is actually inside the **D** function, at line 8.

I have fixed it by changing **b > .707** to **b > .708**. So now **sqrt(b – .707)** always produces a reasonable result.

I notice there is some artifacts with the rim of the sphere on my GTX1080:

http://www.umiacs.umd.edu/~ruofei/perlin012517.PNG

The artifacts disppear if I remove:

c += z * ( c * max(0., .06 * dot(L, v)) + // Rim light

vec3(.3,.3,.3)

* pow(H(v + L) + .8 * H(v – L), 8.) ); // Highlights

I guess it’s because of the distance field of the disk but I did not solve it.

Any suggestions?

Thanks!

]]>