diff options
author | Yein Jo <yeinj@google.com> | 2024-01-04 17:40:51 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-01-12 22:36:28 +0000 |
commit | 79da255ab21741cf8a7f67fabe6d477950ee3aa6 (patch) | |
tree | 4b661328f24f0354f138db045c9b73d522242d87 | |
parent | 9be8bf7ce9be6f66472ada645af50f31093f8bfe (diff) | |
download | base-79da255ab21741cf8a7f67fabe6d477950ee3aa6.tar.gz |
Fix the grid artifacts in simplex noise
Skew grid artifacts were shown due to the recent GPU driver update that
may have changed some floating point computation. Making the hash
function integer based to mitigate floating point precision issue.
Skewed grid can be only shown if the hash function produces different
gradient vectors in the same simplex vertex. Since the hash function
produces "discontinuous" random values, a small difference in the input
could cause a huge difference in the output. This is why it's more
robust to use integer based hash.
Bug: 315533269
Flag: NA
Test: Visually inspect
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:47ab14aa59ecdf013e5e87573a164114f8503d61)
Merged-In: I4bdc69a7dd8e6c3919a7c0594bebf37b83fd946a
Change-Id: I4bdc69a7dd8e6c3919a7c0594bebf37b83fd946a
-rw-r--r-- | packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/shaderutil/ShaderUtilLibrary.kt | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/shaderutil/ShaderUtilLibrary.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/shaderutil/ShaderUtilLibrary.kt index 23fcb691ddb4..867bbb7d74eb 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/shaderutil/ShaderUtilLibrary.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/shaderutil/ShaderUtilLibrary.kt @@ -65,12 +65,33 @@ object ShaderUtilLibrary { return dest; } - // Return range [-1, 1]. + // Integer mod. GLSL es 1.0 doesn't have integer mod :( + int imod(int a, int b) { + return a - (b * (a / b)); + } + + ivec3 imod(ivec3 a, int b) { + return ivec3(imod(a.x, b), imod(a.y, b), imod(a.z, b)); + } + + // Integer based hash function with the return range of [-1, 1]. vec3 hash(vec3 p) { - p = fract(p * vec3(.3456, .1234, .9876)); - p += dot(p, p.yxz + 43.21); - p = (p.xxy + p.yxx) * p.zyx; - return (fract(sin(p) * 4567.1234567) - .5) * 2.; + ivec3 v = ivec3(p); + v = v * 1671731 + 10139267; + + v.x += v.y * v.z; + v.y += v.z * v.x; + v.z += v.x * v.y; + + ivec3 v2 = v / 65536; // v >> 16 + v = imod((10 - imod((v + v2), 10)), 10); // v ^ v2 + + v.x += v.y * v.z; + v.y += v.z * v.x; + v.z += v.x * v.y; + + // Use sin and cos to map the range to [-1, 1]. + return vec3(sin(float(v.x)), cos(float(v.y)), sin(float(v.z))); } // Skew factors (non-uniform). |