[go: nahoru, domu]

Skip to content

Commit

Permalink
2d preview, noise and bug fixes
Browse files Browse the repository at this point in the history
+ Restored and renamed the preview_2d to TexturePreviewComponent
+ Restored noise, combiners and blend nodes
+ Exposed the spinbox custom step
+ Fixed a bug from d9773e1 affecting dropdown components
  • Loading branch information
HungryProton committed Mar 20, 2023
1 parent b8f2ec1 commit 6e456c7
Show file tree
Hide file tree
Showing 25 changed files with 670 additions and 30 deletions.
9 changes: 9 additions & 0 deletions common/custom_types/noise/combiners/noise_add.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class_name NoiseAdd
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
if z == null:
return clamp(noise_a.get_noise_2d(x, y) + noise_b.get_noise_2d(x, y), -1.0, 1.0)
else:
return clamp(noise_a.get_noise_3d(x, y, z) + noise_b.get_noise_3d(x, y, z), -1.0, 1.0)
26 changes: 26 additions & 0 deletions common/custom_types/noise/combiners/noise_blend.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class_name NoiseBlend
extends NoiseCombiner


var blend_amount: float = 0.5:
set(val):
blend_amount = clamp(val, 0.0, 1.0)


func _init(noise1: ProtonNoise = null, noise2: ProtonNoise = null, amount := 0.0):
super(noise1, noise2)
blend_amount = amount


func _combine_noise(x: float, y: float, z = null) -> float:
var val1 = 0.0
var val2 = 0.0

if z == null:
val1 = noise_a.get_noise_2d(x, y)
val2 = noise_b.get_noise_2d(x, y)
else:
val1 = noise_a.get_noise_3d(x, y, z)
val2 = noise_b.get_noise_3d(x, y, z)

return lerp(val1, val2, blend_amount)
35 changes: 35 additions & 0 deletions common/custom_types/noise/combiners/noise_combiner.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class_name NoiseCombiner
extends ProtonNoise


var noise_a: ProtonNoise
var noise_b: ProtonNoise


func _init(n1: ProtonNoise = null, n2: ProtonNoise = null):
noise_a = n1
noise_b = n2


func get_noise_2d(x:float, y:float) -> float:
return _combine_noise(x, y)


func get_noise_2dv(v: Vector2) -> float:
return _combine_noise(v.x, v.y)


func get_noise_3d(x: float, y: float, z: float) -> float:
return _combine_noise(x, y, z)


func get_noise_3dv(v: Vector3) -> float:
return _combine_noise(v.x, v.y, v.z)


func _combine_noise(x:float, y: float, z = null) -> float:
if z == null:
return noise_b.get_noise_2d(x, y)

else:
return noise_b.get_noise_3d(x, y, z)
9 changes: 9 additions & 0 deletions common/custom_types/noise/combiners/noise_divide.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class_name NoiseDivide
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
if z == null:
return clamp(noise_a.get_noise_2d(x, y) / max(0.001, noise_a.get_noise_2d(x, y)), -1.0, 1.0)
else:
return clamp(noise_a.get_noise_3d(x, y, z) / max(0.001, noise_b.get_noise_3d(x, y, z)), -1.0, 1.0)
9 changes: 9 additions & 0 deletions common/custom_types/noise/combiners/noise_max.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class_name NoiseMax
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
if z == null:
return max(noise_a.get_noise_2d(x, y), noise_b.get_noise_2d(x, y))
else:
return max(noise_a.get_noise_3d(x, y, z), noise_b.get_noise_3d(x, y, z))
9 changes: 9 additions & 0 deletions common/custom_types/noise/combiners/noise_min.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class_name NoiseMin
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
if z == null:
return min(noise_a.get_noise_2d(x, y), noise_b.get_noise_2d(x, y))
else:
return min(noise_a.get_noise_3d(x, y, z), noise_b.get_noise_3d(x, y, z))
9 changes: 9 additions & 0 deletions common/custom_types/noise/combiners/noise_multiply.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class_name NoiseMultiply
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
if z == null:
return noise_a.get_noise_2d(x, y) * noise_b.get_noise_2d(x, y)
else:
return noise_a.get_noise_3d(x, y, z) * noise_b.get_noise_3d(x, y, z)
18 changes: 18 additions & 0 deletions common/custom_types/noise/combiners/noise_overlay.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class_name NoiseOverlay
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
var a
var b
if z == null:
a = noise_a.get_noise_2d(x, y)
b = noise_b.get_noise_2d(x, y)
else:
a = noise_a.get_noise_3d(x, y, z)
b = noise_b.get_noise_3d(x, y, z)

if a < 0.5:
return 2 * a * b

return 1 - 2 * (1 - a) * (1 - b)
15 changes: 15 additions & 0 deletions common/custom_types/noise/combiners/noise_screen.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class_name NoiseScreen
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
var a
var b
if z == null:
a = noise_a.get_noise_2d(x, y)
b = noise_b.get_noise_2d(x, y)
else:
a = noise_a.get_noise_3d(x, y, z)
b = noise_b.get_noise_3d(x, y, z)

