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

[3.x] Add half frame to floor() for animated particles UV #53233

Merged
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
2 changes: 1 addition & 1 deletion scene/2d/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void CanvasItemMaterial::_update_shader() {
code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n";
code += "\t}";
code += "\tUV /= vec2(h_frames, v_frames);\n";
code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames);\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess to address @lawnjelly's comment this should be:

Suggested change
code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames);\n";
code += "\tUV += vec2(mod(floor(particle_frame + 0.5), h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames);\n";

Copy link
Member

@akien-mga akien-mga Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then this might be worth doing further up when particle_frame is calculated?

Maybe there's a better operation that could be done on integer values to calculate particle_frame in the first place instead of using floating point?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of hard to read and follow in the stringifyed format 😕 but I think it could be:

floor (mod(particle_frame+0.5, h_frames)) / h_frames

Or do the particle_frame += 0.5; earlier as a once off as @akien-mga points out.

You could also in theory do something like a:

particle_frame = round(particle_frame) + epsilon;

And then not need the later bodges .. but for being a little more 'clever' this is something that would be be bound to screw up on some hardware with some special precision etc.

GLES has next to no support for integers unfortunately, which makes this kind of juggling super annoying but necessary.

code += "}\n";
}

Expand Down
2 changes: 1 addition & 1 deletion scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void SpatialMaterial::_update_shader() {
code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n";
code += "\t}";
code += "\tUV /= vec2(h_frames, v_frames);\n";
code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames);\n";
} break;
}

Expand Down