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

GS: Simulate scan mask (fix transparency in MGS2 & MGS3) #4385

Merged
merged 1 commit into from
Dec 26, 2021
Merged

GS: Simulate scan mask (fix transparency in MGS2 & MGS3) #4385

merged 1 commit into from
Dec 26, 2021

Conversation

Sergeanur
Copy link
Contributor

Description of Changes

This adds simulation of a PS2 scanline masked drawing on hardware renderer. Masked drawing allowed to skip rendering of primitives on even/odd lines (depending on the mask). As different games may have used this mask for different techniques several options were implemented:
изображение

1. Off (current behaviour)
Ignores the scanmask. For cases when the end result is just fine without it.
изображение

2. Unscaled (set as a default setting as this is what PS2 does)
Do the masking with PS2 resolution in mind. The prohibited lines are skipped by failing depth test in fragment shader/pixel shader.
изображение

3. Scaled
Same as above except actual internal resolution is used.
изображение

4. Transparent
Suitable if masking was used to create an illusion of transparency.
No lines are skipped when drawing. Geometry is rendered with half-transparency (blending forcibly enabled) and disabled z-write.
изображение

Rationale behind Changes

As shown on screenshots above, this fixes transparency issues in Metal Gear Solid games. It should also fix issues in games that used scanmask as well (I don't know any other games that do).

Suggested Testing Steps

MGS2: check Otacon's glasses, also water (when you're on top of it). Bubbles should be seen around player's model when you swim. When entering first person view you should see small particles underwater.
MGS3: cockpit in the first cutscene.

I have not tested further in the game nor I haven't checked with different varieties of HW hacks and blending modes enables, so it would be good if someone could test it too, though I assume everything should be ok.

Comment on lines 863 to 876
#if PS_SCANMSK_TRANSPARENT
alpha_blend /= 2.0f;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

This is just a hack.

The reason MGS doesn't work if you implement scanmsk is nothing to do with the blending equation. It has to do with our PCRTC implementation. You've simply bypassed actually addressing the problem and ignored the functionality of scanmsk to instead render at half transparency. This isn't a fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naturally Transparent mode was only an option to escape the interlaced look given by scaled and unscaled, but you're saying there's more to it with PCRTC? I was under impression that illusion of transparency was given by the TV's of the era but there's also something else that PS2 does that could be fixed too?

Copy link
Member

Choose a reason for hiding this comment

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

Okay, at least I can see where you're coming from then.

No, PCRTC has two displays and MGS sticks the framebuffer in both of them and offsets one of them before compositing them together. PCSX2 just removes this offsetting as a part of another hack that removes blur.

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've tackled GSRenderer::Merge a bit so that the offsetting would depend on a mode. Scaled looks pretty neat now with no noticeable blur. Please check if it's doable.

@Sergeanur
Copy link
Contributor Author

Merged with current master and made 'Scaled' as default.

@Sergeanur
Copy link
Contributor Author

Also made this for SW mode too.

@Sergeanur
Copy link
Contributor Author

Linux and mac should be fixed now

@nobleflame
Copy link

Hi there, where is this option located in the latest dev build?

@F0bes
Copy link
Member

F0bes commented Nov 18, 2021

It's not merged, you need to build this pr.
Or download the artifacts*

@nobleflame
Copy link

Thanks, I'm not sure how to do that, so I'll leave it until this is fully integrated. Strange because Sergeanur commented:
"Merged with current master and made 'Scaled' as default."

@F0bes
Copy link
Member

F0bes commented Nov 18, 2021

Oh yeah I guess that could've been confusing.

Click on the Checks tab and click on windows builds.
Once they finish you'll be able to download a zip with this prs pcsx2

Regarding merging with master, they pulled in master (merged) and updated their pr to eliminate conflicts. If there are conflicts we can't merge it. Another word used for this is rebase.

Conflicts happen when two pieces of code have been changed and git doesn't know how to merge them together.

@nobleflame
Copy link

Thanks very much. You've been really helpful!

@nobleflame
Copy link

Hey, so I’ve got it working. Thanks for putting this together - it works like a charm and now all transparent surfaces are displaying correctly.

