GS: Simulate scan mask (fix transparency in MGS2 & MGS3)#4385
Conversation
| #if PS_SCANMSK_TRANSPARENT | ||
| alpha_blend /= 2.0f; | ||
| #endif |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Merged with current master and made 'Scaled' as default. |
|
Also made this for SW mode too. |
|
Linux and mac should be fixed now |
|
Hi there, where is this option located in the latest dev build? |
|
It's not merged, you need to build this pr. |
|
Thanks, I'm not sure how to do that, so I'll leave it until this is fully integrated. Strange because Sergeanur commented: |
|
Oh yeah I guess that could've been confusing. Click on the 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. |
|
Thanks very much. You've been really helpful! |
|
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 :) |
|
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. |
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. |
|
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 |
|
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). |
|
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. |
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. |
|
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. |
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. |
|
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. Video showcase: BobInterlacingNetworkScreen.mp4 |
lightningterror
left a comment
There was a problem hiding this comment.
Can this be rebased as some changes were made which caused conflicts?
|
Is it possible to have this build where it logs scanmask effects? |
|
Rebased |
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. |
|
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. |
|
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. |
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. |
|
Master: ScanMaskMaster.mp4PR: ScanMaskPR.mp4You can see bob effect on buttons, not sure if intended. Atleast it's not the whole screen flickering now. |
|
That just looks like deinterlacing is disabled |
|
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. |
|
PS1DRV uses scanmask, what a surprise. |
|
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. |
|
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) |
|
We might modify this later but this is fine for now :) |






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.