summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-04-06 23:36:37 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-04-06 23:49:27 -0300
commit74808ac4d9176180dc7ecace99723edab8a73e0e (patch)
tree065e903073bbdebe864bb6322ca0abc2fca108bb /scene/2d
parent25d09b92be0f5d86cdee6eada80823cdcc2d42bc (diff)
New particle system, mostly working, some small features missing.
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/canvas_item.cpp130
-rw-r--r--scene/2d/canvas_item.h38
-rw-r--r--scene/2d/tile_map.cpp4
3 files changed, 11 insertions, 161 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 3e5bb7f572..9ac12de45e 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -37,124 +37,6 @@
#include "scene/scene_string_names.h"
#include "servers/visual_server.h"
-bool CanvasItemMaterial::_set(const StringName &p_name, const Variant &p_value) {
-
- if (p_name == SceneStringNames::get_singleton()->shader_shader) {
- set_shader(p_value);
- return true;
- } else {
-
- if (shader.is_valid()) {
-
- StringName pr = shader->remap_param(p_name);
- if (!pr) {
- String n = p_name;
- if (n.find("param/") == 0) { //backwards compatibility
- pr = n.substr(6, n.length());
- }
- }
- if (pr) {
- VisualServer::get_singleton()->material_set_param(_get_material(), pr, p_value);
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool CanvasItemMaterial::_get(const StringName &p_name, Variant &r_ret) const {
-
- if (p_name == SceneStringNames::get_singleton()->shader_shader) {
-
- r_ret = get_shader();
- return true;
-
- } else {
-
- if (shader.is_valid()) {
-
- StringName pr = shader->remap_param(p_name);
- if (pr) {
- r_ret = VisualServer::get_singleton()->material_get_param(_get_material(), pr);
- return true;
- }
- }
- }
-
- return false;
-}
-
-void CanvasItemMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
-
- p_list->push_back(PropertyInfo(Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"));
-
- if (!shader.is_null()) {
-
- shader->get_param_list(p_list);
- }
-}
-
-void CanvasItemMaterial::set_shader(const Ref<Shader> &p_shader) {
-
- ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode() != Shader::MODE_CANVAS_ITEM);
-
- shader = p_shader;
-
- RID rid;
- if (shader.is_valid())
- rid = shader->get_rid();
-
- VS::get_singleton()->material_set_shader(_get_material(), rid);
- _change_notify(); //properties for shader exposed
- emit_changed();
-}
-
-Ref<Shader> CanvasItemMaterial::get_shader() const {
-
- return shader;
-}
-
-void CanvasItemMaterial::set_shader_param(const StringName &p_param, const Variant &p_value) {
-
- VS::get_singleton()->material_set_param(_get_material(), p_param, p_value);
-}
-
-Variant CanvasItemMaterial::get_shader_param(const StringName &p_param) const {
-
- return VS::get_singleton()->material_get_param(_get_material(), p_param);
-}
-
-void CanvasItemMaterial::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("set_shader", "shader:Shader"), &CanvasItemMaterial::set_shader);
- ClassDB::bind_method(D_METHOD("get_shader:Shader"), &CanvasItemMaterial::get_shader);
- ClassDB::bind_method(D_METHOD("set_shader_param", "param", "value"), &CanvasItemMaterial::set_shader_param);
- ClassDB::bind_method(D_METHOD("get_shader_param", "param"), &CanvasItemMaterial::get_shader_param);
-}
-
-void CanvasItemMaterial::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
-
- String f = p_function.operator String();
- if ((f == "get_shader_param" || f == "set_shader_param") && p_idx == 0) {
-
- if (shader.is_valid()) {
- List<PropertyInfo> pl;
- shader->get_param_list(&pl);
- for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) {
- r_options->push_back("\"" + E->get().name.replace_first("shader_param/", "") + "\"");
- }
- }
- }
- Resource::get_argument_options(p_function, p_idx, r_options);
-}
-
-CanvasItemMaterial::CanvasItemMaterial() {
-}
-
-CanvasItemMaterial::~CanvasItemMaterial() {
-}
-
///////////////////////////////////////////////////////////////////
bool CanvasItem::is_visible_in_tree() const {
@@ -770,7 +652,7 @@ bool CanvasItem::is_draw_behind_parent_enabled() const {
return behind;
}
-void CanvasItem::set_material(const Ref<CanvasItemMaterial> &p_material) {
+void CanvasItem::set_material(const Ref<ShaderMaterial> &p_material) {
material = p_material;
RID rid;
@@ -791,7 +673,7 @@ bool CanvasItem::get_use_parent_material() const {
return use_parent_material;
}
-Ref<CanvasItemMaterial> CanvasItem::get_material() const {
+Ref<ShaderMaterial> CanvasItem::get_material() const {
return material;
}
@@ -801,7 +683,7 @@ Vector2 CanvasItem::make_canvas_pos_local(const Vector2 &screen_point) const {
ERR_FAIL_COND_V(!is_inside_tree(), screen_point);
Transform2D local_matrix = (get_canvas_transform() *
- get_global_transform())
+ get_global_transform())
.affine_inverse();
return local_matrix.xform(screen_point);
@@ -895,8 +777,8 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasItem::get_world_2d);
//ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasItem::get_viewport);
- ClassDB::bind_method(D_METHOD("set_material", "material:CanvasItemMaterial"), &CanvasItem::set_material);
- ClassDB::bind_method(D_METHOD("get_material:CanvasItemMaterial"), &CanvasItem::get_material);
+ ClassDB::bind_method(D_METHOD("set_material", "material:ShaderMaterial"), &CanvasItem::set_material);
+ ClassDB::bind_method(D_METHOD("get_material:ShaderMaterial"), &CanvasItem::get_material);
ClassDB::bind_method(D_METHOD("set_use_parent_material", "enable"), &CanvasItem::set_use_parent_material);
ClassDB::bind_method(D_METHOD("get_use_parent_material"), &CanvasItem::get_use_parent_material);
@@ -922,7 +804,7 @@ void CanvasItem::_bind_methods() {
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask");
ADD_GROUP("Material", "");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), "set_material", "get_material");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial"), "set_material", "get_material");
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material");
//exporting these two things doesn't really make much sense i think
//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), "set_as_toplevel","is_set_as_toplevel") ;
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index a188ce495a..a5074991da 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -41,38 +41,6 @@ class Font;
class StyleBox;
-class CanvasItemMaterial : public Material {
-
- GDCLASS(CanvasItemMaterial, Material);
- Ref<Shader> shader;
-
-public:
- /*enum ShadingMode {
- SHADING_NORMAL,
- SHADING_UNSHADED,
- SHADING_ONLY_LIGHT,
- };*/
-
-protected:
- bool _set(const StringName &p_name, const Variant &p_value);
- bool _get(const StringName &p_name, Variant &r_ret) const;
- void _get_property_list(List<PropertyInfo> *p_list) const;
-
- static void _bind_methods();
-
- void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
-
-public:
- void set_shader(const Ref<Shader> &p_shader);
- Ref<Shader> get_shader() const;
-
- void set_shader_param(const StringName &p_param, const Variant &p_value);
- Variant get_shader_param(const StringName &p_param) const;
-
- CanvasItemMaterial();
- ~CanvasItemMaterial();
-};
-
class CanvasItem : public Node {
GDCLASS(CanvasItem, Node);
@@ -114,7 +82,7 @@ private:
bool notify_local_transform;
bool notify_transform;
- Ref<CanvasItemMaterial> material;
+ Ref<ShaderMaterial> material;
mutable Transform2D global_transform;
mutable bool global_invalid;
@@ -234,8 +202,8 @@ public:
RID get_canvas() const;
Ref<World2D> get_world_2d() const;
- void set_material(const Ref<CanvasItemMaterial> &p_material);
- Ref<CanvasItemMaterial> get_material() const;
+ void set_material(const Ref<ShaderMaterial> &p_material);
+ Ref<ShaderMaterial> get_material() const;
void set_use_parent_material(bool p_use_parent_material);
bool get_use_parent_material() const;
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 02b41fbd0c..8e57517175 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -304,7 +304,7 @@ void TileMap::_update_dirty_quadrants() {
VS::get_singleton()->free(E->get().id);
}
q.occluder_instances.clear();
- Ref<CanvasItemMaterial> prev_material;
+ Ref<ShaderMaterial> prev_material;
RID prev_canvas_item;
RID prev_debug_canvas_item;
@@ -324,7 +324,7 @@ void TileMap::_update_dirty_quadrants() {
if (!tex.is_valid())
continue;
- Ref<CanvasItemMaterial> mat = tile_set->tile_get_material(c.id);
+ Ref<ShaderMaterial> mat = tile_set->tile_get_material(c.id);
RID canvas_item;
RID debug_canvas_item;