Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Popular blend modes algorithms implemented in Cg.
fixed G (fixed4 c) { return .299 * c.r + .587 * c.g + .114 * c.b; }
fixed4 Darken (fixed4 a, fixed4 b)
{
fixed4 r = min(a, b);
r.a = b.a;
return r;
}
fixed4 Multiply (fixed4 a, fixed4 b)
{
fixed4 r = a * b;
r.a = b.a;
return r;
}
fixed4 ColorBurn (fixed4 a, fixed4 b)
{
fixed4 r = 1.0 - (1.0 - a) / b;
r.a = b.a;
return r;
}
fixed4 LinearBurn (fixed4 a, fixed4 b)
{
fixed4 r = a + b - 1.0;
r.a = b.a;
return r;
}
fixed4 DarkerColor (fixed4 a, fixed4 b)
{
fixed4 r = G(a) < G(b) ? a : b;
r.a = b.a;
return r;
}
fixed4 Lighten (fixed4 a, fixed4 b)
{
fixed4 r = max(a, b);
r.a = b.a;
return r;
}
fixed4 Screen (fixed4 a, fixed4 b)
{
fixed4 r = 1.0 - (1.0 - a) * (1.0 - b);
r.a = b.a;
return r;
}
fixed4 ColorDodge (fixed4 a, fixed4 b)
{
fixed4 r = a / (1.0 - b);
r.a = b.a;
return r;
}
fixed4 LinearDodge (fixed4 a, fixed4 b)
{
fixed4 r = a + b;
r.a = b.a;
return r;
}
fixed4 LighterColor (fixed4 a, fixed4 b)
{
fixed4 r = G(a) > G(b) ? a : b;
r.a = b.a;
return r;
}
fixed4 Overlay (fixed4 a, fixed4 b)
{
fixed4 r = a > .5 ? 1.0 - 2.0 * (1.0 - a) * (1.0 - b) : 2.0 * a * b;
r.a = b.a;
return r;
}
fixed4 SoftLight (fixed4 a, fixed4 b)
{
fixed4 r = (1.0 - a) * a * b + a * (1.0 - (1.0 - a) * (1.0 - b));
r.a = b.a;
return r;
}
fixed4 HardLight (fixed4 a, fixed4 b)
{
fixed4 r = b > .5 ? 1.0 - (1.0 - a) * (1.0 - 2.0 * (b - .5)) : a * (2.0 * b);
r.a = b.a;
return r;
}
fixed4 VividLight (fixed4 a, fixed4 b)
{
fixed4 r = b > .5 ? a / (1.0 - (b - .5) * 2.0) : 1.0 - (1.0 - a) / (b * 2.0);
r.a = b.a;
return r;
}
fixed4 LinearLight (fixed4 a, fixed4 b)
{
fixed4 r = b > .5 ? a + 2.0 * (b - .5) : a + 2.0 * b - 1.0;
r.a = b.a;
return r;
}
fixed4 PinLight (fixed4 a, fixed4 b)
{
fixed4 r = b > .5 ? max(a, 2.0 * (b - .5)) : min(a, 2.0 * b);
r.a = b.a;
return r;
}
fixed4 HardMix (fixed4 a, fixed4 b)
{
fixed4 r = (b > 1.0 - a) ? 1.0 : .0;
r.a = b.a;
return r;
}
fixed4 Difference (fixed4 a, fixed4 b)
{
fixed4 r = abs(a - b);
r.a = b.a;
return r;
}
fixed4 Exclusion (fixed4 a, fixed4 b)
{
fixed4 r = a + b - 2.0 * a * b;
r.a = b.a;
return r;
}
fixed4 Subtract (fixed4 a, fixed4 b)
{
fixed4 r = a - b;
r.a = b.a;
return r;
}
fixed4 Divide (fixed4 a, fixed4 b)
{
fixed4 r = a / b;
r.a = b.a;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment