From 4e12113beac6a9a48cf65fc5604513c36c02c5f3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 23 Feb 2017 14:46:22 +0100 Subject: Cycles: Fix wrong render results with texture limit and half-float textures --- intern/cycles/util/util_image_impl.h | 62 +++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'intern/cycles/util/util_image_impl.h') diff --git a/intern/cycles/util/util_image_impl.h b/intern/cycles/util/util_image_impl.h index 73ecfda0855..4daf1eaac22 100644 --- a/intern/cycles/util/util_image_impl.h +++ b/intern/cycles/util/util_image_impl.h @@ -19,6 +19,7 @@ #include "util_algorithm.h" #include "util_debug.h" +#include "util_half.h" #include "util_image.h" CCL_NAMESPACE_BEGIN @@ -38,6 +39,52 @@ const T *util_image_read(const vector& pixels, return &pixels[index]; } +/* Cast input pixel from unknown storage to float. */ +template +inline float cast_to_float(T value); + +template<> +inline float cast_to_float(float value) +{ + return value; +} +template<> +inline float cast_to_float(uchar value) +{ + return (float)value / 255.0f; +} +template<> +inline float cast_to_float(half value) +{ + return half_to_float(value); +} + +/* Cast float value to output pixel type. */ +template +inline T cast_from_float(float value); + +template<> +inline float cast_from_float(float value) +{ + return value; +} +template<> +inline uchar cast_from_float(float value) +{ + if(value < 0.0f) { + return 0; + } + else if(value > (1.0f - 0.5f / 255.0f)) { + return 255; + } + return (uchar)((255.0f * value) + 0.5f); +} +template<> +inline half cast_from_float(float value) +{ + return float_to_half(value); +} + template void util_image_downscale_sample(const vector& pixels, const size_t width, @@ -71,15 +118,22 @@ void util_image_downscale_sample(const vector& pixels, components, nx, ny, nz); for(size_t k = 0; k < components; ++k) { - accum[k] += pixel[k]; + accum[k] += cast_to_float(pixel[k]); } ++count; } } } - const float inv_count = 1.0f / (float)count; - for(size_t k = 0; k < components; ++k) { - result[k] = T(accum[k] * inv_count); + if(count != 0) { + const float inv_count = 1.0f / (float)count; + for(size_t k = 0; k < components; ++k) { + result[k] = cast_from_float(accum[k] * inv_count); + } + } + else { + for(size_t k = 0; k < components; ++k) { + result[k] = T(0.0f); + } } } -- cgit v1.2.3 From 0579eaae1f7afd2e40ad525fe97de7c4be2a9a1e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 28 Mar 2017 20:39:14 +0200 Subject: Cycles: Make all #include statements relative to cycles source directory The idea is to make include statements more explicit and obvious where the file is coming from, additionally reducing chance of wrong header being picked up. For example, it was not obvious whether bvh.h was refferring to builder or traversal, whenter node.h is a generic graph node or a shader node and cases like that. Surely this might look obvious for the active developers, but after some time of not touching the code it becomes less obvious where file is coming from. This was briefly mentioned in T50824 and seems @brecht is fine with such explicitness, but need to agree with all active developers before committing this. Please note that this patch is lacking changes related on GPU/OpenCL support. This will be solved if/when we all agree this is a good idea to move forward. Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner Reviewed By: lukasstockner97, maiself, nirved, dingto Subscribers: brecht Differential Revision: https://developer.blender.org/D2586 --- intern/cycles/util/util_image_impl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'intern/cycles/util/util_image_impl.h') diff --git a/intern/cycles/util/util_image_impl.h b/intern/cycles/util/util_image_impl.h index 4daf1eaac22..a0f9c66f979 100644 --- a/intern/cycles/util/util_image_impl.h +++ b/intern/cycles/util/util_image_impl.h @@ -17,10 +17,10 @@ #ifndef __UTIL_IMAGE_IMPL_H__ #define __UTIL_IMAGE_IMPL_H__ -#include "util_algorithm.h" -#include "util_debug.h" -#include "util_half.h" -#include "util_image.h" +#include "util/util_algorithm.h" +#include "util/util_debug.h" +#include "util/util_half.h" +#include "util/util_image.h" CCL_NAMESPACE_BEGIN -- cgit v1.2.3