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: Translate inactive particles to -INF #75162

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions drivers/gles3/shaders/particles_copy.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ uniform highp mat4 inv_emission_transform;

#define PARTICLE_FLAG_ACTIVE uint(1)

#define FLT_MAX float(3.402823466e+38)

void main() {
mat4 txform = mat4(vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0)); // zero scale, becomes invisible.
// Set scale to zero and translate to -INF so particle will be invisible
// even for materials that ignore rotation/scale (i.e. billboards).
mat4 txform = mat4(vec4(0.0), vec4(0.0), vec4(0.0), vec4(-FLT_MAX, -FLT_MAX, -FLT_MAX, 0.0));
if (bool(floatBitsToUint(velocity_flags.w) & PARTICLE_FLAG_ACTIVE)) {
#ifdef MODE_3D
txform = transpose(mat4(xform_1, xform_2, xform_3, vec4(0.0, 0.0, 0.0, 1.0)));
Expand Down Expand Up @@ -102,9 +106,8 @@ void main() {
// as they will be drawn with the node position as origin.
txform = inv_emission_transform * txform;
#endif

txform = transpose(txform);
}
txform = transpose(txform);

instance_color_custom_data = uvec4(packHalf2x16(color.xy), packHalf2x16(color.zw), packHalf2x16(custom.xy), packHalf2x16(custom.zw));
out_xform_1 = txform[0];
Expand Down
7 changes: 4 additions & 3 deletions servers/rendering/renderer_rd/shaders/particles_copy.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ void main() {
// as they will be drawn with the node position as origin.
txform = params.inv_emission_transform * txform;
}

txform = transpose(txform);
} else {
txform = mat4(vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0)); //zero scale, becomes invisible
// Set scale to zero and translate to -INF so particle will be invisible
// even for materials that ignore rotation/scale (i.e. billboards).
txform = mat4(vec4(0.0), vec4(0.0), vec4(0.0), vec4(-1.0 / 0.0, -1.0 / 0.0, -1.0 / 0.0, 0.0));
}
txform = transpose(txform);

if (params.copy_mode_2d) {
uint write_offset = gl_GlobalInvocationID.x * (2 + 1 + 1); //xform + color + custom
Expand Down