Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

konami/mystwarr_v.cpp, k053246_k053247_k055673.cpp: improve sprite blending #13328

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

FredYeye
Copy link
Contributor

@FredYeye FredYeye commented Feb 3, 2025

This pull request is split into three commits:

  1. d0faecd
    The sprite effect attribute bits in mystwarr, metamrph and viostorm are used for sprite blending purposes. I changed the sprite callbacks to attach the attribute bits.

  2. e7f911e
    Blending was being done in reverse. There are probably several reasons why this was never noticed, but two reasons would be that 0% and 100% blending worked as intended and almost no games use sprite blending (at least in current MAME). Simple solution: reverse the operands to alpha_blend_r32().

  3. 8184130
    Optional commit: minor cleanup of zdrawgfxzoom32GP(), the function that contains the alpha_blend_r32() calls. Initially I had planned to make bigger changes, like condensing the switch-cases, but I wasn't satisfied with my attempts at doing so. Instead I opted for a more conservative cleanup pass. It appears to give a marginal speedup as a bonus.
    This is the least important commit of the three, so if it's deemed unnecessary it can be dropped.


This fixes transparent sprites in mystwarr, metamrph and viostorm. Mystwarr & viostorm make little use of these; it's a bit more apparent in metamrph.
I assume this affects other systems too - like konami GX? I ran all GX games with -bench 400 and didn't run into any sprites that use any transparency. Either GX games do not have transparent sprites or they're not tagged as such in current MAME. This is hardly the perfect testing method, so please let me know if I should be testing any other games and systems.

mark sprites with their attribute bits for blending
-move variable declarations closer to use
-use appropriate variable types
-mark applicable variables as const
-move "cull off-screen objects" early out check earlier in function
@angelosa
Copy link
Member

angelosa commented Feb 4, 2025

I'm not gonna judge the changes here (they looks reasonable to me), you may give a shot at dadandrn Centaur and Fungus stages (both uses blending in one form or another). Don't think sexyparo stages 3L and 3W (i.e. Castlevania stage and its mission 2 quota satisfied equivalent) are affected here but you may try anyway.

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 4, 2025

Good call on dadandrn! I had trouble finding real HW footage so I didn't dig into it earlier. Found a video here to compare against. I switched it over to using the mystwarr sprite callback and blending does seem to work! It was using the gaiapols callback which is slightly different, so I will play through the rest of the game and see if anything looks out of place.

Will check sexyparo soonish, whenever I have time.

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 5, 2025

I pushed the dadandrn change. This makes blending happen. It should be mentioned that many effects still don't look quite right due to the brightness registers going unused in mame at the moment.

There is some other problem with blending, maybe overlapping blended sprites? This can be seen in dadandrn (centaur light pillar) and metamrph (4 solid colors overlay in the intro). Fixing this in a timely manner may be out of scope for this PR though...

-move back "dst_" vars under appropriate comment
- further reduce reuse of "eax" variable
@FredYeye FredYeye closed this Feb 5, 2025
@FredYeye FredYeye reopened this Feb 5, 2025
@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 5, 2025

