TokisanGames / Terrain3D

A high performance, editable terrain system for Godot 4.
MIT License
2.02k stars 115 forks source link

Use linear filtering for painting height #445

Closed Smorty10 closed 2 weeks ago

Smorty10 commented 1 month ago

Description

When painting the world and using a very large brush size like everything over 150 meters, the aliasing of the brushes become painfully obvious. This can be seen in this image image

I used one of the basic round brushes to create this cliff looking terrain and due to the large brush size, the falloff becomes very step-like. Having the option to paint using a linearly sampled brush texture would get rid of this issue, as such step-like patterns would become interpolated and thus smoothed over.

The image is an extreme case of the problem, but it is still very obvious even with less strong brush stregnth as seen here image I used the very smooth round brush for making this image with a brush size of 500 meters.

I would also advise giving the user the option to switch between nearest-neighbour (the current sampling method) and linear sampling in the brush settings list (at the bottom of the 3d viewport).

Notes

TokisanGames commented 1 month ago

The brush alpha mask is only 100px^2.

I would also advise giving the user the option to switch between nearest-neighbour (the current sampling method) and linear sampling

How would we change the code from sampling nearest to sampling linear, here? https://github.com/TokisanGames/Terrain3D/blob/main/src/terrain_3d_editor.cpp#L171-L216

@Xtarsia any ideas?

Xtarsia commented 1 month ago

The simplest approach would be to provide much larger brushes.

Else when set_brush_data() Is called, resize a copy of the brush image to the desired size ( brush size * 1.44 accounts for rotation too) useing bilinear/lacanzos interpolation, then use the resulting image for painting. This would prevent having to do any real time interpolation.

I'm unsure if godots image function will play nice with exr data tho.

3rd option is a bit heavy and would mean sampling the brush multiple times and doing piecemeal interpolation similar to the current smooth operation, which is already slow.

Xtarsia commented 1 month ago

Adding to the above, its worth always doing the 2nd option, and useing higher res source images for the brushes.

That way when shrinking a brush from 1k wide to 50m for example, there wouldn't be noisey results due to the current nearest filtering.

TokisanGames commented 2 weeks ago

Fixed in #468 by @Xtarsia. See pr for images.