Do you have any idea of this will be included in the next official release of PCSX2?

Thanks :)

@RedDevilus
Copy link
Contributor

When it's reviewed to be not hacky, enough perfomant, doesn't break that or other games. So no ETA and i'm not capable or knowledgeable enough for the GS side.

It needs to replace any gsdx mention to GS too.

@refractionpcsx2
Copy link
Member

refractionpcsx2 commented Nov 20, 2021

Hey, so I’ve got it working. Thanks for putting this together - it works like a charm and now all transparent surfaces are displaying correctly.

Do you have any idea of this will be included in the next official release of PCSX2?

Thanks :)

Not in its current state, I don't like it having options in a GUI and a "transparent mode" which is really just a hack I don't like, also I don't like the fact it's forcefully disabling the Z writes, when it should be still doing it for the pixels written. However if the scanmask should be scaled or not, that's another question, I'm not sure which would be most correct. From the emulation point of view, an unscaled version would be more accurate.

@arcum42
Copy link
Contributor

arcum42 commented Nov 20, 2021

Seems like the fact that all the dialog box changes were to a version of the dialog box that no longer exists would be a bit of an issue too. :P

@nobleflame
Copy link

All fair points. Still, hack or not, it does work with MGS2/3. Perhaps it could be implemented in a different place in the menus and once it’s been tested of course.

Thanks to all who work on this stuff. I have absolutely no coding knowledge whatsoever, so your hard work is enabling people like me to enjoy their PS2 libraries (which were, up until recently, gathering dust).

@refractionpcsx2
Copy link
Member

Sure, it works for MGS, but it might not work for anything else. I'd rather it was done correctly, if you don't mind.

@Sergeanur
Copy link
Contributor Author

Hey, so I’ve got it working. Thanks for putting this together - it works like a charm and now all transparent surfaces are displaying correctly.
Do you have any idea of this will be included in the next official release of PCSX2?
Thanks :)

Not in its current state, I don't like it having options in a GUI and a "transparent mode" which is really just a hack I don't like, also I don't like the fact it's forcefully disabling the Z writes, when it should be still doing it for the pixels written. However if the scanmask should be scaled or not, that's another question, I'm not sure which would be most correct. From the emulation point of view, an unscaled version would be more accurate.

I don't think there's an ultimate win without having a GUI option. I don't know if there are games that use scanmask other than MGS but I assume there are, and I assume they may use it for different purposes other than "fake transparency". Unscaled option is most faithful to PS2 but it blurs the image on any resolution, so it's most recommended only if scanmask is relying on native resolution. With scaled you get less blur as you crank the resolution up, so if the game doesn't care about being exact to native resolution, it's a doable option. The problem with both of these modes if that you get "interlaced in motion" geometry, most noticeable in MGS2 when you look on the water in first person mode and move the camera around. You can get rid of it in scaled mode if you increase internal resolution higher than your monitor's but that of course comes with a cost. Because of that I made transparency mode that renders full geometry half-transparent, it eliminates the "interlaced in motion" look without need change the resolution. Z-write is disabled for that mode because in case of MGS2 there were bubbles drawn after water render and because of that Z-test would fail and they end up being not drawn at all. It makes sense that if the developers tried to make transparent objects with scanmask they wouldn't care about rendering order, so I only recommend this if scanmask is used to fake transparent geometry. It's a bit hacky, yeah, but I've played around with it and haven't seen any issues.

@JordanTheToaster
Copy link
Contributor

Fixes transparency on GT4 ghost car in time trial.

image

@nobleflame
Copy link

@JordanTheToaster

that’s interesting. I played through the whole of MGS2 and 3 and the hack does indeed work.

I’ve since switched over to the latest dev build for stability and since new builds come out all of the time, but I’d love it for something like this hack to be added to a future release.

Hoping that someone can fix the blending accuracy issues with MGS2 as well - the skin tones are shown as much darker on some models. setting blending accuracy to high fixes the issue, but causes massive slow down.

@refractionpcsx2
Copy link
Member

but I’d love it for something like this hack to be added to a future release.

Well kinda what I was saying is this doesn't need to be a hack if done properly. it is entirely plausible for this to work properly without hacks. In fact a hack will need to be removed (though preferably made an option) to make this work.

