Scratches node.

This commit is contained in:
Relintai 2021-10-18 20:06:49 +02:00
parent 0e07f2388c
commit a317240526
3 changed files with 83 additions and 71 deletions

View File

@ -536,8 +536,8 @@ static func scratches(uv : Vector2, layers : int, size : Vector2, waviness : flo
var v : float = 0.0;
for i in range(layers):# (int i = 0; i < layers; ++i) {
v = max(v, scratch(Commons.fractv2(uv + pseed), size, waviness, angle/360.0, randomness, pseed));
pseed = Commons.rand2(pseed);
v = max(v, scratch(Commons.fractv2(uv + pseed), size, waviness, angle/360.0, randomness, pseed));
return v;

View File

@ -1,70 +0,0 @@
tool
extends MMNode
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
var image : Image
var tex : ImageTexture
export(Vector2) var bmin : Vector2 = Vector2(0.1, 0.1)
export(Vector2) var bmax : Vector2 = Vector2(1, 1)
export(bool) var refresh setget reff,reffg
func _ready():
if !Engine.editor_hint:
gen()
func gen() -> void:
if !image:
image = Image.new()
image.create(300, 300, false, Image.FORMAT_RGBA8)
if !tex:
tex = ImageTexture.new()
# var bmin : Vector2 = Vector2(0.1, 0.1)
# var bmax : Vector2 = Vector2(1, 1)
image.lock()
var w : float = image.get_width()
var h : float = image.get_width()
var pseed : float = randf() + randi()
for x in range(image.get_width()):
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
# var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
var col : Color = scratchescol(v)
image.set_pixel(x, y, col)
image.unlock()
tex.create_from_image(image)
# texture = tex
var seed_o74963 = 31821;
var p_o74963_length = 0.250000000;
var p_o74963_width = 0.400000000;
var p_o74963_layers = 5.000000000;
var p_o74963_waviness = 0.510000000;
var p_o74963_angle = -1.000000000;
var p_o74963_randomness = 0.440000000;
func scratchescol(uv : Vector2) -> Color:
return Patterns.scratchesc(uv, int(p_o74963_layers), Vector2(p_o74963_length, p_o74963_width), p_o74963_waviness, p_o74963_angle, p_o74963_randomness, Vector2(float(seed_o74963), 0.0));
func reffg():
return false
func reff(bb):
if bb:
gen()

View File

@ -0,0 +1,82 @@
tool
extends MMNode
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
export(Resource) var image : Resource
export(Vector2) var size : Vector2 = Vector2(0.25, 0.4)
export(int) var layers : int = 4
export(float) var waviness : float = 0.51
export(int) var angle : int = 0
export(float) var randomness : float = 0.44
func _init_properties():
if !image:
image = MMNodeUniversalProperty.new()
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
register_output_property(image)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture_universal(image)
mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 0.01)
mm_graph_node.add_slot_int("get_layers", "set_layers", "Layers")
mm_graph_node.add_slot_float("get_waviness", "set_waviness", "Waviness", 0.01)
mm_graph_node.add_slot_int("get_angle", "set_angle", "Angle")
mm_graph_node.add_slot_float("get_randomness", "set_randomness", "Randomness", 0.01)
func _render(material) -> void:
var img : Image = render_image(material)
image.set_value(img)
func get_value_for(uv : Vector2, pseed : int) -> Color:
#scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0))
return Patterns.scratchesc(uv, layers, size, waviness, angle, randomness, Vector2(pseed, 0.0))
#size
func get_size() -> Vector2:
return size
func set_size(val : Vector2) -> void:
size = val
set_dirty(true)
#layers
func get_layers() -> int:
return layers
func set_layers(val : int) -> void:
layers = val
set_dirty(true)
#waviness
func get_waviness() -> float:
return waviness
func set_waviness(val : float) -> void:
waviness = val
set_dirty(true)
#angle
func get_angle() -> int:
return angle
func set_angle(val : int) -> void:
angle = val
set_dirty(true)
#randomness
func get_randomness() -> float:
return randomness
func set_randomness(val : float) -> void:
randomness = val
set_dirty(true)