Additional Blend Types

Additional Blend Types
written by me​

This is a fun hack I've found many years back. It should work with every RGSS version so disregard that we're in the RGSS3 subforum. The used graphics library not only implements the 3 blend types (normal, add, sub) we all know and love but also 4 additional ones: multiply, screen, lighten, darken. Descriptions with examples can be found here and on many other websites. Maybe somebody out there has a use case for them. :LZSsmile: Feel free to use the script in commercial projects or adapt the underlying concept to font sizes without having to credit me (I'd still appreciate it though).

This script (written by me) circumvents the bad value check by temporarily pretending to be a “good” value. This is possible because the argument to #blend_type= is unnecessarily converted to a long (or int) two times: for the check and for the internal blend type assignment; and because the conversion function sends to_int to “unknown” objects.

Spoiler: Script
Ruby:
# ★ Additional Blend Types
# ★★★★★★★★★★★★★★★★★
#
# Author/s : cremno
# RGSS ver : 1 to 3

# old: 0 = normal, 1 = addition, 2 = subtract
# new: 3 = multiply, 4 = screen, 5 = lighten, 6 = darken
class Blend_Type
  def initialize(blend_type)
    @blend_type = blend_type.to_i
    @checked = false
  end
  def to_int
    if @checked
      @checked = false
      @blend_type
    else
      @checked = true
      @blend_type.between?(0, 6) ? 0 : @blend_type
    end
  end
end

[Plane, Sprite].each do |e|
  e.class_eval do
    alias cremno_blend_type= blend_type= unless $@
    def blend_type=(blend_type)
      self.cremno_blend_type = Blend_Type.new(blend_type)
    rescue => e
      raise e.class, e.message, e.backtrace[2..-1]
    end
  end
end

There isn't a demo but here's an example for XP:
Ruby:
$game_screen.pictures[id].show(filename, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
# Show Picture: 1, 'lightmap', Upper Left (0,0), (100%,100%), 192, Lighten
$game_screen.pictures[1].show('lightmap', 0, 0, 0, 100, 100, 192, 5)

For VX Ace use screen instead of $game_screen. Check out this thread to get more information about how to use the equivalent of a specific event command in the Script... command.
mm probably there's a reason they didn't add those blend types. I tried them and:
- multiply and darken are identical to sub
- screen and lighten are identical to add
so unfortunately they don't add any value
Can't confirm that. They all look different and work as intended.

Everything below uses 0.0~1.0 as base for RGB-channels, not 0~255. I know, math can be weird:

★ Add (aka "linear dodge"): The brighter the pixel, more gets added up to white ( A + B ).
★ Subtract (aka "linear burn"): The brighter the pixel, more gets subtracted down to black ( A + B - 1 ).
★ Multiply: Multiplying image and background, darker image results in darker screen ( A * B ).
★ Screen (aka "negative multiply"): Has a lightening-effect different from add ( 1 - ( 1 - A ) * ( 1 - B ) ).
★ Lighten: Applies image's channel to background when it is brighter ( A > B ? A : B ).
★ Darken: Applies image's channel to background when it is darker ( A < B ? A : B ).

~炬燵あ

Original thread: https://forums.rpgmakerweb.com/threads/additional-blend-types.122566/