@RedDevilus
Copy link
Contributor

RedDevilus commented Dec 22, 2021

Refraction made an addition to detect scanmask in the Program Log and I found out that all the network config screens use scanmsk, however on this PR it will automatically choose Bob Interlacing instead of Blending Interlacing. Keep in mind this is only for software mode.

image
vs
image

Video showcase:

BobInterlacingNetworkScreen.mp4

Copy link
Contributor

@lightningterror lightningterror left a comment

Choose a reason for hiding this comment

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

Can this be rebased as some changes were made which caused conflicts?

@ghost
Copy link

ghost commented Dec 22, 2021

Is it possible to have this build where it logs scanmask effects?

@Sergeanur
Copy link
Contributor Author

Rebased

@Sergeanur
Copy link
Contributor Author

Refraction made an addition to detect scanmask in the Program Log and I found out that all the network config screens use scanmsk, however on this PR it will automatically choose Bob Interlacing instead of Blending Interlacing. Keep in mind this is only for software mode.

image vs image

Video showcase:
BobInterlacingNetworkScreen.mp4

Looks like an issue of a merge or the SW renderer. In this case scanmask is used with offsetY=0 and should fill the gaps of one frame with another. On HW renderer it makes the image a bit darker though. Not sure if real PS2 would do the same, can't check too.

@refractionpcsx2
Copy link
Member

What I think is happening, is for some reason they chose to only render the lines which would be rendered out to the TV on the next VSync, however because in some situations we can cheat and use "bob" method (this is kind of a fake progressive) which skips all the interlacing and we just display the whole buffer, it causes this effect.

So what needs to be done is if scanmsk is detected and we're using Bob, it needs to change to Blend (preferably) or Weave.

@Sergeanur
Copy link
Contributor Author

Sergeanur commented Dec 22, 2021

Nah, it was DrawSprite that would draw the whole rect instead of scanmasked one, patched it now. The darker HW picture is because of blending btw, setting it to Full fixes it.

@RedDevilus
Copy link
Contributor

RedDevilus commented Dec 22, 2021

Is it possible to have this build where it logs scanmask effects?
pcsx2-scanmsk_with_log.zip

I tried many games, and alas didn't really find any new ones. Like I thought Casper would be one as scanmask seems to layer with transparency but like with PS2 nothing is standard and seems to be quite rare.

@RedDevilus
Copy link
Contributor

Master:

ScanMaskMaster.mp4

PR:

ScanMaskPR.mp4

You can see bob effect on buttons, not sure if intended. Atleast it's not the whole screen flickering now.

@refractionpcsx2
Copy link
Member

refractionpcsx2 commented Dec 22, 2021

That just looks like deinterlacing is disabled

@RedDevilus
Copy link
Contributor

Screenshots if you can't see it clearly, when you move buttons:
image
image

When idle, looks the same as master:
image

@Sergeanur
Copy link
Contributor Author

This is expected due to nature of the effect. Could try enabling Blend if interlacing is set to automatic and scanmask was used while both frames have the same offsetY.

@ghost
Copy link

ghost commented Dec 22, 2021

PS1DRV uses scanmask, what a surprise.

@PCSX2 PCSX2 blocked ghost Dec 24, 2021
@PCSX2 PCSX2 deleted a comment Dec 24, 2021
@ghost
Copy link

ghost commented Dec 24, 2021

So what is the status of this PR, is the implementation of scanmask proper now? And what about the "antiblurr" hack?

@nobleflame
Copy link

So what is the status of this PR, is the implementation of scanmask proper now? And what about the "antiblurr" hack?

Patience. Devs are testing it and it will probably merge when they're confident it's been properly implemented.

@refractionpcsx2
Copy link
Member

I think the PR is good to go, I'm just wanting a code review from @lightningterror and @TellowKrinkle since they are the main GS guys, just to make sure they're happy with the placement of things, mainly the software renderer changes, I don't know if there's a better way to do those (don't know enough about it personally)

@refractionpcsx2
Copy link
Member

We might modify this later but this is fine for now :)

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

Successfully merging this pull request may close these issues.

None yet