summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-06-26 22:47:11 +0200
committerGitHub <noreply@github.com>2017-06-26 22:47:11 +0200
commitf7b77e5b76639dbc2e7a770cc57b64fc02a1e075 (patch)
tree697fa698482091279b49847a98b0ba1048e6d995 /scene
parent8ca690bbd707dfe56f0c8bc63bba57837664193e (diff)
parent2edb082c7eb85fa1175771ad298f8a8169bc267a (diff)
Merge pull request #9318 from bojidar-bg/readd-normal-tilemap
Add normal map to tilemaps and tilesets
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/tile_map.cpp5
-rw-r--r--scene/resources/tile_set.cpp20
-rw-r--r--scene/resources/tile_set.h4
3 files changed, 27 insertions, 2 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 7ffe029231..098bdf93de 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -441,14 +441,15 @@ void TileMap::_update_dirty_quadrants() {
rect.position.y -= center.y;
}
+ Ref<Texture> normal_map = tile_set->tile_get_normal_map(c.id);
Color modulate = tile_set->tile_get_modulate(c.id);
Color self_modulate = get_self_modulate();
modulate = Color(modulate.r * self_modulate.r, modulate.g * self_modulate.g,
modulate.b * self_modulate.b, modulate.a * self_modulate.a);
if (r == Rect2()) {
- tex->draw_rect(canvas_item, rect, false, modulate, c.transpose);
+ tex->draw_rect(canvas_item, rect, false, modulate, c.transpose, normal_map);
} else {
- tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose);
+ tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map);
}
Vector<Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 76bb1daf94..489c99e15a 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -45,6 +45,8 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
tile_set_name(id, p_value);
else if (what == "texture")
tile_set_texture(id, p_value);
+ else if (what == "normal_map")
+ tile_set_normal_map(id, p_value);
else if (what == "tex_offset")
tile_set_texture_offset(id, p_value);
else if (what == "material")
@@ -89,6 +91,8 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = tile_get_name(id);
else if (what == "texture")
r_ret = tile_get_texture(id);
+ else if (what == "normal_map")
+ r_ret = tile_get_normal_map(id);
else if (what == "tex_offset")
r_ret = tile_get_texture_offset(id);
else if (what == "material")
@@ -125,6 +129,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
String pre = itos(id) + "/";
p_list->push_back(PropertyInfo(Variant::STRING, pre + "name"));
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "tex_offset"));
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial"));
p_list->push_back(PropertyInfo(Variant::COLOR, pre + "modulate"));
@@ -160,6 +165,19 @@ Ref<Texture> TileSet::tile_get_texture(int p_id) const {
return tile_map[p_id].texture;
}
+void TileSet::tile_set_normal_map(int p_id, const Ref<Texture> &p_normal_map) {
+
+ ERR_FAIL_COND(!tile_map.has(p_id));
+ tile_map[p_id].normal_map = p_normal_map;
+ emit_changed();
+}
+
+Ref<Texture> TileSet::tile_get_normal_map(int p_id) const {
+
+ ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture>());
+ return tile_map[p_id].normal_map;
+}
+
void TileSet::tile_set_material(int p_id, const Ref<ShaderMaterial> &p_material) {
ERR_FAIL_COND(!tile_map.has(p_id));
@@ -404,6 +422,8 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("tile_get_name", "id"), &TileSet::tile_get_name);
ClassDB::bind_method(D_METHOD("tile_set_texture", "id", "texture:Texture"), &TileSet::tile_set_texture);
ClassDB::bind_method(D_METHOD("tile_get_texture:Texture", "id"), &TileSet::tile_get_texture);
+ ClassDB::bind_method(D_METHOD("tile_set_normal_map", "id", "normal_map:Texture"), &TileSet::tile_set_normal_map);
+ ClassDB::bind_method(D_METHOD("tile_get_normal_map:Texture", "id"), &TileSet::tile_get_normal_map);
ClassDB::bind_method(D_METHOD("tile_set_material", "id", "material:ShaderMaterial"), &TileSet::tile_set_material);
ClassDB::bind_method(D_METHOD("tile_get_material:ShaderMaterial", "id"), &TileSet::tile_get_material);
ClassDB::bind_method(D_METHOD("tile_set_texture_offset", "id", "texture_offset"), &TileSet::tile_set_texture_offset);
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index 448444d34a..3c4584161c 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -44,6 +44,7 @@ class TileSet : public Resource {
String name;
Ref<Texture> texture;
+ Ref<Texture> normal_map;
Vector2 offset;
Vector2 shape_offset;
Rect2i region;
@@ -81,6 +82,9 @@ public:
void tile_set_texture(int p_id, const Ref<Texture> &p_texture);
Ref<Texture> tile_get_texture(int p_id) const;
+ void tile_set_normal_map(int p_id, const Ref<Texture> &p_normal_map);
+ Ref<Texture> tile_get_normal_map(int p_id) const;
+
void tile_set_texture_offset(int p_id, const Vector2 &p_offset);
Vector2 tile_get_texture_offset(int p_id) const;