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

Added extents for GPU and CPU Particles2D emission points #30665

Closed
Closed
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
4 changes: 2 additions & 2 deletions editor/plugins/cpu_particles_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() {
valid_colors.write[vpc * 4 + 2] = r[(j * s.width + i) * 4 + 2];
valid_colors.write[vpc * 4 + 3] = r[(j * s.width + i) * 4 + 3];
}
valid_positions.write[vpc++] = Point2(i, j);
valid_positions.write[vpc++] = Point2(i, j) / s;

} else {

Expand All @@ -156,7 +156,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() {
}

if (on_border) {
valid_positions.write[vpc] = Point2(i, j);
valid_positions.write[vpc] = Point2(i, j) / s;

if (emode == EMISSION_MODE_BORDER_DIRECTED) {
Vector2 normal;
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/particles_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() {
valid_colors.write[vpc * 4 + 2] = r[(j * s.width + i) * 4 + 2];
valid_colors.write[vpc * 4 + 3] = r[(j * s.width + i) * 4 + 3];
}
valid_positions.write[vpc++] = Point2(i, j);
valid_positions.write[vpc++] = Point2(i, j) / s;

} else {

Expand All @@ -229,7 +229,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() {
}

if (on_border) {
valid_positions.write[vpc] = Point2(i, j);
valid_positions.write[vpc] = Point2(i, j) / s;

if (emode == EMISSION_MODE_BORDER_DIRECTED) {
Vector2 normal;
Expand Down
4 changes: 2 additions & 2 deletions scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void CPUParticles2D::_validate_property(PropertyInfo &property) const {
property.usage = 0;
}

if (property.name == "emission_rect_extents" && emission_shape != EMISSION_SHAPE_RECTANGLE) {
if (property.name == "emission_rect_extents" && emission_shape != EMISSION_SHAPE_RECTANGLE && emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
property.usage = 0;
}

Expand Down Expand Up @@ -690,7 +690,7 @@ void CPUParticles2D::_particles_process(float p_delta) {

int random_idx = Math::rand() % pc;

p.transform[2] = emission_points.get(random_idx);
p.transform[2] = emission_points.get(random_idx) * emission_rect_extents - (emission_rect_extents * 0.5);

if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS && emission_normals.size() == pc) {
p.velocity = emission_normals.get(random_idx);
Expand Down
5 changes: 3 additions & 2 deletions scene/resources/particles_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void ParticlesMaterial::_update_shader() {
FALLTHROUGH;
}
case EMISSION_SHAPE_POINTS: {
code += "uniform vec3 emission_box_extents;\n";
code += "uniform sampler2D emission_texture_points : hint_black;\n";
code += "uniform int emission_texture_point_count;\n";
if (emission_color_texture.is_valid()) {
Expand Down Expand Up @@ -350,7 +351,7 @@ void ParticlesMaterial::_update_shader() {
} break;
case EMISSION_SHAPE_POINTS:
case EMISSION_SHAPE_DIRECTED_POINTS: {
code += " TRANSFORM[3].xyz = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz;\n";
code += " TRANSFORM[3].xyz = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz * emission_box_extents - (emission_box_extents * 0.5);\n";

if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
if (flags[FLAG_DISABLE_Z]) {
Expand Down Expand Up @@ -1052,7 +1053,7 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
property.usage = 0;
}

if (property.name == "emission_box_extents" && emission_shape != EMISSION_SHAPE_BOX) {
if (property.name == "emission_box_extents" && (emission_shape != EMISSION_SHAPE_BOX && emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS)) {
property.usage = 0;
}

Expand Down