diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-07-03 10:55:50 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2018-07-03 10:56:31 -0300 |
commit | e179bf0726868fbf2c6216a6c6a715c4a2f99419 (patch) | |
tree | ca4c02c36e57147ad1a2e298503b48e21d6e1f47 /core/image.cpp | |
parent | 74369229de7f43ce4a0e0a102e5b3bf3c6e3a33a (diff) |
Ensure, if a texture meant for a normal map is imported and size limit exists, that it's renormalized after resize.
Diffstat (limited to 'core/image.cpp')
-rw-r--r-- | core/image.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/image.cpp b/core/image.cpp index c08b1ac39b..b0bed80a6f 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1076,6 +1076,36 @@ void Image::shrink_x2() { } } +void Image::normalize() { + + bool used_mipmaps = has_mipmaps(); + if (used_mipmaps) { + clear_mipmaps(); + } + + lock(); + + for (int y = 0; y < height; y++) { + + for (int x = 0; x < width; x++) { + + Color c = get_pixel(x, y); + Vector3 v(c.r * 2.0 - 1.0, c.g * 2.0 - 1.0, c.b * 2.0 - 1.0); + v.normalize(); + c.r = v.x * 0.5 + 0.5; + c.g = v.y * 0.5 + 0.5; + c.b = v.z * 0.5 + 0.5; + set_pixel(x, y, c); + } + } + + unlock(); + + if (used_mipmaps) { + generate_mipmaps(true); + } +} + Error Image::generate_mipmaps(bool p_renormalize) { if (!_can_modify(format)) { |