summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJFonS <joan.fonssanchez@gmail.com>2018-11-13 18:19:16 +0100
committerJFonS <joan.fonssanchez@gmail.com>2018-11-13 23:25:05 +0100
commitcbfb7bd613a697503fe046428b0fd0fc08829926 (patch)
tree7172e1b4a10c07d254bc83eda66e0e6fe30a0b27 /scene
parent7f347cc31a121a059e881d4df52add49642dcca3 (diff)
Make 2D particles work OOTB (again)
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/canvas_item.cpp2
-rw-r--r--scene/2d/cpu_particles_2d.cpp28
-rw-r--r--scene/2d/cpu_particles_2d.h11
-rw-r--r--scene/2d/particles_2d.cpp14
-rw-r--r--scene/3d/cpu_particles.cpp29
-rw-r--r--scene/3d/particles.cpp24
6 files changed, 86 insertions, 22 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 7c734d6af5..26ad3d0cdd 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -123,8 +123,6 @@ void CanvasItemMaterial::_update_shader() {
code += "\tfloat h_frames = float(particles_anim_h_frames);\n";
code += "\tfloat v_frames = float(particles_anim_v_frames);\n";
- code += "\tVERTEX.xy /= TEXTURE_PIXEL_SIZE * vec2(h_frames, v_frames);\n";
-
code += "\tint total_frames = particles_anim_h_frames * particles_anim_v_frames;\n";
code += "\tint frame = int(float(total_frames) * INSTANCE_CUSTOM.z);\n";
code += "\tif (particles_anim_loop) {\n";
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index bc2bd9a1c5..a1b624a246 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -153,13 +153,19 @@ CPUParticles2D::DrawOrder CPUParticles2D::get_draw_order() const {
return draw_order;
}
-void CPUParticles2D::_generate_mesh_texture() {
+void CPUParticles2D::_update_mesh_texture() {
+ Size2 tex_size;
+ if (texture.is_valid()) {
+ tex_size = texture->get_size();
+ } else {
+ tex_size = Size2(1, 1);
+ }
PoolVector<Vector2> vertices;
- vertices.push_back(Vector2(-0.5, -0.5));
- vertices.push_back(Vector2(0.5, -0.5));
- vertices.push_back(Vector2(0.5, 0.5));
- vertices.push_back(Vector2(-0.5, 0.5));
+ vertices.push_back(-tex_size * 0.5);
+ vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, 0));
+ vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, tex_size.y));
+ vertices.push_back(-tex_size * 0.5 + Vector2(0, tex_size.y));
PoolVector<Vector2> uvs;
uvs.push_back(Vector2(0, 0));
uvs.push_back(Vector2(1, 0));
@@ -193,6 +199,7 @@ void CPUParticles2D::set_texture(const Ref<Texture> &p_texture) {
texture = p_texture;
update();
+ _update_mesh_texture();
}
Ref<Texture> CPUParticles2D::get_texture() const {
@@ -234,9 +241,12 @@ String CPUParticles2D::get_configuration_warning() const {
CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());
if (get_material().is_null() || (mat && !mat->get_particles_animation())) {
- if (warnings != String())
- warnings += "\n";
- warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
+ if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 ||
+ get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) {
+ if (warnings != String())
+ warnings += "\n";
+ warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
+ }
}
return warnings;
@@ -1396,7 +1406,7 @@ CPUParticles2D::CPUParticles2D() {
update_mutex = Mutex::create();
#endif
- _generate_mesh_texture();
+ _update_mesh_texture();
}
CPUParticles2D::~CPUParticles2D() {
diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h
index 15b7642b5e..d967c3be26 100644
--- a/scene/2d/cpu_particles_2d.h
+++ b/scene/2d/cpu_particles_2d.h
@@ -177,7 +177,7 @@ private:
void _update_render_thread();
- void _generate_mesh_texture();
+ void _update_mesh_texture();
protected:
static void _bind_methods();
@@ -222,15 +222,6 @@ public:
void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
- void set_h_frames(int p_frames);
- int get_h_frames();
-
- void set_v_frames(int p_frames);
- int get_v_frames();
-
- void set_loop_animation(bool p_loop);
- bool get_loop_animation() const;
-
void set_normalmap(const Ref<Texture> &p_normalmap);
Ref<Texture> get_normalmap() const;
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 9c01d81c11..35b7e7da3e 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -219,6 +219,20 @@ String Particles2D::get_configuration_warning() const {
if (warnings != String())
warnings += "\n";
warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted.");
+ } else {
+
+ CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());
+
+ if (get_material().is_null() || (mat && !mat->get_particles_animation())) {
+ const ParticlesMaterial *process = Object::cast_to<ParticlesMaterial>(process_material.ptr());
+ if (process &&
+ (process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
+ process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
+ if (warnings != String())
+ warnings += "\n";
+ warnings += "- " + TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
+ }
+ }
}
return warnings;
diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp
index 5b3229e931..a22708ac99 100644
--- a/scene/3d/cpu_particles.cpp
+++ b/scene/3d/cpu_particles.cpp
@@ -198,6 +198,35 @@ String CPUParticles::get_configuration_warning() const {
String warnings;
+ bool mesh_found = false;
+ bool anim_material_found = false;
+
+ if (get_mesh().is_valid()) {
+ mesh_found = true;
+ for (int j = 0; j < get_mesh()->get_surface_count(); j++) {
+ anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != NULL;
+ SpatialMaterial *spat = Object::cast_to<SpatialMaterial>(get_mesh()->surface_get_material(j).ptr());
+ anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == SpatialMaterial::BILLBOARD_PARTICLES);
+ }
+ }
+
+ anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != NULL;
+ SpatialMaterial *spat = Object::cast_to<SpatialMaterial>(get_material_override().ptr());
+ anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == SpatialMaterial::BILLBOARD_PARTICLES);
+
+ if (!mesh_found) {
+ if (warnings != String())
+ warnings += "\n";
+ warnings += "- " + TTR("Nothing is visible because no mesh has not been assigned.");
+ }
+
+ if (!anim_material_found && (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 ||
+ get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid())) {
+ if (warnings != String())
+ warnings += "\n";
+ warnings += "- " + TTR("CPUParticles animation requires the usage of a SpatialMaterial with \"Billboard Particles\" enabled.");
+ }
+
return warnings;
}
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp
index 10b26778ef..3fff42aa78 100644
--- a/scene/3d/particles.cpp
+++ b/scene/3d/particles.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "particles.h"
+#include "scene/resources/particles_material.h"
#include "servers/visual_server.h"
@@ -226,15 +227,27 @@ String Particles::get_configuration_warning() const {
String warnings;
bool meshes_found = false;
+ bool anim_material_found = false;
for (int i = 0; i < draw_passes.size(); i++) {
if (draw_passes[i].is_valid()) {
meshes_found = true;
- break;
+ for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) {
+ anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != NULL;
+ SpatialMaterial *spat = Object::cast_to<SpatialMaterial>(draw_passes[i]->surface_get_material(j).ptr());
+ anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == SpatialMaterial::BILLBOARD_PARTICLES);
+ }
+ if (meshes_found && anim_material_found) break;
}
}
+ anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != NULL;
+ SpatialMaterial *spat = Object::cast_to<SpatialMaterial>(get_material_override().ptr());
+ anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == SpatialMaterial::BILLBOARD_PARTICLES);
+
if (!meshes_found) {
+ if (warnings != String())
+ warnings += "\n";
warnings += "- " + TTR("Nothing is visible because meshes have not been assigned to draw passes.");
}
@@ -242,6 +255,15 @@ String Particles::get_configuration_warning() const {
if (warnings != String())
warnings += "\n";
warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted.");
+ } else {
+ const ParticlesMaterial *process = Object::cast_to<ParticlesMaterial>(process_material.ptr());
+ if (!anim_material_found && process &&
+ (process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
+ process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
+ if (warnings != String())
+ warnings += "\n";
+ warnings += "- " + TTR("Particles animation requires the usage of a SpatialMaterial with \"Billboard Particles\" enabled.");
+ }
}
return warnings;