Added more properties to PropDataLight and other light helper classes.

This commit is contained in:
Relintai 2024-03-18 08:38:27 +01:00
parent e63a88836c
commit a52a68afb7
22 changed files with 541 additions and 88 deletions

View File

@ -9,9 +9,19 @@
<methods>
</methods>
<members>
<member name="light_attenuation" type="float" setter="set_light_attenuation" getter="get_light_attenuation" default="0.0">
</member>
<member name="light_color" type="Color" setter="set_light_color" getter="get_light_color" default="Color( 0, 0, 0, 1 )">
</member>
<member name="light_size" type="int" setter="set_light_size" getter="get_light_size" default="0">
<member name="light_energy" type="float" setter="set_light_energy" getter="get_light_energy" default="0.0">
</member>
<member name="light_indirect_energy" type="float" setter="set_light_indirect_energy" getter="get_light_indirect_energy" default="0.0">
</member>
<member name="light_negative" type="bool" setter="set_light_negative" getter="get_light_negative" default="false">
</member>
<member name="light_range" type="float" setter="set_light_range" getter="get_light_range" default="0.0">
</member>
<member name="light_specular" type="float" setter="set_light_specular" getter="get_light_specular" default="0.0">
</member>
</members>
<constants>

View File

@ -9,9 +9,19 @@
<methods>
</methods>
<members>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
<member name="light_attenuation" type="float" setter="set_attenuation" getter="get_attenuation" default="0.0">
</member>
<member name="size" type="float" setter="set_size" getter="get_size" default="0.0">
<member name="light_color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
</member>
<member name="light_energy" type="float" setter="set_energy" getter="get_energy" default="0.0">
</member>
<member name="light_indirect_energy" type="float" setter="set_indirect_energy" getter="get_indirect_energy" default="0.0">
</member>
<member name="light_negative" type="bool" setter="set_negative" getter="get_negative" default="false">
</member>
<member name="light_range" type="float" setter="set_range" getter="get_range" default="0.0">
</member>
<member name="light_specular" type="float" setter="set_specular" getter="get_specular" default="0.0">
</member>
<member name="world_position" type="Vector3" setter="set_position" getter="get_position" default="Vector3( 0, 0, 0 )">
</member>

View File

