From b6d12f11fedd9544429745c13381d36ed6d20e8c Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 8 Feb 2012 17:09:30 +0000 Subject: Fix #30004: cycles brightness/contrast node issues. The formula used did not work very well for colors that can be outside of the 0.0..1.0 range, giving +/- infinity results. Now we just use a simple linear contrast factor as proposed by Paolo Sourvinos, and clamp values to be >= 0, and also make the parameters work more in the 0..1 range instead of the 0..100 range, to be more consistent with other nodes. --- intern/cycles/kernel/svm/svm_brightness.h | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'intern/cycles') diff --git a/intern/cycles/kernel/svm/svm_brightness.h b/intern/cycles/kernel/svm/svm_brightness.h index 698899ffd60..7514fc2f2fe 100644 --- a/intern/cycles/kernel/svm/svm_brightness.h +++ b/intern/cycles/kernel/svm/svm_brightness.h @@ -27,28 +27,12 @@ __device void svm_node_brightness(ShaderData *sd, float *stack, uint in_color, u float brightness = stack_load_float(stack, bright_offset); float contrast = stack_load_float(stack, contrast_offset); - brightness *= 1.0f/100.0f; - float delta = contrast * (1.0f/200.0f); - float a = 1.0f - delta * 2.0f; - float b; + float a = 1.0f + contrast; + float b = brightness - contrast*0.5f; - /* - * The algorithm is by Werner D. Streidt - * (http://visca.com/ffactory/archives/5-99/msg00021.html) - * Extracted of OpenCV demhist.c - */ - if (contrast > 0.0f) { - a = (a > 0.0f? (1.0f / a): 0.0f); - b = a * (brightness - delta); - } - else { - delta *= -1.0f; - b = a * (brightness + delta); - } - - color.x = a*color.x + b; - color.y = a*color.y + b; - color.z = a*color.z + b; + color.x = max(a*color.x + b, 0.0f); + color.y = max(a*color.y + b, 0.0f); + color.z = max(a*color.z + b, 0.0f); if (stack_valid(out_color)) stack_store_float3(stack, out_color, color); -- cgit v1.2.3