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

GPUParticles3D: Zero modelview matrix of billboard materials when model matrix is zeroes #75090

Closed

Conversation

ecmjohnson
Copy link
Contributor

Resolves #72650 by zeroing the modelview matrix of billboards when all scales (X, Y, Z) of the model matrix are exactly zero. This was hypothesized to be the issue by @QbieShay in this comment: the particle gets a zero transform when it is inactive, but since the billboarded material ignores the rotation/scale of the model matrix, this method of preventing them from being rendered was not working.

gpuparticles_billboarding_resolution

This implementation introduces a conditional branch to the shader for billboarded materials. An alternative is a non-branching implementation that adds an unconditional 16 multiplications with e.g. the following line:

code += "	MODELVIEW_MATRIX = float(scale_sum != 0.0) * MODELVIEW_MATRIX;\n";

I chose the branching form since it will nearly always be synchronized across the wavefront, particularly in the non-particle use-case where the scales will all be non-zero, and this will most often avoid the cost of the 16 multiplications.

@ecmjohnson
Copy link
Contributor Author

I made a mistake in my initial implementation as there is no guarantee that the scales will be along the major diagonal of the affine matrix. In fact, completely valid affine transformations can have an affine matrix with a trace of zero.

Instead the check should be against a property of the affine matrix that we know must hold: invertibility. For this it suffices to sum the first column of the affine matrix and check if that is zero. A zero first column cannot be the case for any valid affine transformation.

@ecmjohnson ecmjohnson force-pushed the gpuparticles_zero_scale branch from d8cfc8b to 0144868 Compare March 20, 2023 23:21
@ecmjohnson ecmjohnson changed the title GPUParticles3D: Zero modelview matrix of billboard materials when scales are exactly zero GPUParticles3D: Zero modelview matrix of billboard materials when model matrix is zeroes Mar 20, 2023
@ecmjohnson
Copy link
Contributor Author

PR #75162 resolves the same issue in a cleaner way and in a way that is more in alignment with how "Hide On Contact" collision mode works

@ecmjohnson ecmjohnson closed this Mar 26, 2023
@ecmjohnson ecmjohnson deleted the gpuparticles_zero_scale branch December 11, 2023 03:00
@AThousandShips AThousandShips removed this from the 4.1 milestone Dec 11, 2023
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.

GPUParticles3D flickers frozen particle at world origin (0, 0, 0) when shader material has y-billboard set
4 participants