From 5567e898d1052c1e2c2d32d3c37dfd957f4dc4bd Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 29 May 2017 22:11:33 -0300 Subject: Several fixes related to PBR and Environment --- modules/tinyexr/image_loader_tinyexr.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/tinyexr/image_loader_tinyexr.cpp') diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp index fbf5dea15..4eb91da10 100644 --- a/modules/tinyexr/image_loader_tinyexr.cpp +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -34,7 +34,7 @@ #include "thirdparty/tinyexr/tinyexr.h" -Error ImageLoaderTinyEXR::load_image(Ref p_image, FileAccess *f) { +Error ImageLoaderTinyEXR::load_image(Ref p_image, FileAccess *f, bool p_force_linear) { PoolVector src_image; int src_image_len = f->get_len(); @@ -133,9 +133,17 @@ Error ImageLoaderTinyEXR::load_image(Ref p_image, FileAccess *f) { // Assume `out_rgba` have enough memory allocated. for (int i = 0; i < exr_image.width * exr_image.height; i++) { - *iw++ = Math::make_half_float(reinterpret_cast(exr_image.images)[idxR][i]); - *iw++ = Math::make_half_float(reinterpret_cast(exr_image.images)[idxG][i]); - *iw++ = Math::make_half_float(reinterpret_cast(exr_image.images)[idxB][i]); + Color color( + reinterpret_cast(exr_image.images)[idxR][i], + reinterpret_cast(exr_image.images)[idxG][i], + reinterpret_cast(exr_image.images)[idxB][i]); + + if (p_force_linear) + color = color.to_linear(); + + *iw++ = Math::make_half_float(color.r); + *iw++ = Math::make_half_float(color.g); + *iw++ = Math::make_half_float(color.b); if (idxA > 0) { *iw++ = Math::make_half_float(reinterpret_cast(exr_image.images)[idxA][i]); -- cgit v1.2.3-70-g09d2