From 40f65c843fb3a75cd236cbd298caec2495af1405 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 23 Feb 2022 09:38:07 +0100 Subject: [PATCH] Added pixels_per_nit property to the prop mesher. Uses the value set in the Prop2DCache singleton by default. Made the light calculation scale with it, so now light are defined in pixels aswell. --- prop_2d_mesher.cpp | 15 ++++++++++++++- prop_2d_mesher.h | 5 +++++ tiled_wall/tiled_wall_2d.cpp | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/prop_2d_mesher.cpp b/prop_2d_mesher.cpp index aac4dd5..50bae00 100644 --- a/prop_2d_mesher.cpp +++ b/prop_2d_mesher.cpp @@ -27,6 +27,7 @@ SOFTWARE. #include "material_cache/prop_2d_material_cache.h" #include "tiled_wall/tiled_wall_2d_data.h" +#include "./singleton/prop_2d_cache.h" const String Prop2DMesher::BINDING_STRING_BUILD_FLAGS = "Use Lighting,Use AO,Use RAO,Bake Lights"; @@ -86,6 +87,13 @@ void Prop2DMesher::set_material(const Ref &material) { _material = material; } +float Prop2DMesher::get_pixels_per_unit() const { + return _pixels_per_unit; +} +void Prop2DMesher::set_pixels_per_unit(const float value) { + _pixels_per_unit = value; +} + float Prop2DMesher::get_ao_strength() const { return _ao_strength; } @@ -709,7 +717,7 @@ Color Prop2DMesher::get_light_color_at(const Vector2 &position) { Color cc = light->get_color(); Vector3 cv(cc.r, cc.g, cc.b); - Vector3 value = cv * (1.0 / (1.0 + dist2)); + Vector3 value = cv * (_pixels_per_unit / (_pixels_per_unit + dist2)); value *= light->get_size(); v_lightDiffuse += value; @@ -1097,6 +1105,7 @@ Prop2DMesher::Prop2DMesher() { _uv_margin = Rect2(0, 0, 1, 1); _format = 0; _texture_scale = 1; + _pixels_per_unit = Prop2DCache::get_singleton()->get_default_pixels_per_unit(); _build_flags = 0; @@ -1128,6 +1137,10 @@ void Prop2DMesher::_bind_methods() { ClassDB::bind_method(D_METHOD("set_material", "value"), &Prop2DMesher::set_material); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material"); + ClassDB::bind_method(D_METHOD("get_pixels_per_unit"), &Prop2DMesher::get_pixels_per_unit); + ClassDB::bind_method(D_METHOD("set_pixels_per_unit", "value"), &Prop2DMesher::set_pixels_per_unit); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "pixels_per_unit"), "set_pixels_per_unit", "get_pixels_per_unit"); + ClassDB::bind_method(D_METHOD("get_voxel_scale"), &Prop2DMesher::get_voxel_scale); ClassDB::bind_method(D_METHOD("set_voxel_scale", "value"), &Prop2DMesher::set_voxel_scale); ADD_PROPERTY(PropertyInfo(Variant::REAL, "voxel_scale"), "set_voxel_scale", "get_voxel_scale"); diff --git a/prop_2d_mesher.h b/prop_2d_mesher.h index 1753177..751b6ec 100644 --- a/prop_2d_mesher.h +++ b/prop_2d_mesher.h @@ -115,6 +115,9 @@ public: Ref get_material(); void set_material(const Ref &material); + float get_pixels_per_unit() const; + void set_pixels_per_unit(const float value); + float get_ao_strength() const; void set_ao_strength(const float value); @@ -227,6 +230,8 @@ protected: Ref _noise; float _rao_scale_factor; int _rao_seed; + + float _pixels_per_unit; }; VARIANT_ENUM_CAST(Prop2DMesher::BuildFlags); diff --git a/tiled_wall/tiled_wall_2d.cpp b/tiled_wall/tiled_wall_2d.cpp index 056dc53..94b7152 100644 --- a/tiled_wall/tiled_wall_2d.cpp +++ b/tiled_wall/tiled_wall_2d.cpp @@ -168,9 +168,9 @@ void TiledWall2D::generate_mesh() { Ref l; l.instance(); - l->set_position(Vector2(10, 10)); + l->set_position(Vector2(600, 600)); l->set_color(Color(1, 0, 0, 1)); - l->set_size(3); + l->set_size(100); _mesher->add_light(l); _mesher->add_tiled_wall_simple(_width, _height, Transform2D(), _data, _cache);