Fixed lingering Sky Shader bug (tentative, needs confirmation)

Description of the problem

I was playing around with syntopia’s GLSL implementation of the Preetham sky model and using the original code on glslsandbox, came across the Android bugs and Windows ANGLE bugs involving the TotalRayleigh() function which uses pow() with very small values. I then realized three.js uses almost the same code with the same issues that have been discussed and resolved or worked around in the past.

I replaced the pow(Lambda, vec3(4.0)) calculation with a pre-calculated constant vec3 Kray4 . Lambda is constant anyway so there’s no need to calculate it every pixel. It is stored away in Kray4 for reuse.

Now, using the original sky model Rayleigh calculations, the shader works both on my Windows/ANGLE device as well as my Android smartphone.

Please visit: http://glslsandbox.com/e#36146.2
update with new const vec3 totalRayleigh: http://glslsandbox.com/e#36146.5
and confirm if it is working on your devices as well.

Once we have confirmation, I can make a PR if you like. Glancing at the calculations, there are some optimizations to be made involving storing constants instead of calculating them over and over again for each pixel. For example line 70 in the example above, the following calc could be made a constant:
vec3 inverse = 1.0 / ( 3.0 * N * Kral4 * ( 6.0 – 7.0 * pn ) );

One more minor issue is that we could remove the changing from exp(n) to pow(e,n) in #8614 and the simplified calculation in #5602

ping @zz85 @brianchirls @mrdoob @arturitu

Three.js version
  • Dev
  • r81
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “Fixed lingering Sky Shader bug (tentative, needs confirmation)

Comments are closed.