Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-07-25 20:11:29 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-07-25 20:26:12 +0300
commit46dbfce7fc59cd93566251b6cc7a2d8521c991bd (patch)
treefa0007b56c4ec71b8c1afc2f07083d442cd6bd0f /intern
parent703dff333ce6cbc25c990042858a0c40f9a212cb (diff)
Cycles: Nishita Sky: Fix sun disk imprecision for large elevation
The issue was introduced by rBad5e3d30a2d2 which made possible to use unbounded elevation angle. In order to not touch the shading code, we just remap the value to the expected range the shading code expects. This means that elevation angles above +/-PI/2 effectively flip the sun rotation angle.
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/shader.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp
index 81a64457c88..4218a9a8a68 100644
--- a/intern/cycles/blender/shader.cpp
+++ b/intern/cycles/blender/shader.cpp
@@ -928,8 +928,22 @@ static ShaderNode *add_node(Scene *scene,
sky->set_sun_disc(b_sky_node.sun_disc());
sky->set_sun_size(b_sky_node.sun_size());
sky->set_sun_intensity(b_sky_node.sun_intensity());
- sky->set_sun_elevation(b_sky_node.sun_elevation());
- sky->set_sun_rotation(b_sky_node.sun_rotation());
+ /* Patch sun position to be able to animate daylight cycle while keeping the shading code
+ * simple. */
+ float sun_rotation = b_sky_node.sun_rotation();
+ /* Wrap into [-2PI..2PI] range. */
+ float sun_elevation = fmodf(b_sky_node.sun_elevation(), M_2PI_F);
+ /* Wrap into [-PI..PI] range. */
+ if (fabsf(sun_elevation) >= M_PI_F) {
+ sun_elevation -= copysignf(2.0f, sun_elevation) * M_PI_F;
+ }
+ /* Wrap into [-PI/2..PI/2] range while keeping the same absolute position. */
+ if (sun_elevation >= M_PI_2_F || sun_elevation <= -M_PI_2_F) {
+ sun_elevation = copysignf(M_PI_F, sun_elevation) - sun_elevation;
+ sun_rotation += M_PI_F;
+ }
+ sky->set_sun_elevation(sun_elevation);
+ sky->set_sun_rotation(sun_rotation);
sky->set_altitude(b_sky_node.altitude());
sky->set_air_density(b_sky_node.air_density());
sky->set_dust_density(b_sky_node.dust_density());