From 7b7ba584938a276f5fe118bf46a9a9e7aab22655 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 6 Dec 2017 19:43:22 -0300 Subject: [PATCH] -Fix particles with size==0, closes #13931 -Fixed material previews (dont show sphere unless for spatial) --- editor/plugins/editor_preview_plugins.cpp | 41 +++++++++++++---------- scene/2d/canvas_item.cpp | 5 +++ scene/2d/canvas_item.h | 2 ++ scene/3d/particles.cpp | 6 ++++ scene/3d/particles.h | 2 ++ scene/resources/material.cpp | 12 +++++++ scene/resources/material.h | 6 ++++ 7 files changed, 56 insertions(+), 18 deletions(-) diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index ed04c90cc5e..558f44769db 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -235,29 +235,34 @@ Ref EditorMaterialPreviewPlugin::generate(const RES &p_from) { Ref material = p_from; ERR_FAIL_COND_V(material.is_null(), Ref()); - VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); + if (material->get_shader_mode() == Shader::MODE_SPATIAL) { - VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture + VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); - preview_done = false; - VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture - while (!preview_done) { - OS::get_singleton()->delay_usec(10); + preview_done = false; + VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + + while (!preview_done) { + OS::get_singleton()->delay_usec(10); + } + + Ref img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); + + ERR_FAIL_COND_V(!img.is_valid(), Ref()); + + int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + thumbnail_size *= EDSCALE; + img->convert(Image::FORMAT_RGBA8); + img->resize(thumbnail_size, thumbnail_size); + Ref ptex = Ref(memnew(ImageTexture)); + ptex->create_from_image(img, 0); + return ptex; } - Ref img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); - VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); - - ERR_FAIL_COND_V(!img.is_valid(), Ref()); - - int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size *= EDSCALE; - img->convert(Image::FORMAT_RGBA8); - img->resize(thumbnail_size, thumbnail_size); - Ref ptex = Ref(memnew(ImageTexture)); - ptex->create_from_image(img, 0); - return ptex; + return Ref(); } EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 66abe1baa8e..9a3debbe900 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -184,6 +184,11 @@ RID CanvasItemMaterial::get_shader_rid() const { return shader_map[current_key].shader; } +Shader::Mode CanvasItemMaterial::get_shader_mode() const { + + return Shader::MODE_CANVAS_ITEM; +} + void CanvasItemMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index c877a94755f..ccbb528d6f9 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -123,6 +123,8 @@ public: RID get_shader_rid() const; + virtual Shader::Mode get_shader_mode() const; + CanvasItemMaterial(); virtual ~CanvasItemMaterial(); }; diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 2a032f5d964..f8685a7b7cc 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -869,6 +869,7 @@ void ParticlesMaterial::_update_shader() { } //scale by scale code += " float base_scale = mix(scale*tex_scale,1.0,scale_random*scale_rand);\n"; + code += " if (base_scale==0.0) base_scale=0.000001;\n"; if (trail_size_modifier.is_valid()) { code += " if (trail_divisor > 1) { base_scale *= textureLod(trail_size_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0).r; } \n"; } @@ -1360,6 +1361,11 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const { } } +Shader::Mode ParticlesMaterial::get_shader_mode() const { + + return Shader::MODE_PARTICLES; +} + void ParticlesMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &ParticlesMaterial::set_spread); diff --git a/scene/3d/particles.h b/scene/3d/particles.h index 30080360bb2..5b8121e9374 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -390,6 +390,8 @@ public: RID get_shader_rid() const; + virtual Shader::Mode get_shader_mode() const; + ParticlesMaterial(); ~ParticlesMaterial(); }; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 15710f4c142..a6f301af1e8 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -215,6 +215,13 @@ bool ShaderMaterial::_can_do_next_pass() const { return shader.is_valid() && shader->get_mode() == Shader::MODE_SPATIAL; } +Shader::Mode ShaderMaterial::get_shader_mode() const { + if (shader.is_valid()) + return shader->get_mode(); + else + return Shader::MODE_SPATIAL; +} + ShaderMaterial::ShaderMaterial() { } @@ -1662,6 +1669,11 @@ RID SpatialMaterial::get_shader_rid() const { return shader_map[current_key].shader; } +Shader::Mode SpatialMaterial::get_shader_mode() const { + + return Shader::MODE_SPATIAL; +} + void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo); diff --git a/scene/resources/material.h b/scene/resources/material.h index 374ec853dc3..7cfa38fce41 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -69,6 +69,8 @@ public: int get_render_priority() const; virtual RID get_rid() const; + + virtual Shader::Mode get_shader_mode() const = 0; Material(); virtual ~Material(); }; @@ -96,6 +98,8 @@ public: void set_shader_param(const StringName &p_param, const Variant &p_value); Variant get_shader_param(const StringName &p_param) const; + virtual Shader::Mode get_shader_mode() const; + ShaderMaterial(); ~ShaderMaterial(); }; @@ -600,6 +604,8 @@ public: RID get_shader_rid() const; + virtual Shader::Mode get_shader_mode() const; + SpatialMaterial(); virtual ~SpatialMaterial(); };