Skip to content

Commit

Permalink
Fix dithered brushing with scale < 1
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Feb 16, 2024
1 parent 6c31a76 commit 80cf786
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/terrain_3d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,17 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
}
Object::cast_to<Node>(_terrain->get_plugin()->get("ui"))->call("set_decal_rotation", rot);

Vector3 descaled_position = p_global_position / _terrain->get_mesh_vertex_spacing();

AABB edited_area;
edited_area.position = p_global_position - Vector3(brush_size, 0.0f, brush_size) / 2.0f;
edited_area.size = Vector3(brush_size, 0.0f, brush_size);

for (int x = 0; x < brush_size; x++) {
for (int y = 0; y < brush_size; y++) {
Vector2i brush_offset = Vector2i(x, y) - (Vector2i(brush_size, brush_size) / 2);
Vector3 brush_global_position = Vector3(0.5f, 0.f, 0.5f) +
Vector3(p_global_position.x + real_t(brush_offset.x), p_global_position.y,
p_global_position.z + real_t(brush_offset.y));
real_t vertex_spacing = _terrain->get_mesh_vertex_spacing();
for (real_t x = 0.f; x < brush_size; x += vertex_spacing) {
for (real_t y = 0.f; y < brush_size; y += vertex_spacing) {
Vector2 brush_offset = Vector2(x, y) - (Vector2(brush_size, brush_size) / 2.f);
Vector3 brush_global_position =
Vector3(p_global_position.x + brush_offset.x + .5f, p_global_position.y,
p_global_position.z + brush_offset.y + .5f);

// If we're brushing across a region boundary, possibly add a region, and get the other map
int new_region_index = storage->get_region_index(brush_global_position);
Expand Down Expand Up @@ -223,11 +222,10 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
destf = Math::lerp(srcf, height, brush_alpha * opacity);
break;
case AVERAGE: {
real_t step = _terrain->get_mesh_vertex_spacing();
Vector3 left_position = brush_global_position - Vector3(step, 0, 0);
Vector3 right_position = brush_global_position + Vector3(step, 0, 0);
Vector3 down_position = brush_global_position - Vector3(0, 0, step);
Vector3 up_position = brush_global_position + Vector3(0, 0, step);
Vector3 left_position = brush_global_position - Vector3(vertex_spacing, 0.f, 0.f);
Vector3 right_position = brush_global_position + Vector3(vertex_spacing, 0.f, 0.f);
Vector3 down_position = brush_global_position - Vector3(0.f, 0.f, vertex_spacing);
Vector3 up_position = brush_global_position + Vector3(0.f, 0.f, vertex_spacing);

real_t left = srcf, right = srcf, up = srcf, down = srcf;

Expand Down

0 comments on commit 80cf786

Please sign in to comment.