mohsenph69 / Godot-MTerrain-plugin

A GDExtension plugin which give godot the ability to produce highly optimized Terrain for Open world games
MIT License
372 stars 19 forks source link

add brush shape fariation and brush decal with shape #22

Open agung098 opened 6 months ago

agung098 commented 6 months ago

func paint_height(coord: Vector2): heightmap = current_terrain.get_material().get_heightmap() heightmap_img = heightmap.get_image() brush_shape = toolbar.get_brush_shape() brush_shape_size = brush_shape.get_size() var heightmap_size: Vector2i = heightmap_img.get_size() var brush_size: int = toolbar.get_brush_size()

var brush_opacity: float = toolbar.get_brush_opacity()
var brush_flow: float = toolbar.get_brush_flow()

var rand_rotation: float = PI * randf()
var brush_position : Vector2i
var pixel_position : Vector2i
var brush_shape_uv: Vector2
var cor_brush = coord / current_terrain.size
var brush_center = brush_size / 2
var brush_cen = Vector2(brush_center, brush_center)
for x in brush_size:
    for y in brush_size:
        brush_shape_uv = Vector2(x,y) / brush_size
        brush_shape_uv = rotate_uv(brush_shape_uv, rand_rotation)
        var brush_offset: Vector2i = Vector2(x, y) - brush_cen
        brush_position = Vector2(Vector2(heightmap_size) * cor_brush)
        pixel_position = (brush_position + brush_offset)
        var hight
        if is_in_bounds(pixel_position, heightmap_size):
            gizmo_plugin.gizmo_rotation = rand_rotation
            var brush_pixel_position: Vector2i = Vector2i(brush_shape_uv * Vector2(brush_shape_size))
            brush_pixel_position = brush_pixel_position.clamp(Vector2i.ZERO, brush_shape_size - Vector2i.ONE)

            var alpha: float = brush_shape.get_pixelv(brush_pixel_position).r
            var source: float = heightmap_img.get_pixelv(pixel_position).r
            target = source
            if toolbar.current_mode == toolbar.Mode.HEIGHT_ADD:
                target = lerp(source, source + (brush_opacity * alpha), (brush_opacity * alpha) + .05)

decal.txt

mohsenph69 commented 6 months ago

Please explain more about what you want to achieve exactly!

Thanks!

agung098 commented 6 months ago

Please watching this :https://youtu.be/_6bepq_DGJw?si=VDYKONNjMkKJWy12

mohsenph69 commented 6 months ago

This Terrain system is different to other plugin

It has its own way of brush and brush mask system!

Watch this video to see how brush mask works: https://www.youtube.com/watch?v=_hLjIuJbziU

There are also other good tutorial on my youtube channel about how terrain works