Enable light blocking by player weapon#714
Open
joshuarwood wants to merge 8 commits intofgsfdsfgs:portfrom
Open
Enable light blocking by player weapon#714joshuarwood wants to merge 8 commits intofgsfdsfgs:portfrom
joshuarwood wants to merge 8 commits intofgsfdsfgs:portfrom
Conversation
Author
|
Oh, I forgot to upload the example of cloaking behavior. It's similar to N64 where the lights become visible whenever the cloak is active or fading. Here is a video of cloak behavior from this PR: Screencast_20260407_202948.webm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a software test to account for when the player weapon blocks light artifacts on screen. It is intended to be an efficient re-implementation of the old zbuffer test on original hardware. It takes around 2e-5 to 7e-5 seconds to complete on my Ryzen 8840HS cpu with no notable impact up to a 240 FPS cap.
Details
The software test checks whether a ray drawn from the camera location to the screen position of a light artifact intersects a triangle in the player weapon + hand model. It is done in the camera coordinate system with all locations relative to the camera.
Visibility is determined by converting the z distance of the triangle intersection to an N64 depth integer rather than a straight distance comparison to account for the weapon draw loop using different znear/zfar (1.5/1000) compared to the background draw loop (15/10000). This is needed to replicate light bleed through the weapon geometry at close distances on original hardware. The lights in the Carrington test range are a good example of this. The first light should be visible through the Falcon muzzle but not the handle when comparing against ParaLLEl RDP emulation (a proxy for original hardware):
This PR


ParaLLEl RDP


The weapon/hand model intersection test is implemented in
bgTestHitOnWeapon()inside bg.c. It is closely based onbgTestHitOnChr()with 3 notable changes:boundspointer that returns a bbox boundary from the full model geometry. This is useful for culling extra calculations using a simple bounding box test in cases where many lights are on screen. It needs to be done manually since, as far as I can tell, the weapon models don't have bbox model nodes.bgTestLineIntersectsTriangle()for the triangle intersection test instead offunc0002f560(). In theory, both are implementations of the Moller-Trumbore intersection test, butfunc0002f560()seems to take a shortcut or has resolution issues that result in occasional light flicker through the weapon.func0002f560()might be optimized to only work for directions (0, 0, -1) since that is the direction used when applyingbgTestHitOnChr()to character models.Example of light flicker through weapon with

func0002f560()intersection calculation:Light artifact visibility is updated just before weapon matrix information gets wiped at the end of the weapon render loop.
Performance Testing
I did some performance tests at a few locations. There was no notable impact up to a 240 FPS cap on my Ryzen 8840HS.
Additional Exxamples
Left hand blocking light:
