[Bf-committers] what is the difference between these 2 LINEAR operations? or a bug?

Kévin Dietrich kevin.dietrich at mailoo.org
Sun Apr 12 15:25:18 CEST 2015


 

Le 2015-04-12 14:03, oyster a écrit : 

> Hi,
> These 2 operations in different sourcefile puzzled me. can anyone give
> me any hints?
> 1. the 'color node_mix_linear(float t, color col1, color col2)'
> function in https://developer.blender.org/diffusion/B/browse/master/intern/cycles/kernel/shaders/node_mix.osl [1],
> says
> [code]
> if (col2[0] > 0.5)
> outcol[0] = col1[0] + t * (2.0 * (col2[0] - 0.5));
> else
> outcol[0] = col1[0] + t * (2.0 * (col2[0]) - 1.0);
> [/code]
> if col2[0] > 0.5, then outcol[0] = col1[0] + t * (2.0 * (col2[0] -
> 0.5)) = col1[0] + t * (2.0 * col2[0] - 2.0 * 0.5) = col1[0] + t * (2.0
> * col2[0] - 1.0 ). In other word, no matter what is col2[0], outcol[0]
> is always col1[0] + t * (2.0 * (col2[0]) - 1.0).

Busted! :) 

> So, why do we need to
> write 'else' since 'osl-languagespec.pdf' says color is made from 3
> float.

I don't understand what you mean here. 

> 2. in D:\blender-2.74-src\release\scripts\addons\uv_bake_texture_to_vcols.py,
> we can find
> [code]
> elif self.blendingMode == 'LINEAR_LIGHT':
> if col_in[0] > 0.5:
> col_result[0] = col_out[0] + 2.0 * (col_in[0] - 0.5)
> else:
> col_result[0] = col_out[0] + 2.0 * (col_in[0] - 1.0)
> [/code]
> 
> So, I suppose that node_mix.osl is buggy, the correct code should be
> [code]
> if (col2[0] > 0.5)
> outcol[0] = col1[0] + t * (2.0 * (col2[0] - 0.5));
> else
> outcol[0] = col1[0] + t * (2.0 * (col2[0] - 1.0));
> [/code]
> 
> Am I right?

Actually, the formula should just be: (note that we should have a linear
mix, so to further correct) 

col_result = (1.0 - t) * col_out + t * (2.0 * col_in - 1.0); 

that is: 

col_result = mix(col_out, 2.0 * col_in - 1.0, t); 

To understand, the actual formula (as defined by Adobe) is: 

linear_burn(x, 2y, t), if y > 0.5 
linear_dodge(x, 2y - 1, t), otherwise 

where linear_burn is defined as: x + y - 1, and linear_dodge: x + y 
so that gives: 
x + 2y - 1, if (y > 0.5) 
x + 2y - 1, otherwise 

This function (and some others) was originally coined by Adobe to
overcome the weirdness of their software when it comes to color
management (I won't spend too much time explaining)... I personally
would remove it from Blender and Cycles altogether. 

 

Links:
------
[1]
https://developer.blender.org/diffusion/B/browse/master/intern/cycles/kernel/shaders/node_mix.osl


More information about the Bf-committers mailing list