[cairo] [RFC] Cairo operators expressed in shader syntax

Bill Spitzak spitzak at thefoundry.co.uk
Wed May 16 12:48:29 EEST 2007


Daniel Amelang wrote:

>> This is not as complicated as everybody is making out. ALL(*) cairo
>> operators are equivalent to:
>>
>> (src OP dest) * mask + dest * (1-mask).
> 
> If as you say, ALL (except saturate) cairo operators are equivalent to
> that expression, then the following example doesn't make sense (to
> me).
> 
> Say we want a src IN mask IN dst. Using your conjecture above, we can
> rewrite it this way:
> 
> result = (src * dst.a) * mask.a + dst * (1 - mask.a)
> 
> Which is very different than what I have current for the "src IN mask
> IN dst" shader ATM:
> 
> result = src * mask.a * dst.a

That will result in 0 outside the mask. Nobody expects anything to 
change outside the mask. Therefore any expression must produce dst when 
mask is zero.

However you may be right that IN is like saturate and needs to have the 
math fiddled with when the mask is not zero or 1, because right now if 
the mask and the dst.a align with each other the edge is 
double-multiplied and different than if you drew the same thing at a 
higher resolution and down-rezed it.

This might work, it pretents dst.a is 1 when it is the same as the mask 
edge:

src*min(1,dst.a/mask)*mask + dst*(1-mask)



More information about the cairo mailing list