return 1 - (1 - a) * (1 - b)
9 changes: 9 additions & 0 deletions common/custom_types/noise/combiners/noise_substract.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class_name NoiseSubstract
extends NoiseCombiner


func _combine_noise(x: float, y: float, z = null) -> float:
if z == null:
return clamp(noise_a.get_noise_2d(x, y) - noise_b.get_noise_2d(x, y), -1.0, 1.0)
else:
return clamp(noise_a.get_noise_3d(x, y, z) - noise_b.get_noise_3d(x, y, z), -1.0, 1.0)
55 changes: 55 additions & 0 deletions common/custom_types/noise/noise.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class_name ProtonNoise
extends RefCounted


var curve: Curve


func get_noise_2d(_x: float, _y: float) -> float:
return 0.0


func get_noise_2dv(_v: Vector2) -> float:
return 0.0


func get_noise_3d(_x: float, _y: float, _z: float) -> float:
return 0.0


func get_noise_3dv(_v: Vector3) -> float:
return 0.0


func get_image(width: int, height: int, scale = 1.0, offset = Vector2()) -> Image:
var bytes = PackedByteArray()
bytes.resize(width * height * 3)

var color
var val = 0
var i = 0

for y in height:
for x in width:
val = get_noise_2d(
offset.x + (x * scale),
offset.y + (y * scale)
) * 0.5 + 0.5
color = Color(val, val, val)
bytes[i] = color.r8
bytes[i + 1] = color.g8
bytes[i + 2] = color.b8
i += 3

return Image.create_from_data(width, height, false, Image.FORMAT_RGB8, bytes)


func apply_curve(noise_value: float) -> float:
if not curve is Curve:
return noise_value

return clamp(
curve.sample_baked(noise_value * 0.5 + 0.5) * 2.0 - 1.0,
-1.0,
1.0
)
29 changes: 29 additions & 0 deletions common/custom_types/noise/noise_fast_lite.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends ProtonNoise
class_name ProtonNoiseFast


var _fast_noise: FastNoiseLite


func _init():
_fast_noise = FastNoiseLite.new()


func get_noise_2d(x: float, y: float) -> float:
return apply_curve(_fast_noise.get_noise_2d(x, y))


func get_noise_2dv(v: Vector2) -> float:
return apply_curve(_fast_noise.get_noise_2dv(v))


func get_noise_3d(x: float, y: float, z: float) -> float:
return apply_curve(_fast_noise.get_noise_3d(x, y, z))


func get_noise_3dv(v: Vector3) -> float:
return apply_curve(_fast_noise.get_noise_3dv(v))


func get_noise_object() -> FastNoiseLite:
return _fast_noise
2 changes: 2 additions & 0 deletions common/static/ui_util.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static func create_component(name: String, type: int, opts: SlotOptions) -> Grap
DataType.MISC:
if opts.has_dropdown():
component = DropdownComponent.new()
DataType.MISC_PREVIEW_2D:
component = TexturePreviewComponent.new()

if not component:
component = GenericInputComponent.new()
Expand Down
15 changes: 14 additions & 1 deletion core/proton_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class_name ProtonNode
extends Resource


signal local_value_changed(idx, value)
signal layout_changed
signal local_value_changed(idx: String, value: Variant)
signal extra_changed(idx: String, value: Variant)


var external_data: Dictionary
Expand Down Expand Up @@ -187,6 +188,18 @@ func set_output(idx: String, value: Variant) -> void:
outputs[idx].computed_value_ready = true


func set_extra(idx: String, value: Variant) -> void:
if not idx in extras:
push_error("Invalid index: ", idx, " was not found in extras")
return

if not value is Array:
value = [value]

extras[idx].computed_value = value
extra_changed.emit(idx, value)


func clear_values() -> void:
for idx in inputs:
inputs[idx].computed_value = []
Expand Down
10 changes: 3 additions & 7 deletions examples/brick_wall.tpgn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ connections=[{
"to_idx": "curve"
}]
external_data={
"scroll_offset": Vector2i(932, 1194)
"scroll_offset": Vector2i(851, 1088)
}

[curve_sample_points_even]
Expand Down Expand Up @@ -111,12 +111,10 @@ local_values={
"local_pos_offset": true,
"local_rotation": false,
"local_scale": false,
"min_amount": -1.0,
"pos_offset": Vector3(0, 0.42, 0),
"rotation": Vector3(0, 0, 0),
"rotation_pivot": Vector3(0, 0, 0),
"scale": Vector3(1, 1, 1),
"seed": 0.0
"scale": Vector3(1, 1, 1)
}
custom_data={}
external_data={
Expand All @@ -136,12 +134,10 @@ local_values={
"local_pos_offset": true,
"local_rotation": false,
"local_scale": false,
"min_amount": -1.0,
"pos_offset": Vector3(0, 0.21, 0.2),
"rotation": Vector3(0, 0, 0),
"rotation_pivot": Vector3(0, 0, 0),
"scale": Vector3(1, 1, 1),
"seed": 0.0
"scale": Vector3(1, 1, 1)
}
custom_data={}
external_data={
Expand Down
Loading

0 comments on commit 6e456c7

Please sign in to comment.