From 703004f830f39adcde9b9565f1aa49d1b10e8d27 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 16 Jun 2014 10:22:26 -0300 Subject: More 3D Work -=-=-=-=-=- -ESM Shadow Mapping for softer and less glitchy shadows -HDR Pipeline (convert to Linear on texture import, convert to SRGB at the end) -Fix to xml parse bug --- core/color.h | 11 +++++++++++ core/image.cpp | 39 +++++++++++++++++++++++++++++++++++++++ core/image.h | 1 + 3 files changed, 51 insertions(+) (limited to 'core') diff --git a/core/color.h b/core/color.h index 9b5850f56b..491c72d449 100644 --- a/core/color.h +++ b/core/color.h @@ -30,6 +30,7 @@ #define COLOR_H #include "ustring.h" +#include "math_funcs.h" /** @author Juan Linietsky */ @@ -97,6 +98,16 @@ struct Color { return res; } + _FORCE_INLINE_ Color to_linear() const { + + return Color( + r<0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4), + g<0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4), + b<0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4), + a + ); + } + static Color hex(uint32_t p_hex); static Color html(const String& p_color); static bool html_is_valid(const String& p_color); diff --git a/core/image.cpp b/core/image.cpp index b577117f1e..e5489c06fa 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1664,6 +1664,45 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) { +void Image::srgb_to_linear() { + + if (data.size()==0) + return; + + static const uint8_t srgb2lin[256]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252}; + + + ERR_FAIL_COND( format!=FORMAT_RGB && format!=FORMAT_RGBA ); + + if (format==FORMAT_RGBA) { + + int len = data.size()/4; + DVector::Write wp = data.write(); + unsigned char *data_ptr=wp.ptr(); + + for(int i=0;i::Write wp = data.write(); + unsigned char *data_ptr=wp.ptr(); + + for(int i=0;i