libretro / beetle-psx-libretro

Standalone port/fork of Mednafen PSX to the Libretro API.
GNU General Public License v2.0
309 stars 131 forks source link

[PGXP] Spyro 1 floor textures close to camera glitch with Perspective Correction on #466

Open Magicql opened 5 years ago

Magicql commented 5 years ago

When PGXP mode is enabled, some of the floor tiles close to the camera behind Spyro appear incorrectly rendered. The issue is constant and occurs on both memory only and memory + CPU modes, and on both GL and Vulkan renderers.

PGXP mode enabled: 20181213224835_1

PGXP mode disabled: 20181213224841_1

DonelBueno commented 5 years ago

This is a very old and known issue. It happens in NFS High Stakes too. Just disable perspective correct texturing.

iCatButler said that PGXP is going to be revamped sometime.

iCatButler commented 5 years ago

This isn't technically a bug within PGXP. It's caused by the developers playing around with perspective, presumably to make better use of the fixed point range available to them.

A lot of PS1 games will calculate transformation of various parts of the scene at different scales. For instance character models and items in Crash Bandicoot 3 are 4x the scale of the level geometry, but they're also positioned 4x as far from the viewer, so perspective makes them appear the correct size. This is one of the reasons why it's not possible to generate a proper z-buffer automatically for most PS1 games.

Insomniac use this trick in Spyro for characters and items, but they also use it for some of the terrain vertices when they're very close to the viewer. It's when these vertices share a triangle with vertices at a different scale that the perspective correction breaks down, technically that triangle is really big and stretches far into the distance. On real hardware the PS1 GPU has already discarded the depth information so it's not a problem.

pcsxr0298 Increasing depth is shown here as a colour from blue through green to red. Note how the objects and very close vertices have much greater depth than the nearby terrain.

There's a similar issue with Gran Turismo, which stitches the terrain together from patches, each of which use the full range of depth values available. So far the only ways I can think to fix it would be game specific hacks or a slider for rejecting perspective correction on triangles with a depth range exceeding some arbitrary size, neither of which is a great solution.

rz5 commented 5 years ago

Ok then, so the textures glitch out because the GAME itself is applying different rules to triangles close to the viewer.

I dunno if this issue should remain open (to keep this discoverable and prevent duplicate issues) or closed because it's not PGXP's fault that this game is doing non-photorealistic transformations to certain vertices.

coccofresco commented 5 years ago

So far the only ways I can think to fix it would be game specific hacks or a slider for rejecting perspective correction on triangles with a depth range exceeding some arbitrary size, neither of which is a great solution.

Would be possible compare the depth range with the ordering table to get automatically the correct scale ?

iCatButler commented 5 years ago

Would be possible compare the depth range with the ordering table to get automatically the correct scale ?

Spyro doesn't seem to use ordering tables, it doesn't use DMA 6 (which clears the OT) and there don't seem to be any of the characteristic empty nodes in the data it sends to the GPU. Insomniac must have implemented their own method of sorting geometry instead.

Marcelo20XX commented 5 years ago

So far the only ways I can think to fix it would be ...rejecting perspective correction on triangles with a depth range exceeding some arbitrary size...

Can you tell me where in the code I can implement this please. I would like to try it and see if this can solve the issue at least for Spyro and Gran Turismo 2, thanks

kosior555 commented 4 years ago

I have the latest version of RetroArch and Beetle PSX HW, and the issue is still there? Is something wrong with my setup?

rz5 commented 4 years ago

@kosior555 - The bug hasn't been fixed. If you want to know why it happens, read iCatButler's comments.

kosior555 commented 4 years ago

@rz5 I read, but I wanted to make sure :) Let me add screenshots from Spyro 2 and 3, here it is the same with MEMORY + CPU turned on (at this moment the only way to get rid of texture gaps, the vertex cache gives a weak effect in my opinion) s2 s3 In this mode you could play, but this distortion is quite annoying to me, in addition, in Spyro 1 we get a strong freez when there is a portal in the field of view, and Spyro 2 and 3 are starting to experience minor menu issues. Videos: https://streamable.com/a2wx6 https://streamable.com/c6oj1 https://streamable.com/2oco6

DonelBueno commented 4 years ago

@xzn Are you aware of this issue? Any ideas on how to fix it? If affects lots of games.

iCatButler said this about it (just see some posts above):

So far the only ways I can think to fix it would be game specific hacks or a slider for rejecting perspective correction on triangles with a depth range exceeding some arbitrary size, neither of which is a great solution.

xzn commented 4 years ago

@DonelBueno it's really as you said just turn off perspective texture for those games.

I tried implement iCB's second suggestion (reject perspective correction for polygons whose depth ranges are too high), it sort of works for Spyro but couldn't get it to work reliably for NFS High Stakes.

I don't have any other solution to this either.

Kazeira commented 4 years ago

@xzn I think rejecting too high depth ranges is only one of the possible checks. In NFS only quads seems to be affected by this issue: if there is a way to check if the quad isn't broken, I mean that the 4 xyz values are coherent, maybe NFS, GT2 and some other games will be "corrected".