diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-05-28 21:46:48 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-05-28 21:48:05 -0300 |
commit | bb20f230ad307a2a5f18c03bece3793d29ae208a (patch) | |
tree | b217d7c10054e23b0f456acee41bc208dc12bfdf /core/color.h | |
parent | 06fc9637966dafe8e06e1d4f823bf9e8b3475c97 (diff) | |
download | redot-engine-bb20f230ad307a2a5f18c03bece3793d29ae208a.tar.gz |
-Added .hdr format support
-Added default environment editor setting
-Added environment created by default in new projects
-Removed default light and ambient from spatial editor, to make the editor more PBR compliant
Diffstat (limited to 'core/color.h')
-rw-r--r-- | core/color.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/color.h b/core/color.h index 46386fac64..c83dcda4b4 100644 --- a/core/color.h +++ b/core/color.h @@ -83,6 +83,40 @@ struct Color { return res; } + _FORCE_INLINE_ uint32_t to_rgbe9995() const { + + const float pow2to9 = 512.0f; + const float B = 15.0f; + //const float Emax = 31.0f; + const float N = 9.0f; + + float sharedexp = 65408.000f; //(( pow2to9 - 1.0f)/ pow2to9)*powf( 2.0f, 31.0f - 15.0f); + + float cRed = MAX(0.0f, MIN(sharedexp, r)); + float cGreen = MAX(0.0f, MIN(sharedexp, g)); + float cBlue = MAX(0.0f, MIN(sharedexp, b)); + + float cMax = MAX(cRed, MAX(cGreen, cBlue)); + + // expp = MAX(-B - 1, log2(maxc)) + 1 + B + + float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B; + + float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f); + + float exps = expp + 1.0f; + + if (0.0 <= sMax && sMax < pow2to9) { + exps = expp; + } + + float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f); + float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f); + float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f); + + return (uint32_t(Math::fast_ftoi(sRed)) & 0x1FF) | ((uint32_t(Math::fast_ftoi(sGreen)) & 0x1FF) << 9) | ((uint32_t(Math::fast_ftoi(sBlue)) & 0x1FF) << 18) | ((uint32_t(Math::fast_ftoi(exps)) & 0x1F) << 27); + } + _FORCE_INLINE_ Color blend(const Color &p_over) const { Color res; |