@ -1,5 +1,5 @@
/*************************************************************************/
/* prop_light.cpp */
/* prop.cpp */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
@ -38,37 +38,108 @@ void PropLight::set_position(const Vector3 &pos) {
_position = pos;
}
real_t PropLight::get_range() const {
return _range;
}
void PropLight::set_range(const real_t value) {
_range = value;
}
real_t PropLight::get_attenuation() const {
return _attenuation;
}
void PropLight::set_attenuation(const real_t value) {
_attenuation = value;
}
Color PropLight::get_color() const {
return _color;
}
void PropLight::set_color(const Color &color) {
_color = color;
void PropLight::set_color(const Color value) {
_color = value;
}
float PropLight::get_size() const {
return _size;
real_t PropLight::get_energy() const {
return _energy;
}
void PropLight::set_size(const float size) {
_size = size;
void PropLight::set_energy(const real_t value) {
_energy = value;
}
real_t PropLight::get_indirect_energy() const {
return _indirect_energy;
}
void PropLight::set_indirect_energy(const real_t value) {
_indirect_energy = value;
}
bool PropLight::get_negative() const {
return _negative;
}
void PropLight::set_negative(const bool value) {
_negative = value;
}
real_t PropLight::get_specular() const {
return _specular;
}
void PropLight::set_specular(const real_t value) {
_specular = value;
}
PropLight::PropLight() {
_size = 0;
_range = 0;
_attenuation = 0;
_energy = 0;
_indirect_energy = 0;
_negative = false;
_specular = 0;
}
PropLight::~PropLight() {
}
#ifndef DISABLE_DEPRECATED
bool PropLight::_set(const StringName &p_name, const Variant &p_value) {
// Convert to range
if (p_name == "light_size") {
set_range(p_value);
}
return false;
}
#endif
void PropLight::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_position"), &PropLight::get_position);
ClassDB::bind_method(D_METHOD("set_position"), &PropLight::set_position);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "world_position"), "set_position", "get_position");
ClassDB::bind_method(D_METHOD("get_color"), &PropLight::get_color);
ClassDB::bind_method(D_METHOD("set_color"), &PropLight::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_range"), &PropLight::get_range);
ClassDB::bind_method(D_METHOD("set_range", "value"), &PropLight::set_range);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_range"), "set_range", "get_range");
ClassDB::bind_method(D_METHOD("get_size"), &PropLight::get_size);
ClassDB::bind_method(D_METHOD("set_size"), &PropLight::set_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
ClassDB::bind_method(D_METHOD("get_attenuation"), &PropLight::get_attenuation);
ClassDB::bind_method(D_METHOD("set_attenuation", "value"), &PropLight::set_attenuation);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_attenuation"), "set_attenuation", "get_attenuation");
ClassDB::bind_method(D_METHOD("get_color"), &PropLight::get_color);
ClassDB::bind_method(D_METHOD("set_color", "value"), &PropLight::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_energy"), &PropLight::get_energy);
ClassDB::bind_method(D_METHOD("set_energy", "value"), &PropLight::set_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_energy"), "set_energy", "get_energy");
ClassDB::bind_method(D_METHOD("get_indirect_energy"), &PropLight::get_indirect_energy);
ClassDB::bind_method(D_METHOD("set_indirect_energy", "value"), &PropLight::set_indirect_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_indirect_energy"), "set_indirect_energy", "get_indirect_energy");
ClassDB::bind_method(D_METHOD("get_negative"), &PropLight::get_negative);
ClassDB::bind_method(D_METHOD("set_negative", "value"), &PropLight::set_negative);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "get_negative");
ClassDB::bind_method(D_METHOD("get_specular"), &PropLight::get_specular);
ClassDB::bind_method(D_METHOD("set_specular", "value"), &PropLight::set_specular);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_specular"), "set_specular", "get_specular");
}

View File

@ -43,23 +43,47 @@ public:
Vector3 get_position();
void set_position(const Vector3 &pos);
Color get_color() const;
void set_color(const Color &color);
real_t get_range() const;
void set_range(const real_t value);
float get_size() const;
void set_size(const float strength);
real_t get_attenuation() const;
void set_attenuation(const real_t value);
Color get_color() const;
void set_color(const Color value);
real_t get_energy() const;
void set_energy(const real_t value);
real_t get_indirect_energy() const;
void set_indirect_energy(const real_t value);
bool get_negative() const;
void set_negative(const bool value);
real_t get_specular() const;
void set_specular(const real_t value);
PropLight();
~PropLight();
private:
#ifndef DISABLE_DEPRECATED
bool _set(const StringName &p_name, const Variant &p_value);
#endif
static void _bind_methods();
private:
Vector3 _position;
real_t _range;
real_t _attenuation;
Color _color;
int _size;
real_t _energy;
real_t _indirect_energy;
bool _negative;
real_t _specular;
};
#endif

View File

@ -231,7 +231,7 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
OmniLight *light = memnew(OmniLight);
add_child(light);
light->set_color(light_data->get_light_color());
light->set_param(Light::PARAM_RANGE, light_data->get_light_size());
light->set_param(Light::PARAM_RANGE, light_data->get_light_range());
light->set_transform(t);
continue;

View File

@ -710,8 +710,13 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Ref<PropDat
Vector3 v = t.xform(Vector3());
light->set_position(v);
light->set_range(light_data->get_light_range());
light->set_attenuation(light_data->get_light_attenuation());
light->set_color(light_data->get_light_color());
light->set_size(light_data->get_light_size());
light->set_energy(light_data->get_light_energy());
light->set_indirect_energy(light_data->get_light_indirect_energy());
light->set_negative(light_data->get_light_negative());
light->set_specular(light_data->get_light_specular());
_job->add_light(light);

View File

@ -1013,7 +1013,7 @@ Color PropMesher::get_light_color_at(const Vector3 &position, const Vector3 &nor
Vector3 value = cv * (NdotL / (1.0 + dist2));
value *= light->get_size();
value *= light->get_range();
v_lightDiffuse += value;
/*
@ -1227,7 +1227,7 @@ void PropMesher::bake_lights(MeshInstance *node, Vector<Ref<TerrainLight>> &ligh
Vector3 value = cv * (NdotL / (1.0 + dist2));
value *= light->get_size();
value *= light->get_range();
v_lightDiffuse += value;
/*

View File

@ -35,6 +35,20 @@
#include "scene/3d/light.h"
real_t PropDataLight::get_light_range() const {
return _light_range;
}
void PropDataLight::set_light_range(const real_t value) {
_light_range = value;
}
real_t PropDataLight::get_light_attenuation() const {
return _light_attenuation;
}
void PropDataLight::set_light_attenuation(const real_t value) {
_light_attenuation = value;
}
Color PropDataLight::get_light_color() const {
return _light_color;
}
@ -42,11 +56,32 @@ void PropDataLight::set_light_color(const Color value) {
_light_color = value;
}
int PropDataLight::get_light_size() const {
return _light_size;
real_t PropDataLight::get_light_energy() const {
return _light_energy;
}
void PropDataLight::set_light_size(const int value) {
_light_size = value;
void PropDataLight::set_light_energy(const real_t value) {
_light_energy = value;
}
real_t PropDataLight::get_light_indirect_energy() const {
return _light_indirect_energy;
}
void PropDataLight::set_light_indirect_energy(const real_t value) {
_light_indirect_energy = value;
}
bool PropDataLight::get_light_negative() const {
return _light_negative;
}
void PropDataLight::set_light_negative(const bool value) {
_light_negative = value;
}
real_t PropDataLight::get_light_specular() const {
return _light_specular;
}
void PropDataLight::set_light_specular(const real_t value) {
_light_specular = value;
}
bool PropDataLight::_processor_handles(Node *node) {
@ -66,34 +101,82 @@ void PropDataLight::_processor_process(Ref<PropData> prop_data, Node *node, cons
Ref<PropDataLight> l;
l.instance();
l->set_light_range(i->get_param(Light::PARAM_RANGE));
l->set_light_attenuation(i->get_param(Light::PARAM_ATTENUATION));
l->set_light_color(i->get_color());
l->set_light_size(i->get_param(Light::PARAM_RANGE));
l->set_light_energy(i->get_param(Light::PARAM_ENERGY));
l->set_light_indirect_energy(i->get_param(Light::PARAM_INDIRECT_ENERGY));
l->set_light_negative(i->is_negative());
l->set_light_specular(i->get_param(Light::PARAM_SPECULAR));
l->set_transform(transform * i->get_transform());
prop_data->add_prop(l);
}
Node *PropDataLight::_processor_get_node_for(const Transform &transform) {
OmniLight *i = memnew(OmniLight);
i->set_param(Light::PARAM_RANGE, get_light_range());
i->set_param(Light::PARAM_ATTENUATION, get_light_attenuation());
i->set_color(get_light_color());
i->set_param(Light::PARAM_RANGE, get_light_size());
i->set_param(Light::PARAM_ENERGY, get_light_energy());
i->set_param(Light::PARAM_INDIRECT_ENERGY, get_light_indirect_energy());
i->set_negative(get_light_negative());
i->set_param(Light::PARAM_SPECULAR, get_light_specular());
i->set_transform(get_transform());
return i;
}
PropDataLight::PropDataLight() {
_light_size = 0;
_light_range = 0;
_light_attenuation = 0;
_light_energy = 0;
_light_indirect_energy = 0;
_light_negative = false;
_light_specular = 0;
}
PropDataLight::~PropDataLight() {
}
#ifndef DISABLE_DEPRECATED
bool PropDataLight::_set(const StringName &p_name, const Variant &p_value) {
// Convert to range
if (p_name == "light_size") {
set_light_range(p_value);
}
return false;
}
#endif
void PropDataLight::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_light_range"), &PropDataLight::get_light_range);
ClassDB::bind_method(D_METHOD("set_light_range", "value"), &PropDataLight::set_light_range);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_range"), "set_light_range", "get_light_range");
ClassDB::bind_method(D_METHOD("get_light_attenuation"), &PropDataLight::get_light_attenuation);
ClassDB::bind_method(D_METHOD("set_light_attenuation", "value"), &PropDataLight::set_light_attenuation);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_attenuation"), "set_light_attenuation", "get_light_attenuation");
ClassDB::bind_method(D_METHOD("get_light_color"), &PropDataLight::get_light_color);
ClassDB::bind_method(D_METHOD("set_light_color", "value"), &PropDataLight::set_light_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_light_color", "get_light_color");
ClassDB::bind_method(D_METHOD("get_light_size"), &PropDataLight::get_light_size);
ClassDB::bind_method(D_METHOD("set_light_size", "value"), &PropDataLight::set_light_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size"), "set_light_size", "get_light_size");
ClassDB::bind_method(D_METHOD("get_light_energy"), &PropDataLight::get_light_energy);
ClassDB::bind_method(D_METHOD("set_light_energy", "value"), &PropDataLight::set_light_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_energy"), "set_light_energy", "get_light_energy");
ClassDB::bind_method(D_METHOD("get_light_indirect_energy"), &PropDataLight::get_light_indirect_energy);
ClassDB::bind_method(D_METHOD("set_light_indirect_energy", "value"), &PropDataLight::set_light_indirect_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_indirect_energy"), "set_light_indirect_energy", "get_light_indirect_energy");
ClassDB::bind_method(D_METHOD("get_light_negative"), &PropDataLight::get_light_negative);
ClassDB::bind_method(D_METHOD("set_light_negative", "value"), &PropDataLight::set_light_negative);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_light_negative", "get_light_negative");
ClassDB::bind_method(D_METHOD("get_light_specular"), &PropDataLight::get_light_specular);
ClassDB::bind_method(D_METHOD("set_light_specular", "value"), &PropDataLight::set_light_specular);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_specular"), "set_light_specular", "get_light_specular");
}

View File

@ -40,11 +40,26 @@ class PropDataLight : public PropDataEntry {
GDCLASS(PropDataLight, PropDataEntry);
public:
real_t get_light_range() const;
void set_light_range(const real_t value);
real_t get_light_attenuation() const;
void set_light_attenuation(const real_t value);
Color get_light_color() const;
void set_light_color(const Color value);
int get_light_size() const;
void set_light_size(const int value);
real_t get_light_energy() const;
void set_light_energy(const real_t value);
real_t get_light_indirect_energy() const;
void set_light_indirect_energy(const real_t value);
bool get_light_negative() const;
void set_light_negative(const bool value);
real_t get_light_specular() const;
void set_light_specular(const real_t value);
bool _processor_handles(Node *node);
void _processor_process(Ref<PropData> prop_data, Node *node, const Transform &transform);
@ -54,11 +69,20 @@ public:
~PropDataLight();
protected:
#ifndef DISABLE_DEPRECATED
bool _set(const StringName &p_name, const Variant &p_value);
#endif
static void _bind_methods();
private:
real_t _light_range;
real_t _light_attenuation;
Color _light_color;
int _light_size;
real_t _light_energy;
real_t _light_indirect_energy;
bool _light_negative;
real_t _light_specular;
};
#endif

View File

@ -49,22 +49,73 @@ void TerrainLight::set_world_position(const int x, const int y, const int z) {
_world_position_z = z;
}
_FORCE_INLINE_ Color TerrainLight::get_color() const {
real_t TerrainLight::get_range() const {
return _range;
}
void TerrainLight::set_range(const real_t value) {
_range = value;
}
real_t TerrainLight::get_attenuation() const {
return _attenuation;
}
void TerrainLight::set_attenuation(const real_t value) {
_attenuation = value;
}
Color TerrainLight::get_color() const {
return _color;
}
void TerrainLight::set_color(const Color &color) {
_color = color;
void TerrainLight::set_color(const Color value) {
_color = value;
}
_FORCE_INLINE_ float TerrainLight::get_size() const {
return _size;
real_t TerrainLight::get_energy() const {
return _energy;
}
void TerrainLight::set_size(const float size) {
_size = size;
void TerrainLight::set_energy(const real_t value) {
_energy = value;
}
real_t TerrainLight::get_indirect_energy() const {
return _indirect_energy;
}
void TerrainLight::set_indirect_energy(const real_t value) {
_indirect_energy = value;
}
bool TerrainLight::get_negative() const {
return _negative;
}
void TerrainLight::set_negative(const bool value) {
_negative = value;
}
real_t TerrainLight::get_specular() const {
return _specular;
}
void TerrainLight::set_specular(const real_t value) {
_specular = value;
}
#ifndef DISABLE_DEPRECATED
bool TerrainLight::_set(const StringName &p_name, const Variant &p_value) {
// Convert to range
if (p_name == "light_size") {
set_range(p_value);
}
return false;
}
#endif
TerrainLight::TerrainLight() {
_size = 0;
_range = 0;
_attenuation = 0;
_energy = 0;
_indirect_energy = 0;
_negative = false;
_specular = 0;
}
TerrainLight::~TerrainLight() {
@ -76,11 +127,31 @@ void TerrainLight::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_world_position_z"), &TerrainLight::get_world_position_z);
ClassDB::bind_method(D_METHOD("set_world_position", "x", "y", "z"), &TerrainLight::set_world_position);
ClassDB::bind_method(D_METHOD("get_color"), &TerrainLight::get_color);
ClassDB::bind_method(D_METHOD("set_color"), &TerrainLight::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_range"), &TerrainLight::get_range);
ClassDB::bind_method(D_METHOD("set_range", "value"), &TerrainLight::set_range);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_range"), "set_range", "get_range");
ClassDB::bind_method(D_METHOD("get_size"), &TerrainLight::get_size);
ClassDB::bind_method(D_METHOD("set_size"), &TerrainLight::set_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
ClassDB::bind_method(D_METHOD("get_attenuation"), &TerrainLight::get_attenuation);
ClassDB::bind_method(D_METHOD("set_attenuation", "value"), &TerrainLight::set_attenuation);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_attenuation"), "set_attenuation", "get_attenuation");
ClassDB::bind_method(D_METHOD("get_color"), &TerrainLight::get_color);
ClassDB::bind_method(D_METHOD("set_color", "value"), &TerrainLight::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_energy"), &TerrainLight::get_energy);
ClassDB::bind_method(D_METHOD("set_energy", "value"), &TerrainLight::set_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_energy"), "set_energy", "get_energy");
ClassDB::bind_method(D_METHOD("get_indirect_energy"), &TerrainLight::get_indirect_energy);
ClassDB::bind_method(D_METHOD("set_indirect_energy", "value"), &TerrainLight::set_indirect_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_indirect_energy"), "set_indirect_energy", "get_indirect_energy");
ClassDB::bind_method(D_METHOD("get_negative"), &TerrainLight::get_negative);
ClassDB::bind_method(D_METHOD("set_negative", "value"), &TerrainLight::set_negative);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "get_negative");
ClassDB::bind_method(D_METHOD("get_specular"), &TerrainLight::get_specular);
ClassDB::bind_method(D_METHOD("set_specular", "value"), &TerrainLight::set_specular);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_specular"), "set_specular", "get_specular");
}

View File

@ -46,16 +46,38 @@ public:
Vector3 get_world_position();
void set_world_position(const int x, const int y, const int z);
Color get_color() const;
void set_color(const Color &color);
Vector3 get_position();
void set_position(const Vector3 &pos);
float get_size() const;
void set_size(const float strength);
real_t get_range() const;
void set_range(const real_t value);
real_t get_attenuation() const;
void set_attenuation(const real_t value);
Color get_color() const;
void set_color(const Color value);
real_t get_energy() const;
void set_energy(const real_t value);
real_t get_indirect_energy() const;
void set_indirect_energy(const real_t value);
bool get_negative() const;
void set_negative(const bool value);
real_t get_specular() const;
void set_specular(const real_t value);
TerrainLight();
~TerrainLight();
private:
#ifndef DISABLE_DEPRECATED
bool _set(const StringName &p_name, const Variant &p_value);
#endif
static void _bind_methods();
private:
@ -67,8 +89,13 @@ private:
int _world_position_y;
int _world_position_z;
real_t _range;
real_t _attenuation;
Color _color;
int _size;
real_t _energy;
real_t _indirect_energy;
bool _negative;
real_t _specular;
};
#endif

View File

@ -32,9 +32,19 @@
</method>
</methods>
<members>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
<member name="light_attenuation" type="float" setter="set_attenuation" getter="get_attenuation" default="0.0">
</member>
<member name="size" type="float" setter="set_size" getter="get_size" default="0.0">
<member name="light_color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
</member>
<member name="light_energy" type="float" setter="set_energy" getter="get_energy" default="0.0">
</member>
<member name="light_indirect_energy" type="float" setter="set_indirect_energy" getter="get_indirect_energy" default="0.0">
</member>
<member name="light_negative" type="bool" setter="set_negative" getter="get_negative" default="false">
</member>
<member name="light_range" type="float" setter="set_range" getter="get_range" default="0.0">
</member>
<member name="light_specular" type="float" setter="set_specular" getter="get_specular" default="0.0">
</member>
</members>
<constants>

View File

@ -644,7 +644,7 @@ void TerrainMesher::bake_lights(MeshInstance *node, Vector<Ref<TerrainLight>> &l
Vector3 value = cv * (NdotL / (1.0 + dist2));
value *= light->get_size();
value *= light->get_range();
v_lightDiffuse += value;
/*

View File

@ -758,7 +758,7 @@ void TerrainChunkDefault::_bake_light(Ref<TerrainLight> light) {
ERR_FAIL_COND(!light.is_valid());
Color color = light->get_color();
int size = light->get_size();
int size = light->get_range();
int local_x = light->get_world_position_x() - (_position_x * _size_x);
int local_y = light->get_world_position_y();

View File

@ -671,8 +671,13 @@ void TerrainWorld::prop_add(Transform transform, const Ref<PropData> &prop, cons
light.instance();
light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale(), wp.z / get_voxel_scale());
light->set_range(light_data->get_light_range());
light->set_attenuation(light_data->get_light_attenuation());
light->set_color(light_data->get_light_color());
light->set_size(light_data->get_light_size());
light->set_energy(light_data->get_light_energy());
light->set_indirect_energy(light_data->get_light_indirect_energy());
light->set_negative(light_data->get_light_negative());
light->set_specular(light_data->get_light_specular());
light_add(light);

View File

@ -713,7 +713,7 @@ void Terrain2DWorld::prop_add(Transform transform, const Ref<Prop2DData> &prop,
light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale());
light->set_color(light_data->get_light_color());
light->set_size(light_data->get_light_size());
light->set_size(light_data->get_light_range());
light_add(light);

View File

@ -49,22 +49,73 @@ void VoxelLight::set_world_position(const int x, const int y, const int z) {
_world_position_z = z;
}
_FORCE_INLINE_ Color VoxelLight::get_color() const {
real_t VoxelLight::get_range() const {
return _range;
}
void VoxelLight::set_range(const real_t value) {
_range = value;
}
real_t VoxelLight::get_attenuation() const {
return _attenuation;
}
void VoxelLight::set_attenuation(const real_t value) {
_attenuation = value;
}
Color VoxelLight::get_color() const {
return _color;
}
void VoxelLight::set_color(const Color &color) {
_color = color;
void VoxelLight::set_color(const Color value) {
_color = value;
}
_FORCE_INLINE_ float VoxelLight::get_size() const {
return _size;
real_t VoxelLight::get_energy() const {
return _energy;
}
void VoxelLight::set_size(const float size) {
_size = size;
void VoxelLight::set_energy(const real_t value) {
_energy = value;
}
real_t VoxelLight::get_indirect_energy() const {
return _indirect_energy;
}
void VoxelLight::set_indirect_energy(const real_t value) {
_indirect_energy = value;
}
bool VoxelLight::get_negative() const {
return _negative;
}
void VoxelLight::set_negative(const bool value) {
_negative = value;
}
real_t VoxelLight::get_specular() const {
return _specular;
}
void VoxelLight::set_specular(const real_t value) {
_specular = value;
}
#ifndef DISABLE_DEPRECATED
bool VoxelLight::_set(const StringName &p_name, const Variant &p_value) {
// Convert to range
if (p_name == "light_size") {
set_range(p_value);
}
return false;
}
#endif
VoxelLight::VoxelLight() {
_size = 0;
_range = 0;
_attenuation = 0;
_energy = 0;
_indirect_energy = 0;
_negative = false;
_specular = 0;
}
VoxelLight::~VoxelLight() {
@ -76,11 +127,31 @@ void VoxelLight::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_world_position_z"), &VoxelLight::get_world_position_z);
ClassDB::bind_method(D_METHOD("set_world_position", "x", "y", "z"), &VoxelLight::set_world_position);
ClassDB::bind_method(D_METHOD("get_color"), &VoxelLight::get_color);
ClassDB::bind_method(D_METHOD("set_color"), &VoxelLight::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_range"), &VoxelLight::get_range);
ClassDB::bind_method(D_METHOD("set_range", "value"), &VoxelLight::set_range);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_range"), "set_range", "get_range");
ClassDB::bind_method(D_METHOD("get_size"), &VoxelLight::get_size);
ClassDB::bind_method(D_METHOD("set_size"), &VoxelLight::set_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
ClassDB::bind_method(D_METHOD("get_attenuation"), &VoxelLight::get_attenuation);
ClassDB::bind_method(D_METHOD("set_attenuation", "value"), &VoxelLight::set_attenuation);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_attenuation"), "set_attenuation", "get_attenuation");
ClassDB::bind_method(D_METHOD("get_color"), &VoxelLight::get_color);
ClassDB::bind_method(D_METHOD("set_color", "value"), &VoxelLight::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_energy"), &VoxelLight::get_energy);
ClassDB::bind_method(D_METHOD("set_energy", "value"), &VoxelLight::set_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_energy"), "set_energy", "get_energy");
ClassDB::bind_method(D_METHOD("get_indirect_energy"), &VoxelLight::get_indirect_energy);
ClassDB::bind_method(D_METHOD("set_indirect_energy", "value"), &VoxelLight::set_indirect_energy);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_indirect_energy"), "set_indirect_energy", "get_indirect_energy");
ClassDB::bind_method(D_METHOD("get_negative"), &VoxelLight::get_negative);
ClassDB::bind_method(D_METHOD("set_negative", "value"), &VoxelLight::set_negative);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "get_negative");
ClassDB::bind_method(D_METHOD("get_specular"), &VoxelLight::get_specular);
ClassDB::bind_method(D_METHOD("set_specular", "value"), &VoxelLight::set_specular);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_specular"), "set_specular", "get_specular");
}

View File

@ -46,16 +46,38 @@ public:
Vector3 get_world_position();
void set_world_position(const int x, const int y, const int z);
Color get_color() const;
void set_color(const Color &color);
Vector3 get_position();
void set_position(const Vector3 &pos);
float get_size() const;
void set_size(const float strength);
real_t get_range() const;
void set_range(const real_t value);
real_t get_attenuation() const;
void set_attenuation(const real_t value);
Color get_color() const;
void set_color(const Color value);
real_t get_energy() const;
void set_energy(const real_t value);
real_t get_indirect_energy() const;
void set_indirect_energy(const real_t value);
bool get_negative() const;
void set_negative(const bool value);
real_t get_specular() const;
void set_specular(const real_t value);
VoxelLight();
~VoxelLight();
private:
#ifndef DISABLE_DEPRECATED
bool _set(const StringName &p_name, const Variant &p_value);
#endif
static void _bind_methods();
private:
@ -67,8 +89,13 @@ private:
int _world_position_y;
int _world_position_z;
real_t _range;
real_t _attenuation;
Color _color;
int _size;
real_t _energy;
real_t _indirect_energy;
bool _negative;
real_t _specular;
};
#endif

View File

@ -32,9 +32,19 @@
</method>
</methods>
<members>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
<member name="light_attenuation" type="float" setter="set_attenuation" getter="get_attenuation" default="0.0">
</member>
<member name="size" type="float" setter="set_size" getter="get_size" default="0.0">
<member name="light_color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
</member>
<member name="light_energy" type="float" setter="set_energy" getter="get_energy" default="0.0">
</member>
<member name="light_indirect_energy" type="float" setter="set_indirect_energy" getter="get_indirect_energy" default="0.0">
</member>
<member name="light_negative" type="bool" setter="set_negative" getter="get_negative" default="false">
</member>
<member name="light_range" type="float" setter="set_range" getter="get_range" default="0.0">
</member>
<member name="light_specular" type="float" setter="set_specular" getter="get_specular" default="0.0">
</member>
</members>
<constants>

View File

@ -638,7 +638,7 @@ void VoxelMesher::bake_lights(MeshInstance *node, Vector<Ref<VoxelLight>> &light
Vector3 value = cv * (NdotL / (1.0 + dist2));
value *= light->get_size();
value *= light->get_range();
v_lightDiffuse += value;
/*

View File

@ -755,7 +755,7 @@ void VoxelChunkDefault::_bake_light(Ref<VoxelLight> light) {
ERR_FAIL_COND(!light.is_valid());
Color color = light->get_color();
int size = light->get_size();
int size = light->get_range();
int local_x = light->get_world_position_x() - (_position_x * _size_x);
int local_y = light->get_world_position_y() - (_position_y * _size_y);

View File

@ -637,8 +637,13 @@ void VoxelWorld::prop_add(Transform tarnsform, const Ref<PropData> &prop, const
light.instance();
light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale(), wp.z / get_voxel_scale());
light->set_range(light_data->get_light_range());
light->set_attenuation(light_data->get_light_attenuation());
light->set_color(light_data->get_light_color());
light->set_size(light_data->get_light_size());
light->set_energy(light_data->get_light_energy());
light->set_indirect_energy(light_data->get_light_indirect_energy());
light->set_negative(light_data->get_light_negative());
light->set_specular(light_data->get_light_specular());
light_add(light);