diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2022-10-16 02:57:44 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2022-10-16 03:34:10 +0300 |
commit | 0c50f9c4aaf90eb26240c31fbeff12af519a8ab0 (patch) | |
tree | 3d1bc724eac9f013e1252953fa1905b9d26acf9d /intern/cycles/util/math.h | |
parent | b898330c3744669a8c3805f1560130821422cca1 (diff) |
Fix T98672: Noise texture shows incorrect behaviour for large scales
This was a floating point precision issue - or, to be more precise,
an issue with how Cycles split floats into the integer and fractional
parts for Perlin noise.
For coordinates below -2^24, the integer could be wrong, leading to
the fractional part being outside of 0-1 range, which breaks all sorts
of other things. 2^24 sounds like a lot, but due to how the detail
octaves work, it's not that hard to reach when combined with a large
scale.
Since this code is originally based on OSL, I checked if they changed
it in the meantime, and sure enough, there's a fix for it:
https://github.com/OpenImageIO/oiio/commit/5c9dc68391e9
So, this basically just ports over that change to Cycles.
The original code mentions being faster, but as pointed out in the
linked commit, the performance impact is actually irrelevant.
I also checked in a simple scene with eight Noise textures at
detail 15 (with >90% of render time being spent on the noise), and
the render time went from 13.06sec to 13.05sec. So, yeah, no issue.
Diffstat (limited to 'intern/cycles/util/math.h')
-rw-r--r-- | intern/cycles/util/math.h | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h index 0905b3ec5c9..3a2e0e074a2 100644 --- a/intern/cycles/util/math.h +++ b/intern/cycles/util/math.h @@ -417,15 +417,11 @@ ccl_device_inline int floor_to_int(float f) return float_to_int(floorf(f)); } -ccl_device_inline int quick_floor_to_int(float x) -{ - return float_to_int(x) - ((x < 0) ? 1 : 0); -} - ccl_device_inline float floorfrac(float x, ccl_private int *i) { - *i = quick_floor_to_int(x); - return x - *i; + float f = floorf(x); + *i = float_to_int(f); + return x - f; } ccl_device_inline int ceil_to_int(float f) |