Cycles: Clamp Sky Texture altitude to avoid numerical issues

Differential Revision: https://developer.blender.org/D8091
This commit is contained in:
2020-07-13 01:53:02 +02:00
parent 7aacf2e119
commit 6a3c91f7ad

View File

@@ -828,13 +828,17 @@ void SkyTextureNode::compile(SVMCompiler &compiler)
else if (type == NODE_SKY_HOSEK) else if (type == NODE_SKY_HOSEK)
sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo); sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo);
else if (type == NODE_SKY_NISHITA) { else if (type == NODE_SKY_NISHITA) {
/* Clamp altitude to reasonable values.
* Below 1m causes numerical issues and above 60km is space. */
float clamped_altitude = clamp(altitude, 1.0f, 59999.0f);
sky_texture_precompute_nishita(&sunsky, sky_texture_precompute_nishita(&sunsky,
sun_disc, sun_disc,
sun_size, sun_size,
sun_intensity, sun_intensity,
sun_elevation, sun_elevation,
sun_rotation, sun_rotation,
altitude, clamped_altitude,
air_density, air_density,
dust_density); dust_density);
/* precomputed texture image parameters */ /* precomputed texture image parameters */
@@ -846,7 +850,7 @@ void SkyTextureNode::compile(SVMCompiler &compiler)
/* precompute sky texture */ /* precompute sky texture */
if (handle.empty()) { if (handle.empty()) {
SkyLoader *loader = new SkyLoader( SkyLoader *loader = new SkyLoader(
sun_elevation, altitude, air_density, dust_density, ozone_density); sun_elevation, clamped_altitude, air_density, dust_density, ozone_density);
handle = image_manager->add_image(loader, impar); handle = image_manager->add_image(loader, impar);
} }
} }
@@ -920,13 +924,17 @@ void SkyTextureNode::compile(OSLCompiler &compiler)
else if (type == NODE_SKY_HOSEK) else if (type == NODE_SKY_HOSEK)
sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo); sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo);
else if (type == NODE_SKY_NISHITA) { else if (type == NODE_SKY_NISHITA) {
/* Clamp altitude to reasonable values.
* Below 1m causes numerical issues and above 60km is space. */
float clamped_altitude = clamp(altitude, 1.0f, 59999.0f);
sky_texture_precompute_nishita(&sunsky, sky_texture_precompute_nishita(&sunsky,
sun_disc, sun_disc,
sun_size, sun_size,
sun_intensity, sun_intensity,
sun_elevation, sun_elevation,
sun_rotation, sun_rotation,
altitude, clamped_altitude,
air_density, air_density,
dust_density); dust_density);
/* precomputed texture image parameters */ /* precomputed texture image parameters */
@@ -938,7 +946,7 @@ void SkyTextureNode::compile(OSLCompiler &compiler)
/* precompute sky texture */ /* precompute sky texture */
if (handle.empty()) { if (handle.empty()) {
SkyLoader *loader = new SkyLoader( SkyLoader *loader = new SkyLoader(
sun_elevation, altitude, air_density, dust_density, ozone_density); sun_elevation, clamped_altitude, air_density, dust_density, ozone_density);
handle = image_manager->add_image(loader, impar); handle = image_manager->add_image(loader, impar);
} }
} }