(accidentally closed request somehow, don't mind that)

@happppp
Copy link
Member

happppp commented Feb 5, 2025

While you're at it, could you rename "eax" to something more contextual like "delta"?
It's Acho's code, he had a habit of naming temp variables after Intel X86 registers.

I mean for the ones you already modified, such as:
if (int eax = dst_lasty - dst_maxy; eax > 0) dst_h -= eax;
if (int delta = dst_lasty - dst_maxy; delta > 0) dst_h -= delta;

-use cliprect directly inside function
-rename various "eax" variables
@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 6, 2025

Yes, you're right, that should be done. It seems like most of the "eax" vars are either a distance between a clipping rect and a sprite coord, or a sprite tile byte used as a palette index. I've tried to at least make the names a little more descriptive.

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 6, 2025

I took a look at sexyparo. For stage 3, there's a layer of solid ink that should be transparent. I assume this is a problem with tile / layer blending. I want to get to that eventually but I haven't made much headway there.

The first boss in the boss rush is some blue slime with a coin inside. That thing appears to use blending and seems to work as intended in mame.

@angelosa
Copy link
Member

angelosa commented Feb 6, 2025

iirc the very same path is used by Castlevania stage for the glass background meshes (which should blend, around the boss).

dadandrn use a form of color mixing, specifically a powered up version of how SNES PPU does things i.e. a main screen and a sub screen where a color DAC offset is added/subtracted depending on what's happening on screen.
You can cross check what I mean with the attract intro cycle, where on basic form it just fade-in or out the full video output, while enabling finer tuned control around the Moai punching the camera.

Copy link
Member

@cuavas cuavas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galibert do you have an opinion on this change?

Giving Acho’s variables descriptive names is always a good idea, anyway.

Comment on lines 447 to 450
#define FP 19
#define FPONE (1<<FP)
#define FPHALF (1<<(FP-1))
#define FPENT 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you turn these into constexpr int or constexpr unsigned while you’re at it? Preprocessor macros have a habit of causing difficult to diagnose errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed these to constexpr int and realized that FPONE and FPHALF go unused. Should I comment them out or outright remove them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove them, the definitions contain no unique information as they’re just derived from FP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, done.

Comment on lines 92 to 94
*color = (*color & 0x1f) | m_sprite_colorbase | effect_attributes;

// Bit8 & 9 are effect attributes. It is not known whether the effects are generated by external logic.
if ((attr & 0x300) != 0x300)
{
*color = c;
*priority_mask = (attr & 0xe0) >> 2;
}
else
{
*color = c | 3<<K055555_MIXSHIFT | K055555_SKIPSHADOW; // reflection?
*priority_mask = 0x1c;
}
if (shadow == 0b11) { *color |= K055555_SKIPSHADOW; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You haven’t used braces on your other single line if statements (e.g. the if (foo) return; in k053246_k053247_k055673.cpp – why have them here? You could avoid the if anyway if you wanted, like:

	*color = (*color & 0x1f) | m_sprite_colorbase | effect_attributes | ((shadow == 0b11) ? K055555_SKIPSHADOW : 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't pay enough attention there, I've changed it to use your suggestion, thanks!

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 7, 2025

dadandrn use a form of color mixing, specifically a powered up version of how SNES PPU does things i.e. a main screen and a sub screen where a color DAC offset is added/subtracted depending on what's happening on screen. You can cross check what I mean with the attract intro cycle, where on basic form it just fade-in or out the full video output, while enabling finer tuned control around the Moai punching the camera.

I see!! Yeah, I can tell there's still things to improve on.

@TheCoolPup
Copy link

someone trying to fix video emulation for konami stuff??? its a mircale!

@TheCoolPup
Copy link

also i have noticed one regression, if you look at eagle's teeth, they seem to be the wrong color
Monster Maulers (ver EAA)  mmaulers  - MAME 0 274 (LLP64) 2_7_2025 5_46_35 PM
And also in terms of the water missing in this scene could this be a blending issue or something else entirely?
Monster Maulers (ver EAA)  mmaulers  - MAME 0 274 (LLP64) 2_7_2025 5_48_10 PM

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 7, 2025

Yep, noticed the teeth as well! Will have to investigate

@TheCoolPup
Copy link

so the water is a blend issue?

@TheCoolPup
Copy link

also here is some pcb footage if you want it https://youtu.be/iuLQnJeBKZo?feature=shared&t=6197

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 8, 2025

The teeth regression appears to have been a priority mask issue. I updated the mystwarr_sprite_callback priority mask to use one less bit, which fixes it. This fix seems to make sense: the mask bits were using a bit that I guess is used for palette indexing (*color & 0x1f).

As a bonus, it also fixes the final boss's monitors in mystic warriors! Thanks for pointing it out.

so the water is a blend issue?

It's possible! This PR is only focusing on sprites, though.


I think this is all I will get done for this PR (unless there are other suggestions / objections). dadandrn is far from perfect as angelosa pointed out, but I think fixing that won't be as simple.

@TheCoolPup
Copy link

So happy someone is working on fixing the issues these games have had, thank you again

@FredYeye
Copy link
Contributor Author

FredYeye commented Feb 8, 2025

Alright, so I went ahead and made one last addition. I'm sure I'm being annoying now 😅.
The whole reason I started changing zdrawgfxzoom32GP in the first place was because there were 4 different call sites to the alpha blending function. Almost all the switch cases are very similar so I condensed them down. Drawmodes 0-3 now take the same path, while mode 4 is still separate. There's still different code paths for zoom though, but this reduces some code duplication.

In my testing all current changes come out ~7% faster than current mame, so it seems the compiler can work with drawmode checks inside the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants