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

Initialize particles instance buffer in case it is used before being updated #78852

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

clayjohn
Copy link
Member

Fixes: #71935

We have two buffers that we use for particles:

  1. The particles process buffer (stores full data: Transform, Color, custom, flags, velocity, userdata)
  2. The particles instance buffer (stores only data needed for rendering: transposed Transform, color, custom)

The particles instance buffer is usually filled right after rendering the particles, but when using the "view depth' draw order, or when using billboarding the instance buffer is filled during the scene culling stage (so the camera is known).

This causes problems as particles can get updated late in the frame that they were just allocated (which is the problem that #70418 solved, but only partially).

The bug here comes from relying on unitialized memory (i.e. instance buffer gets created but isn't filled), so the solution is simply to initialize the memory to 0. This way the particles won't draw until ready. Alternative solutions that are less robust are:

  1. try to run fill the instance buffer late (bad solution as camera won't always be known and can cause hiccups in rendering if done too late due to compute->raster dependency)
  2. Track whether the instance buffer has been filled and skip rendering if not (this could be good, but would require significant refactoring on the rendering side as the renderer caches needed particle information.)

@clayjohn clayjohn added bug topic:particles cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release labels Jun 29, 2023
@clayjohn clayjohn added this to the 4.2 milestone Jun 29, 2023
@clayjohn clayjohn requested a review from a team as a code owner June 29, 2023 20:36
@akien-mga akien-mga merged commit c566b03 into godotengine:master Jul 7, 2023
13 checks passed
@akien-mga
Copy link
Member

Thanks!

@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Jul 10, 2023
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.1.

@clayjohn clayjohn deleted the Particles-glitch branch July 19, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instancing GPUParticles3D Causes Flashes Onscreen
3 participants