-Fix particles with size==0, closes #13931
-Fixed material previews (dont show sphere unless for spatial)
This commit is contained in:
parent
e334b0c4b2
commit
7b7ba58493
7 changed files with 56 additions and 18 deletions
|
@ -235,29 +235,34 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) {
|
||||||
Ref<Material> material = p_from;
|
Ref<Material> material = p_from;
|
||||||
ERR_FAIL_COND_V(material.is_null(), Ref<Texture>());
|
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()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
||||||
VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant());
|
|
||||||
|
|
||||||
while (!preview_done) {
|
preview_done = false;
|
||||||
OS::get_singleton()->delay_usec(10);
|
VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant());
|
||||||
|
|
||||||
|
while (!preview_done) {
|
||||||
|
OS::get_singleton()->delay_usec(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Image> 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<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;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture);
|
return Ref<Texture>();
|
||||||
VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID());
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
|
EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
|
||||||
|
|
|
@ -184,6 +184,11 @@ RID CanvasItemMaterial::get_shader_rid() const {
|
||||||
return shader_map[current_key].shader;
|
return shader_map[current_key].shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shader::Mode CanvasItemMaterial::get_shader_mode() const {
|
||||||
|
|
||||||
|
return Shader::MODE_CANVAS_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
void CanvasItemMaterial::_bind_methods() {
|
void CanvasItemMaterial::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
|
ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
|
||||||
|
|
|
@ -123,6 +123,8 @@ public:
|
||||||
|
|
||||||
RID get_shader_rid() const;
|
RID get_shader_rid() const;
|
||||||
|
|
||||||
|
virtual Shader::Mode get_shader_mode() const;
|
||||||
|
|
||||||
CanvasItemMaterial();
|
CanvasItemMaterial();
|
||||||
virtual ~CanvasItemMaterial();
|
virtual ~CanvasItemMaterial();
|
||||||
};
|
};
|
||||||
|
|
|
@ -869,6 +869,7 @@ void ParticlesMaterial::_update_shader() {
|
||||||
}
|
}
|
||||||
//scale by scale
|
//scale by scale
|
||||||
code += " float base_scale = mix(scale*tex_scale,1.0,scale_random*scale_rand);\n";
|
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()) {
|
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";
|
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() {
|
void ParticlesMaterial::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &ParticlesMaterial::set_spread);
|
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &ParticlesMaterial::set_spread);
|
||||||
|
|
|
@ -390,6 +390,8 @@ public:
|
||||||
|
|
||||||
RID get_shader_rid() const;
|
RID get_shader_rid() const;
|
||||||
|
|
||||||
|
virtual Shader::Mode get_shader_mode() const;
|
||||||
|
|
||||||
ParticlesMaterial();
|
ParticlesMaterial();
|
||||||
~ParticlesMaterial();
|
~ParticlesMaterial();
|
||||||
};
|
};
|
||||||
|
|
|
@ -215,6 +215,13 @@ bool ShaderMaterial::_can_do_next_pass() const {
|
||||||
return shader.is_valid() && shader->get_mode() == Shader::MODE_SPATIAL;
|
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() {
|
ShaderMaterial::ShaderMaterial() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1662,6 +1669,11 @@ RID SpatialMaterial::get_shader_rid() const {
|
||||||
return shader_map[current_key].shader;
|
return shader_map[current_key].shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shader::Mode SpatialMaterial::get_shader_mode() const {
|
||||||
|
|
||||||
|
return Shader::MODE_SPATIAL;
|
||||||
|
}
|
||||||
|
|
||||||
void SpatialMaterial::_bind_methods() {
|
void SpatialMaterial::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo);
|
ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo);
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
int get_render_priority() const;
|
int get_render_priority() const;
|
||||||
|
|
||||||
virtual RID get_rid() const;
|
virtual RID get_rid() const;
|
||||||
|
|
||||||
|
virtual Shader::Mode get_shader_mode() const = 0;
|
||||||
Material();
|
Material();
|
||||||
virtual ~Material();
|
virtual ~Material();
|
||||||
};
|
};
|
||||||
|
@ -96,6 +98,8 @@ public:
|
||||||
void set_shader_param(const StringName &p_param, const Variant &p_value);
|
void set_shader_param(const StringName &p_param, const Variant &p_value);
|
||||||
Variant get_shader_param(const StringName &p_param) const;
|
Variant get_shader_param(const StringName &p_param) const;
|
||||||
|
|
||||||
|
virtual Shader::Mode get_shader_mode() const;
|
||||||
|
|
||||||
ShaderMaterial();
|
ShaderMaterial();
|
||||||
~ShaderMaterial();
|
~ShaderMaterial();
|
||||||
};
|
};
|
||||||
|
@ -600,6 +604,8 @@ public:
|
||||||
|
|
||||||
RID get_shader_rid() const;
|
RID get_shader_rid() const;
|
||||||
|
|
||||||
|
virtual Shader::Mode get_shader_mode() const;
|
||||||
|
|
||||||
SpatialMaterial();
|
SpatialMaterial();
|
||||||
virtual ~SpatialMaterial();
|
virtual ~SpatialMaterial();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue