An issue with the shadows in the MZ RTP (and how to fix it)

I noticed something odd involving the RTP graphics in RPG maker MZ.

In MV, the shadows are pure black and have a transparency of around 50%. Even if the shadow itself is smooth, the color is always pure black (0, 0, 0) which makes it easy to pick, and then remove it or change its color, etc. That doesn't always happen, but it's almost guaranteed to be like that. That means even if the opacity is not fixed like in XP, it still acts like it's pixelart; this is very useful for recolors and things like that.

MZ_transparency01.png


Well, in MZ that doesn't happen at all, the color is just not consistent.

Here's the proof. I tried removing the shadow from the large skeletons in both MV and MZ over a green background and change it to white. MV looks fine but in MZ there's dirtiness all over the place.

MZ_transparency02.png


Spoiler: Possible workaround
I made an Engine for WecTools that fixes this.

Simply paste it on the Engines folder with the name "MZ Alpha Bugfix", open the desired tileset/tile with the tool Simple Image Editor, execute the Engine (you will have to wait a bit if you're doing it with full tilesets), and after checking everything still looks fine, save it again.

Ruby:
"Simple Image Editor"

module MZ_Alpha_Bugfix
 
  # Define here the maximum shadow opacity. Everything over this threshold
  # won't be considered shadow so the color change won't be applied.
  OPACITY_THRESHOLD = 160

  # Define here the maximum luminosity threshold; that means transparent things
  # that are very bright (like halos) won't be considered shadows.
  LUMINOSITY_THRESHOLD = 32

  # If you toggle this option the transparency will be removed in anything
  # that's not considered shadow (from threshold to 255 everything will be
  # flatted to 255)
  FLAT_ALPHA_OBJECT = false
 
end

SIMPLE_IMAGE_NIL = "You must load an image before running this engine"

def color_is_shadow?(color)
  return false if color.alpha > MZ_Alpha_Bugfix::OPACITY_THRESHOLD
  lum = color.red + color.green + color.blue
  return false if lum > MZ_Alpha_Bugfix::LUMINOSITY_THRESHOLD
  return true
end

def run_engine
  if @simple_window.image.nil?
    MessageBox.set(SIMPLE_IMAGE_NIL)
    return
  end
  result = @simple_window.image.clone
  for iy in 0...result.height
    Graphics.update if iy % 100 == 0
    for ix in 0...result.width
      current = result.get_pixel(ix, iy)
      next if current.alpha == 255 || current.alpha == 0
      if !color_is_shadow?(current)
        if MZ_Alpha_Bugfix::FLAT_ALPHA_OBJECT
          current.alpha = 255
          result.set_pixel(ix, iy, current)
        end
      else
        result.set_pixel(ix, iy, Color.new(0, 0, 0, current.alpha))
      end
    end
  end
  @simple_window.image = result
end

run_engine

I hope this helps.
Moved to: Useful Development Tools

Original thread: https://forums.rpgmakerweb.com/threads/an-issue-with-the-shadows-in-the-mz-rtp-and-how-to-fix-it.138691/