-
Notifications
You must be signed in to change notification settings - Fork 812
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
Add Fog Occlusion for particles #2766
base: dev
Are you sure you want to change the base?
Conversation
occlusion check based off `RenderSectionManager.getEffectiveRenderDistance`
I don't see a problem with the proposed changes as they are written. But has this been measured to be a problem? I've suspected that some servers will spawn many particles outside the render distance, but have not actually observed this to significantly impact performance. |
Particle rendering on thousands of particles can take up a few milliseconds every frame even on my PC, and I assume the time penalty from all the unnecessary rendering would have a worse effect on a lower-end computer. I do have some older hardware lying around, so I might benchmark the performance thoroughly there. |
On a slower laptop I have (AMD 7530U), a somewhat empty Hypixel Skyblock lobby in the End at 2 Render Distance takes about 1.5ms (lowest was 0.8ms, highest was 2.1ms) to render a frame that stays around 3000 particles. Turning on fog occlusion drops that to the range of 0.4 to 0.6ms, while skipping 28% to 34% of all particles. It seems that at the very least particle-heavy servers do get a noticeable performance increase. |
Interesting that servers send so many particles outside of the fog distance |
The worst-case scenario is that after joining a LAN server hosted on my home PC, the particles I'm spawning with a command block still render at over 100 blocks outside of the render distance (2 again) on the laptop. No Fog, No Fog Occlusioncommand: Fog, No Fog OcclusionIt also seems that particles are rendering over the stars when in fog. This behavior also happens in Vanilla. Fog + Fog OcclusionThis is fixed with Particle Fog Occlusion. |
It seems that particles actually do render over the fog itself (w/o Fog Occlusion), but since they use the sky fog color it's not visible until sunrise/sunset. This then causes some ugly transitions with long-distance particles like campfire smoke. Side note: particles don't render behind translucent blocks/fluids, but I think this is intended behavior. BenchmarkingIn the somewhat plausible situation someone has buildings outside of render distance with lots of campfires going, performance can increase by almost 2X. (Rendering the same setup from the first image, a 15x15 fill of campfires) Rendering the scene inside of the fog distance looks like it has the same performance, so at the very least the occlusion check has a negligible impact. The performance gains from this are going to be extremely situational, probably only having an effect on large multiplayer servers, some large builds, and mods/datapacks that make use of long-distance effects (i.e. some biomes from Terralith and Better End.), but it could fix some existing visual issues with particles. |
Will underwater fog and fog from blindness effect also affect particle culling? This should significantly improve performance in many mini-games related to these effects. |
As of that latest commit, Darkness + Blindness now have an effect on culling. (I forgot to use the fog end distance 😔) Water fog didn't drop the particle count by much after entering it, but I need to test that properly later. |
It looks like water fog isn't actually getting rid of particles because of fog, and I have made a few observations:
Because of that being an unrelated problem, this feature is complete and working properly. The only extra thing I could do is also factor in height for distance to cull particles in a sphere instead of a cylinder (This didn't really provide much of a boost in render time in my survival world though). |
I'm not sure if this is best suited for Sodium, but this PR fixes Minecraft's behavior of rendering particles regardless of fog occlusion. This PR makes Sodium skip particle rendering if a particle falls behind opaque fog and additionally has Fog Occlusion enabled (essentially just re-using the existing fog occlusion logic).
(Render Distance is set to 2.)
render
called.Let me know if I need to fix/rework anything!