xemu-project / xemu

Original Xbox Emulator for Windows, macOS, and Linux (Active Development)
https://xemu.app
Other
2.78k stars 279 forks source link

Midnight Club 3: DUB Edition Remix - Full bright white headlights #996

Open 7HEPOW opened 2 years ago

7HEPOW commented 2 years ago

Title

https://xemu.app/titles/54540079/ (Seemingly the Remix version is not listed, but the regular has the same issue as of this time of writing)

Bug Description

Headlight cones turn everything they touch full white whenever using a 3rd person view.

Expected Behavior

Have the headlights brighten up things normally

xemu Version

0.7.21

System Information

CPU: 12th Gen Intel(R) Core(TM) i9-12900F OS Platform: Linux OS Version: Manjaro Linux Manufacturer: NVIDIA Corporation GPU Model: NVIDIA GeForce RTX 2070 SUPER/PCIe/SSE2 Driver: 4.0.0 NVIDIA 510.73.05 Shader: 4.00 NVIDIA via Cg compiler

Additional Context

Sample image: 20220529 225413 1869x1080

abaire commented 2 years ago

Can you attach a screenshot from an xbox showing what it should look like? It's clearly too opaque but I'm not familiar with the game and am unsure exactly what it should look like (it seems that having nothing changed directly in front of the car's lights is probably wrong as well)

abaire commented 2 years ago

Glancing through a renderdoc capture I see a suspiciously opaque rendering coming out of a triangle strip that includes NaN values in the diffuse components. The NaNs are not NaNs, they're type UB D3D (unsigned int) values close to pure white for the diffuse and specular components.

Looking back a few draws I see where it builds up the headlight overlay, it looks like it uses the fixed function shader w/ texgen enabled and just passes through 1.0,1.0,1.0,1.0 as the diffuse color. It does this for a number of draws, always writing to the same surface. Oddly, I see draws that appear to remove alpha from the surface, but the diffuse values in the mesh are always all 1.0. This makes me suspect a stale surface, but will need to be investigated. The draws all have colors other than alpha masked off and are using different blending operations to add/subtract from the surface.

Of potential interest: in the draws that apply the overlay, I see the vertex shader being given explicit oPts (point size) values through the weight (v1) input register, though as far as I can see point params are disabled and the INLINE_ARRAY used to pass things in does not include them (meaning they're carried over from the last explicit set).

abaire commented 2 years ago

I did a hardware trace and the headlight overlay texture is dramatically different from what I see in xemu+renderdoc, so things likely start going wrong there. The construction of the texture doesn't involve any other textures so this is probably fairly localized.

WRT the shape of the headlight, it's using depth comparison so #843 might be a contributing factor to things looking off. Still not sure why the blending ends up being so wrong, the depth approximation issue would not explain that.

7HEPOW commented 2 years ago

I roamed the internet for an XBOX screenshot, but the closest I could find was this one on a PS2 on GameFAQs: https://gamefaqs.gamespot.com/ps2/931972-midnight-club-3-dub-edition-remix/images/24

From what it loks like, they seem to have a mesh that simply brightens up what it touches. Here's a shot from the bumper cam with regular lights and high beams, Notice how it affects the palm tree in the second shot: 20220531 171852 1869x1080 High beams: 20220531 171858 1869x1080

Here's also another 3rd person shot affecting a lamp post, ped and tree: 20220531 171925 1869x1080

Too bad it's no compatible with the 360, as I could get a capture there.

I hope it helps in any way :)

abaire commented 2 years ago

Thanks, I ended up dumping my copy of the game to do a hardware trace so I've now got a good idea of what it should look like.

I strongly suspect that the opaqueness has to do with the use of signed blending. xemu maps signed blend operations to the default add/subtract glBlendOperation. I have a WIP test that uses the same mesh & pgraph settings as the relevant draws in the game and it produces dramatically different results on xemu as compared to HW. I'll strip it down to a minimal test case and then start thinking about whether we can do some trivial biasing to approximate the correct behavior or if it's going to fall into the same category as general signed textures and need more substantial work.

abaire commented 2 years ago

Confirmed that this is a difference in behavior related to signed blend modes. Test HW results

It looks like in signed mode, the source value should be interpreted as a 2s complement number, so 0xFF should be the smallest negative number rather than the largest positive. The colors are clamped to (0,1) after the operation.

This is related to #587 and will need special handling to do the blend.

xXRaptorSc0pezXx commented 1 year ago

I'm having this same issue. Any idea when it will get fixed?

image

rvkasper commented 1 year ago

I'm having this same issue. Any idea when it will get fixed?

image

seconded

Santsku commented 1 year ago

I'm having this same issue. Any idea when it will get fixed? image

seconded

image Thirded

abaire commented 1 year ago

I believe the underlying problem is understood and explained by my comments and the test I wrote above, now it needs somebody to do the actual work of fixing it; additional screenshots don't add any new information and just bloat this thread making it harder for somebody to follow and attempt a fix.

The nv2a supports some non-standard behavior when it comes to per-component signed blending, making it non-trivial to emulate on typical consumer GPUs, which is why it wasn't fixed when I traced it down originally.

zb3 commented 5 months ago

Is it only about the headlights? I've turned signed blending operations off and now I don't see these rings (but of course headlights no longer work albeit this seems more acceptable), but did this screw other parts of the game? Here's my patch:

diff --git a/hw/xbox/nv2a/pgraph.c b/hw/xbox/nv2a/pgraph.c
index fbf58fce9a..e948645f0e 100644
--- a/hw/xbox/nv2a/pgraph.c
+++ b/hw/xbox/nv2a/pgraph.c
@@ -2922,13 +2922,19 @@ DEF_METHOD(NV097, SET_BEGIN_END)
             uint32_t equation = GET_MASK(pg->regs[NV_PGRAPH_BLEND],
                                          NV_PGRAPH_BLEND_EQN);
             assert(equation < ARRAY_SIZE(pgraph_blend_equation_map));
-            glBlendEquation(pgraph_blend_equation_map[equation]);
+            if (equation == 5 || equation == 6) {
+                glBlendFunc(GL_ZERO, GL_ONE);
+                glBlendEquation(GL_FUNC_ADD);
+            } else {
+                glBlendEquation(pgraph_blend_equation_map[equation]);
+
+                uint32_t blend_color = pg->regs[NV_PGRAPH_BLENDCOLOR];
+                glBlendColor( ((blend_color >> 16) & 0xFF) / 255.0f, /* red */
+                              ((blend_color >> 8) & 0xFF) / 255.0f,  /* green */
+                              (blend_color & 0xFF) / 255.0f,         /* blue */
+                              ((blend_color >> 24) & 0xFF) / 255.0f);/* alpha */
+            }

-            uint32_t blend_color = pg->regs[NV_PGRAPH_BLENDCOLOR];
-            glBlendColor( ((blend_color >> 16) & 0xFF) / 255.0f, /* red */
-                          ((blend_color >> 8) & 0xFF) / 255.0f,  /* green */
-                          (blend_color & 0xFF) / 255.0f,         /* blue */
-                          ((blend_color >> 24) & 0xFF) / 255.0f);/* alpha */
         } else {
             glDisable(GL_BLEND);
         }
7HEPOW commented 4 months ago

It's only on the players vehicle headlights. Disabling them would be a good temporary fix imo.

zb3 commented 4 months ago

I also observed that for me, all cars are white.. and it even happens without my fix.. Is it supposed to be like that? Was it like that with older xemu versions? I see one screenshot here where the car is green

MatheusLeffa commented 4 months ago

The actual version of XEMU (v0.7.122) still have this problem, could someone please fix this problem?

zb3 commented 4 months ago

@MatheusLeffa if you just want to play you can try my patch that disables headlights, but that requires recompiling. I don't know how to fix the actual problem since this requires not only time, but also significant knowledge transfer

TheMucho commented 3 months ago

@zb3 Hello , I am new to applying patches in xemu, I have a little experience applying it in xeniacanary but in xemu I can't figure out how to make the patch that you shared with us for the lights error work, would you be so kind as to explain how to do it?

zb3 commented 3 months ago

@TheMucho are you able to build xemu from source - first without the patch? If you're not yet there, try reading this https://xemu.app/docs/dev/building-from-source/

Note I only used xemu on linux so I'm not able to assist you if you're using windows..

ghyujkilop commented 2 months ago

I was just about to post this bug lol. Also if you can provide extra details on how/what to patch, that'd be cool. Unfortunately I only use Windows, so maybe not the right crowd for you.