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

nv2a: Clip range and see through fix #1707

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

polymetal0
Copy link

Thanks to @coldhex for your work! I used part of the code you mention in #55 (comment) , though I didn't implement any of the other fixes. As per the related commit:

z_perspective is true seems to imply w-buffering and then the w-coordinate stored in the depth buffer should also be interpolated in a perspective-correct way. We do this by calculating w and setting gl_FragDepth in the fragment shader.

Since enabling polygon offset and setting values using glPolygonOffset won't have any effect when manually setting gl_FragDepth, we introduce the depthOffset variable to obtain similar behaviour (but the glPolygonOffset factor-argument is currently not emulated.)

I fixed the regressions by leaving the shader code for no z_perspective unaltered. Also used NV_PGRAPH_ZCLIPMIN and NV_PGRPAH_ZCLIPMAX as clip planes, thus fixing things such as shadows.

as per @coldhex fix:

z_perspective is true seems to imply w-buffering and then the w-coordinate stored in the depth buffer should also be interpolated in a perspective-correct way. We do this by calculating w and setting gl_FragDepth in the fragment shader.

Since enabling polygon offset and setting values using glPolygonOffset
won't have any effect when manually setting gl_FragDepth, we introduce the depthOffset variable to obtain similar behaviour (but the glPolygonOffset factor-argument is currently not emulated.)

*****

I fixed the regressions by leaving the shader code for no z_perspective unaltered.
Also used NV_PGRAPH_ZCLIPMIN and NV_PGRPAH_ZCLIPMAX as clip planes, thus fixing things such as shadows.
@polymetal0 polymetal0 changed the title Clip range and see through fix nv2a: Clip range and see through fix Jul 23, 2024
@polymetal0 polymetal0 marked this pull request as draft July 23, 2024 21:19
@Triticum0
Copy link

Triticum0 commented Jul 25, 2024

If you want you want to make a test case so this can get merged, here a nxdk_pgraph_tests seems to have some test cases related so your fix so you could modify them and confirm it works correctly on hardware and xemu so it can be merge as it should fix a lot of game as clip range affect many games #1020

@polymetal0
Copy link
Author

@Triticum0 sure, I have also been testing with the w_param tests and have been looking at the code. But I'm holding until the Vulkan renderer branch gets merged, since it will introduce fundamental changes in how the shader code is built. I'm implementing my changes locally as it goes.
Unfortunately I have no access to hardware for testing, so I would focus on fixing the w_param tests to have a better understanding of how the hardware works here.

@Triticum0
Copy link

Also forgot to mention you need to fix #1362 as is another reason why clipping occurs on the emulator and not on hardware.

@Fabxx
Copy link
Contributor

Fabxx commented Aug 12, 2024

this draft PR fixes the clipping issues on the first SC

immagine

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.

3 participants