diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-12-06 19:43:22 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-12-06 19:51:13 -0300 |
commit | 7b7ba584938a276f5fe118bf46a9a9e7aab22655 (patch) | |
tree | af84a33b749cc34f348e443a09c2330d9863e320 | |
parent | e334b0c4b29aa018dfa4a292598c3041f2a32730 (diff) |
-Fix particles with size==0, closes #13931
-Fixed material previews (dont show sphere unless for spatial)
-rw-r--r-- | editor/plugins/editor_preview_plugins.cpp | 39 | ||||
-rw-r--r-- | scene/2d/canvas_item.cpp | 5 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 2 | ||||
-rw-r--r-- | scene/3d/particles.cpp | 6 | ||||
-rw-r--r-- | scene/3d/particles.h | 2 | ||||
-rw-r--r-- | scene/resources/material.cpp | 12 | ||||
-rw-r--r-- | scene/resources/material.h | 6 |
7 files changed, 55 insertions, 17 deletions
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index ed04c90cc5..558f44769d 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -235,29 +235,34 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) { Ref<Material> material = p_from; ERR_FAIL_COND_V(material.is_null(), Ref<Texture>()); - 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()); - Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); - VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); + while (!preview_done) { + OS::get_singleton()->delay_usec(10); + } - ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>()); + Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); - 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<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); - return ptex; + ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>()); + + 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<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); + return ptex; + } + + return Ref<Texture>(); } EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 66abe1baa8..9a3debbe90 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 c877a94755..ccbb528d6f 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 2a032f5d96..f8685a7b7c 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 30080360bb..5b8121e937 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 15710f4c14..a6f301af1e 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 374ec853dc..7cfa38fce4 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(); }; |