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.

This commit is contained in:
Relintai 2022-02-23 09:38:07 +01:00
parent 37b2ab5b5e
commit 40f65c843f
3 changed files with 21 additions and 3 deletions

View File

@ -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 = 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");

View File

@ -115,6 +115,9 @@ public:
Ref<Material> get_material();
void set_material(const Ref<Material> &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<OpenSimplexNoise> _noise;
float _rao_scale_factor;
int _rao_seed;
float _pixels_per_unit;
};
VARIANT_ENUM_CAST(Prop2DMesher::BuildFlags);

View File

@ -168,9 +168,9 @@ void TiledWall2D::generate_mesh() {
Ref<Prop2DLight> 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);