From 7fa7ce297edee80258938c5c82837dcd8ab8377a Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 30 Nov 2012 13:17:19 +0000 Subject: Map Range: added the same infinity clamping for Z buffer as normalize node. Think should be pretty much harmless since if this node was used for buffers with infinities it already showed artifacts. Now it should be more useful for mapping Z buffers. --- .../compositor/operations/COM_MapRangeOperation.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source/blender/compositor') diff --git a/source/blender/compositor/operations/COM_MapRangeOperation.cpp b/source/blender/compositor/operations/COM_MapRangeOperation.cpp index a18f418e48e..1fe74ade0fc 100644 --- a/source/blender/compositor/operations/COM_MapRangeOperation.cpp +++ b/source/blender/compositor/operations/COM_MapRangeOperation.cpp @@ -43,6 +43,9 @@ void MapRangeOperation::initExecution() this->m_destMaxOperation = this->getInputSocketReader(4); } +/* The code below assumes all data is inside range +- this, and that input buffer is single channel */ +#define BLENDER_ZMAX 10000.0f + void MapRangeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputs[8]; /* includes the 5 inputs + 3 pads */ @@ -61,9 +64,15 @@ void MapRangeOperation::executePixel(float output[4], float x, float y, PixelSam source_max = inputs[2]; dest_min = inputs[3]; dest_max = inputs[4]; - - value = (value - source_min) / (source_max - source_min); - value = dest_min + value * (dest_max - dest_min); + + if (value >= -BLENDER_ZMAX && value <= BLENDER_ZMAX) { + value = (value - source_min) / (source_max - source_min); + value = dest_min + value * (dest_max - dest_min); + } + else if (value > BLENDER_ZMAX) + value = dest_max; + else + value = dest_min; if (this->m_useClamp) { if (dest_max > dest_min) { -- cgit v1.2.3