diff --git a/meshers/cubic_mesher/voxel_mesher_cubic.cpp b/meshers/cubic_mesher/voxel_mesher_cubic.cpp index 6db8c4c..c256469 100644 --- a/meshers/cubic_mesher/voxel_mesher_cubic.cpp +++ b/meshers/cubic_mesher/voxel_mesher_cubic.cpp @@ -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 buffer) { buffer->generate_ao(); @@ -23,7 +31,7 @@ void VoxelMesherCubic::_add_buffer(Ref 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 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"); } diff --git a/meshers/cubic_mesher/voxel_mesher_cubic.h b/meshers/cubic_mesher/voxel_mesher_cubic.h index 3983f4c..a1b9101 100644 --- a/meshers/cubic_mesher/voxel_mesher_cubic.h +++ b/meshers/cubic_mesher/voxel_mesher_cubic.h @@ -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 buffer); VoxelMesherCubic(); @@ -26,6 +29,7 @@ protected: private: float _ao_strength; + float _base_light_value; }; #endif diff --git a/world/voxel_chunk.cpp b/world/voxel_chunk.cpp index 9a05a8f..6f5ffef 100644 --- a/world/voxel_chunk.cpp +++ b/world/voxel_chunk.cpp @@ -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(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); } diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index 1ecbc29..47aa664 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -75,6 +75,7 @@ public: Ref get_buffer() const; + void create_mesher(); void _create_mesher(); void finalize_mesh();