The Sunlight examples (WebGL and WebGPU) provide useful templates for people using three.js to create open world scenarios. However, for those of us who work in those kinds of scenarios, there is some potential confusion regarding the azimuth and the computation of the position of the sun. To us, when the term azimuth is used in connection with the sun, the term means the “solar azimuth” - which is the absolute direction of the sun - 0 degrees is North, 90 is East, 180 is South, and 270 is West. However, in the Sunlight examples, this is not what is happening.
To see this problem, go to one of the Sunlight examples. The starting (solar) azimuth is 135, which indicates that the sun is roughly South-East of your position. Based on the direction of the shadow, this indicates that you are facing North. If the sun now rotates to the South (as is typical in the Northern Hemisphere), the sun should move clockwise around you so that when the azimuth is 180, the sun is should now be directly behind you (South). However, in the example, the sun rotates counter-clockwise so that when the azimuth is 180, the sun is directly to your right (East).
The reason for this problem is that the examples use the setFromSphericalCoords function to compute the position of the sun, e.g.:
sunLight.position.setFromSphericalCoords(1,THREE.MathUtils.degToRad(90-params.elevation),THREE.MathUtils.degToRad(params.azimuth));
This setFromSphericalCoords function is perfect for computing position in the standard case where the azimuth is the rotation angle in the xy-plane measured counter-clockwise from the positive x-axis. However, the solar azimuth is different. In the spherical coordinate system, the solar azimuth equates to the rotation angle in the xy-plane measured clockwise from the positive y-axis. Compared to the standard azimuth, the solar azimuth is 90 degrees off and rotating in the opposite direction.
Thus, if you want to use the setFromSphericalCoords function get the correct sun position, you need to convert your solar azimuth to a normal azimuth value. This modification of the above instruction appears to do the trick:
sunLight.position.setFromSphericalCoords(1,THREE.MathUtils.degToRad(90-params.elevation),THREE.MathUtils.degToRad(270-params.azimuth));
One you do that, the position of the sun will correlate to the (solar) azimuth.