Compare commits
No commits in common. "73de0506286124194abef2bebf35ffc1ce3d2cc7" and "0b19b9729313b526ae1e9918b98f5229b5853b85" have entirely different histories.
73de050628
...
0b19b97293
BIN
editor.scn (Stored with Git LFS)
BIN
editor.scn (Stored with Git LFS)
Binary file not shown.
|
@ -36,11 +36,13 @@ var size := Vector2i.ZERO:
|
|||
|
||||
size = value
|
||||
|
||||
func _get_brush_area(point: Vector2i, mask_size: Vector2i, scale: float) -> Rect2i:
|
||||
# Convert worldspace point to image-space coordinates for mask.
|
||||
var scaled_mask_size := Vector2i(mask_size * scale)
|
||||
func _get_draw_area(point: Vector2i, mask: Image, scale: float) -> Rect2i:
|
||||
# Convert worldspace point to image-space coordinates for brush and calculate drawable area.
|
||||
var mask_size := mask.get_size()
|
||||
var scaled_mask_size := mask_size * scale
|
||||
|
||||
return Rect2i((point + Vector2i(size * 0.5)) - Vector2i(scaled_mask_size * 0.5), scaled_mask_size)
|
||||
return Rect2i(Vector2i.ZERO, size).intersection(
|
||||
Rect2i((point - Vector2i(scaled_mask_size * 0.5)) + Vector2i(size * 0.5), scaled_mask_size))
|
||||
|
||||
func _init() -> void:
|
||||
clear(BLANK)
|
||||
|
@ -57,29 +59,22 @@ func clear(clear_color: Color) -> void:
|
|||
##
|
||||
##
|
||||
##
|
||||
func oscillate(point: Vector2i, level: float,
|
||||
mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
func lower(point: Vector2i, mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
var mask_size := mask.get_size()
|
||||
var brush_source := _get_brush_area(point, mask_size, scale)
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
if brush_source.has_area():
|
||||
var brush_target := Rect2i(Vector2i.ZERO, size).intersection(brush_source)
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
if brush_target.has_area():
|
||||
var mask_ratio := mask_size / brush_source.size
|
||||
var offset := brush_target.position - brush_source.position
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
for y in brush_target.size.y:
|
||||
var mask_y := int((offset.y + y) * mask_ratio.y)
|
||||
|
||||
for x in brush_target.size.x:
|
||||
var coord := brush_target.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(coord)
|
||||
|
||||
_image.set_pixelv(coord, Color(pixel.r, pixel.g, pixel.b,
|
||||
lerpf(pixel.a, level, intensity * delta *\
|
||||
mask.get_pixel(int((offset.x + x) * mask_ratio.x), mask_y).a)).clamp())
|
||||
_image.set_pixelv(terrain_map_coord, Color(pixel.r, pixel.g, pixel.b,
|
||||
lerpf(pixel.a, pixel.a - (intensity *
|
||||
mask.get_pixel(int(x * mask_ratio.x), brush_mask_y).a), delta)).clamp())
|
||||
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
@ -87,33 +82,134 @@ func oscillate(point: Vector2i, level: float,
|
|||
##
|
||||
##
|
||||
##
|
||||
func paint(point: Vector2i, color: Color,
|
||||
mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
func paint_blue(point: Vector2i, mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
var mask_size := mask.get_size()
|
||||
var brush_source := _get_brush_area(point, mask_size, scale)
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
if brush_source.has_area():
|
||||
var brush_target := Rect2i(Vector2i.ZERO, size).intersection(brush_source)
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
if brush_target.has_area():
|
||||
var mask_ratio := mask_size / brush_source.size
|
||||
var offset := brush_target.position - brush_source.position
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
for y in brush_target.size.y:
|
||||
var mask_y := int((offset.y + y) * mask_ratio.y)
|
||||
var mask_intensity_delta := intensity *\
|
||||
delta * mask.get_pixel(int(x * mask_ratio.x), brush_mask_y).a
|
||||
|
||||
for x in brush_target.size.x:
|
||||
var coord := brush_target.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(coord)
|
||||
_image.set_pixelv(terrain_map_coord, Color(
|
||||
lerpf(pixel.r, 0.0, mask_intensity_delta),
|
||||
lerpf(pixel.g, 0.0, mask_intensity_delta),
|
||||
lerpf(pixel.b, 1.0, mask_intensity_delta),
|
||||
pixel.a).clamp())
|
||||
|
||||
var mask_intensity_delta := intensity * delta *\
|
||||
mask.get_pixel(int((offset.x + x) * mask_ratio.x), mask_y).a
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
||||
_image.set_pixelv(coord, Color(
|
||||
lerpf(pixel.r, color.r, mask_intensity_delta),
|
||||
lerpf(pixel.g, color.g, mask_intensity_delta),
|
||||
lerpf(pixel.b, color.b, mask_intensity_delta), pixel.a).clamp())
|
||||
##
|
||||
##
|
||||
##
|
||||
func paint_erase(point: Vector2i, mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
var mask_intensity_delta := intensity *\
|
||||
delta * mask.get_pixel(int(x * mask_ratio.x), brush_mask_y).a
|
||||
|
||||
_image.set_pixelv(terrain_map_coord, Color(
|
||||
lerpf(pixel.r, 0.0, mask_intensity_delta),
|
||||
lerpf(pixel.g, 0.0, mask_intensity_delta),
|
||||
lerpf(pixel.b, 0.0, mask_intensity_delta),
|
||||
pixel.a).clamp())
|
||||
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
||||
##
|
||||
##
|
||||
##
|
||||
func paint_green(point: Vector2i, mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
var mask_intensity_delta := intensity *\
|
||||
delta * mask.get_pixel(int(x * mask_ratio.x), brush_mask_y).a
|
||||
|
||||
_image.set_pixelv(terrain_map_coord, Color(
|
||||
lerpf(pixel.r, 0.0, mask_intensity_delta),
|
||||
lerpf(pixel.g, 1.0, mask_intensity_delta),
|
||||
lerpf(pixel.b, 0.0, mask_intensity_delta),
|
||||
pixel.a).clamp())
|
||||
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
||||
##
|
||||
##
|
||||
##
|
||||
func paint_red(point: Vector2i, mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
var mask_intensity_delta := intensity *\
|
||||
delta * mask.get_pixel(int(x * mask_ratio.x), brush_mask_y).a
|
||||
|
||||
_image.set_pixelv(terrain_map_coord, Color(
|
||||
lerpf(pixel.r, 1.0, mask_intensity_delta),
|
||||
lerpf(pixel.g, 0.0, mask_intensity_delta),
|
||||
lerpf(pixel.b, 0.0, mask_intensity_delta),
|
||||
pixel.a).clamp())
|
||||
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
||||
##
|
||||
##
|
||||
##
|
||||
func raise(point: Vector2i, mask: Image, scale: float, intensity: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
_image.set_pixelv(terrain_map_coord, Color(pixel.r, pixel.g, pixel.b,
|
||||
lerpf(pixel.a, pixel.a + (intensity *
|
||||
mask.get_pixel(int(x * mask_ratio.x), brush_mask_y).a), delta)).clamp())
|
||||
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
@ -132,3 +228,26 @@ func sample(point: Vector2i) -> Color:
|
|||
return _image.get_pixelv(image_point)
|
||||
|
||||
return BLANK
|
||||
|
||||
##
|
||||
##
|
||||
##
|
||||
func smooth(point: Vector2i, mask: Image, scale: float, level: float, delta: float) -> void:
|
||||
var draw_area := _get_draw_area(point, mask, scale)
|
||||
|
||||
if draw_area.has_area():
|
||||
var mask_ratio := mask.get_size() / draw_area.size
|
||||
|
||||
for y in draw_area.size.y:
|
||||
var brush_mask_y := int(y * mask_ratio.y)
|
||||
|
||||
for x in draw_area.size.x:
|
||||
var terrain_map_coord := draw_area.position + Vector2i(x, y)
|
||||
var pixel := _image.get_pixelv(terrain_map_coord)
|
||||
|
||||
_image.set_pixelv(terrain_map_coord, Color(pixel.r, pixel.g, pixel.b,
|
||||
lerpf(pixel.a, level, delta * mask.get_pixel(
|
||||
int(x * mask_ratio.x), brush_mask_y).a)).clamp())
|
||||
|
||||
if instance != null:
|
||||
instance.terrain_map.update(_image)
|
||||
|
|
|
@ -24,7 +24,7 @@ uniform sampler2D TERRAIN_MAP : hint_default_transparent, repeat_disable;
|
|||
|
||||
void fragment() {
|
||||
vec2 uv = UV * (SIZE / 2.0);
|
||||
vec2 uv_alt = uv * -0.5;
|
||||
vec2 uv_alt = uv * -0.25;
|
||||
vec3 splat_map = texture(TERRAIN_MAP, UV).rgb;
|
||||
float blank = clamp(1.0 - splat_map.r - splat_map.g - splat_map.b, 0.0, 1.0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue