YesNoOk
avatar

Explod sprPriority bug (Read 3224 times)

Started by Jmorphman, March 08, 2021, 03:47:32 AM
Share this topic:
Explod sprPriority bug
New #1  March 08, 2021, 03:47:32 AM
  • ******
  • If you’re gonna reach for a star...
  • reach for the lowest one you can.
    • USA
    • network.mugenguild.com/jmorphman
MUGEN will sometimes incorrectly display Explods with the wrong sprPriority, if several Explods are created all at once or in rapid succession, and if all use the same sprPriority. Emphasis on the "sometimes": this error does not at all happen consistently, but it does occur fairly often if the conditions required for it to happen are repeated over and over.

This can be avoided simply by making sure each Explod is given a different sprPriority; of course, it is also possible that this error might not be worth handling if having inconsistent layering on those Explods is not super important.

With the basic explanation of the issue out of the way, I think it'd be best to demonstrate with a concrete example: I discovered this issue a few days ago while I was coding B.B. Hood; over in the MFG Discord, 2OS also mentioned running into the exact same issue before. She has a projectile move where she fires a missile at the opponent, and as the missile travels forward, it is constantly spewing clouds of exhaust. This is what it should look like:

Note that the missile has at this point already exploded without hitting the opponent. Anyhow, my implementation of this effect uses hi-res FX, and I have opted to use a two Explods for each distinct exhaust cloud. One Explod goes on top of the other, with the upper one using additive transparency, and the bottom using subtractive transparency. I therefore had two Explod controllers making each respective type of Explod as the projectile moved forward; I also set each controller's sprPriority to 3.

The top layer Explod appeared in the code above the bottom layer one, which meant that each time a new exhaust cloud Explod pair was created, MUGEN would first draw the top layer Explod and then draw the bottom layer one below the first. This produced the desired effect, and I had used the same basic method for much of B.B. Hood's other effects. However, occasionally, this would happen:

This occurs in exactly the same point of the move as the first screenshot, but note the odd glow in the leftmost exhaust clouds. Here's a picture of the two side by side for better clarity:

Both of these screenshots were taken during the same gameplay session; I did not make any changes or otherwise reload the character in any way. Instead, MUGEN is occasionally screwing up the layering of the many Explods it's currently drawing in these screenshots.

The glow effect is a result of two top layer/additive transparency Explods being layered right over one another (because the glow only happens where two distinct exhaust clouds touch/overlap one another). This can be verified by giving all top layer/additive transparency Explods a sprPriority of 3, and the bottom layer/subtractive transparency Explods a sprPriority of 2:

Each cloud displays fine, except when two of them are overlapping. It's a bit difficult to tell that the glow shows up in the rightmost clouds, so here's a version of the same effects but with proper layering.

In those overlapping spots, the glow shows up because the top layers of each respective cloud have a sprPriority of 3, and the subtractive layers drawn beneath both. In other words, there's an additive layer, then another additive layer, then the two subtractive layers. The desired layering when two clouds overlap one another should instead be additive, then subtractive, then another additive, and then another subtractive.

The previous screen was, of course, just an experiment, showing what happens when this problem is made to happen to every Explod. Going back to the original example, MUGEN will usually and correctly draw each Explod pair with the proper layering. But it does fuck up sometimes, so you should try and avoid situations like this happening (in my case, I just gave each additive/subtractive Explod pair its own unique sprPriority). Then again, if I wasn't using fancy hi-res effects that required dual layered transparency, this thing wouldn't really matter. But even so, if you're ever making a bunch of Explods all at once, and the layering of those Explods is really important, make sure to take precautions to avoid something like this happening!
Last Edit: March 08, 2021, 06:20:32 AM by Jmorphman