Difference between revisions of "BlendMode"

m
(I reckon it makes sense to have the formulas on the BlendMode page. But uh, someone might want to fix to up my formatting. :P)
Line 1: Line 1:
 
{{newin|[[0.2.0]]|020|type=enum}}
 
{{newin|[[0.2.0]]|020|type=enum}}
Different ways you do alpha blending.
+
How what is drawn is blended with what's already there.
 +
 
 +
The numbers in the formulas are in the interval [0,1]. The resulting color is clamped to [0,1] (except when rendering to HDR [[Canvas]]es).
 +
 
 +
<tt>dst</tt> is the existing color.
 +
 
 +
<tt>src</tt> is the new color.
 +
 
 +
<tt>res</tt> is the resulting color.
 
== Constants ==
 
== Constants ==
;additive: Additive blend mode.
+
;additive
;alpha: Alpha blend mode ('normal').
+
    res.rgba = dst.rgba + (src.rgba * src.a)
 +
;alpha: The default blend mode.
 +
 
 +
    res.rgb = dst.rgb * (1 - src.a) + src.rgb * src.a
 +
    res.a = dst.a * (1 - src.a) + src.a
 +
 
 +
    Before 0.9.0:
 +
    res.rgba = dst.rgba * (1 - src.a) + src.rgba * src.a
 +
 
 
{{newin|[[0.7.0]]|070|type=following choices|plural=y}}
 
{{newin|[[0.7.0]]|070|type=following choices|plural=y}}
;subtractive: Subtractive blend mode.
+
;subtractive
;multiplicative: Multiply blend mode.
+
    res.rgba = dst.rgba - src.rgba * src.a
 +
;multiplicative
 +
    res.r = src.r * dst.r
 +
 
 +
    Before 0.9.0:
 +
    res.rgba = dst.rgba * (1 - src.a) + src.rgba * dst.rgba
 
{{newin|[[0.8.0]]|080|type=following choice}}
 
{{newin|[[0.8.0]]|080|type=following choice}}
;premultiplied: Premultiplied blend mode.
+
;premultiplied
 +
    res.rgba = dst.rgba * (1 - src.a) + src.rgba
 
{{newin|[[0.9.0]]|090|type=following choice}}
 
{{newin|[[0.9.0]]|090|type=following choice}}
;replace: Replace blend mode.
+
;replace
 +
    res.rgba = src.rgba
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]

Revision as of 02:45, 21 June 2013

Available since LÖVE 0.2.0
This enum is not supported in earlier versions.

How what is drawn is blended with what's already there.

The numbers in the formulas are in the interval [0,1]. The resulting color is clamped to [0,1] (except when rendering to HDR Canvases).

dst is the existing color.

src is the new color.

res is the resulting color.

Constants

additive
   res.rgba = dst.rgba + (src.rgba * src.a)
alpha
The default blend mode.
   res.rgb = dst.rgb * (1 - src.a) + src.rgb * src.a
   res.a = dst.a * (1 - src.a) + src.a
   Before 0.9.0:
   res.rgba = dst.rgba * (1 - src.a) + src.rgba * src.a
Available since LÖVE 0.7.0
These following choices are not supported in earlier versions.
subtractive
   res.rgba = dst.rgba - src.rgba * src.a
multiplicative
   res.r = src.r * dst.r
   Before 0.9.0:
   res.rgba = dst.rgba * (1 - src.a) + src.rgba * dst.rgba
Available since LÖVE 0.8.0
This following choice is not supported in earlier versions.
premultiplied
   res.rgba = dst.rgba * (1 - src.a) + src.rgba
Available since LÖVE 0.9.0
This following choice is not supported in earlier versions.
replace
   res.rgba = src.rgba

See Also

Other Languages