Now the base light value is settable in the Cubic Voxel Mesher.

This commit is contained in:
Relintai 2019-07-17 19:51:09 +02:00
parent 469773a9fd
commit 7db42b88a1
4 changed files with 31 additions and 7 deletions

View File

@ -7,6 +7,14 @@ void VoxelMesherCubic::set_ao_strength(float value) {
_ao_strength = value;
}
float VoxelMesherCubic::get_base_light_value() const {
return _base_light_value;
}
void VoxelMesherCubic::set_base_light_value(float value) {
_base_light_value = value;
}
void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
buffer->generate_ao();
@ -23,7 +31,7 @@ void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
cube_points.instance();
float tile_uv_size = 1 / 4.0;
Color base_light(0.4, 0.4, 0.4);
Color base_light(_base_light_value, _base_light_value, _base_light_value);
for (int y = lod_size; y < y_size - lod_size; y += lod_size) {
for (int z = lod_size; z < z_size - lod_size; z += lod_size) {
@ -88,6 +96,7 @@ void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
VoxelMesherCubic::VoxelMesherCubic() {
_ao_strength = 0.25;
_base_light_value = 0.5;
}
VoxelMesherCubic::~VoxelMesherCubic() {
@ -99,4 +108,8 @@ void VoxelMesherCubic::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ao_strength"), &VoxelMesherCubic::get_ao_strength);
ClassDB::bind_method(D_METHOD("set_ao_strength", "value"), &VoxelMesherCubic::set_ao_strength);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ao_strength"), "set_ao_strength", "get_ao_strength");
ClassDB::bind_method(D_METHOD("get_base_light_value"), &VoxelMesherCubic::get_base_light_value);
ClassDB::bind_method(D_METHOD("set_base_light_value", "value"), &VoxelMesherCubic::set_base_light_value);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base_light_value"), "set_base_light_value", "get_base_light_value");
}

View File

@ -16,6 +16,9 @@ public:
float get_ao_strength() const;
void set_ao_strength(float value);
float get_base_light_value() const;
void set_base_light_value(float value);
void _add_buffer(Ref<VoxelBuffer> buffer);
VoxelMesherCubic();
@ -26,6 +29,7 @@ protected:
private:
float _ao_strength;
float _base_light_value;
};
#endif

View File

@ -143,12 +143,7 @@ void VoxelChunk::build() {
ERR_FAIL_COND(!_library.is_valid());
if (!_mesher.is_valid()) {
call("_create_mesher");
ERR_FAIL_COND(!_mesher.is_valid());
_mesher->set_lod_size(get_lod_size());
_mesher->set_voxel_scale(get_voxel_scale());
create_mesher();
}
_mesher->set_library(_library);
@ -176,6 +171,15 @@ void VoxelChunk::build() {
}
}
void VoxelChunk::create_mesher() {
call("_create_mesher");
ERR_FAIL_COND(!_mesher.is_valid());
_mesher->set_lod_size(get_lod_size());
_mesher->set_voxel_scale(get_voxel_scale());
}
void VoxelChunk::_create_mesher() {
_mesher = Ref<VoxelMesher>(memnew(VoxelMesherCubic()));
}
@ -487,6 +491,8 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &VoxelChunk::clear);
ClassDB::bind_method(D_METHOD("create_mesher"), &VoxelChunk::create_mesher);
ClassDB::bind_method(D_METHOD("draw_debug_voxels", "max"), &VoxelChunk::draw_debug_voxels, DEFVAL(Color(1, 1, 1)));
ClassDB::bind_method(D_METHOD("draw_debug_voxel_lights"), &VoxelChunk::draw_debug_voxel_lights);
}

View File

@ -75,6 +75,7 @@ public:
Ref<VoxelBuffer> get_buffer() const;
void create_mesher();
void _create_mesher();
void finalize_mesh();