forked from bartvdbraak/blender
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.
This commit is contained in:
parent
8e81da423c
commit
b6d12f11fe
@ -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 brightness = stack_load_float(stack, bright_offset);
|
||||||
float contrast = stack_load_float(stack, contrast_offset);
|
float contrast = stack_load_float(stack, contrast_offset);
|
||||||
|
|
||||||
brightness *= 1.0f/100.0f;
|
float a = 1.0f + contrast;
|
||||||
float delta = contrast * (1.0f/200.0f);
|
float b = brightness - contrast*0.5f;
|
||||||
float a = 1.0f - delta * 2.0f;
|
|
||||||
float b;
|
|
||||||
|
|
||||||
/*
|
color.x = max(a*color.x + b, 0.0f);
|
||||||
* The algorithm is by Werner D. Streidt
|
color.y = max(a*color.y + b, 0.0f);
|
||||||
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
|
color.z = max(a*color.z + b, 0.0f);
|
||||||
* 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;
|
|
||||||
|
|
||||||
if (stack_valid(out_color))
|
if (stack_valid(out_color))
|
||||||
stack_store_float3(stack, out_color, color);
|
stack_store_float3(stack, out_color, color);
|
||||||
|
Loading…
Reference in New Issue
Block a user