mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-21 13:16:49 +01:00
sine_wave node.
This commit is contained in:
parent
63713bc6cd
commit
0e07f2388c
@ -306,53 +306,14 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
#sine_wave.mmg
|
||||
#Draws a greyscale sine wave pattern
|
||||
|
||||
# "outputs": [
|
||||
# {
|
||||
# "f": "1.0-abs(2.0*($uv.y-0.5)-$amplitude*sin(($frequency*$uv.x+$phase)*6.28318530718))",
|
||||
# "longdesc": "Shows a greyscale image of a sine wave",
|
||||
# "shortdesc": "Output",
|
||||
# "type": "f"
|
||||
# }
|
||||
# ],
|
||||
# "parameters": [
|
||||
# {
|
||||
# "control": "None",
|
||||
# "default": 0.5,
|
||||
# "label": "Amplitude",
|
||||
# "longdesc": "The amplitude of the sine wave function",
|
||||
# "max": 1,
|
||||
# "min": 0,
|
||||
# "name": "amplitude",
|
||||
# "shortdesc": "Amplitude",
|
||||
# "step": 0.01,
|
||||
# "type": "float"
|
||||
# },
|
||||
# {
|
||||
# "control": "None",
|
||||
# "default": 1,
|
||||
# "label": "Frequency",
|
||||
# "longdesc": "The frequency of the sine wave function (i.e. the number of oscillations shown in the generated image).",
|
||||
# "max": 16,
|
||||
# "min": 0,
|
||||
# "name": "frequency",
|
||||
# "shortdesc": "Frequency",
|
||||
# "step": 1,
|
||||
# "type": "float"
|
||||
# },
|
||||
# {
|
||||
# "control": "None",
|
||||
# "default": 0,
|
||||
# "label": "Phase",
|
||||
# "longdesc": "The phase of the sine wave function",
|
||||
# "max": 1,
|
||||
# "min": 0,
|
||||
# "name": "phase",
|
||||
# "shortdesc": "Phase",
|
||||
# "step": 0.01,
|
||||
# "type": "float"
|
||||
# }
|
||||
# ],
|
||||
#Outputs:
|
||||
#Output, float, Shows a greyscale image of a sine wave
|
||||
#1.0-abs(2.0*($uv.y-0.5)-$amplitude*sin(($frequency*$uv.x+$phase)*6.28318530718))
|
||||
|
||||
#Inputs:
|
||||
#amplitude, float, min: 0, max: 1, step: 0.01, default: 0.5
|
||||
#frequency, float, min: 0, max: 16, default: 1
|
||||
#phase, float, min: 0, max: 1, step: 0.01, default: 0.5
|
||||
|
||||
enum CombinerAxisType {
|
||||
SINE,
|
||||
|
@ -1,68 +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 = sinewave(v)
|
||||
# var col : Color = beehive_2_col(v)
|
||||
# var col : Color = beehive_3_col(v)
|
||||
|
||||
image.set_pixel(x, y, col)
|
||||
|
||||
|
||||
image.unlock()
|
||||
|
||||
tex.create_from_image(image)
|
||||
# texture = tex
|
||||
|
||||
var p_o7136_amplitude = 0.500000000;
|
||||
var p_o7136_frequency = 2.000000000;
|
||||
var p_o7136_phase = 0.000000000;
|
||||
|
||||
func sinewave(uv : Vector2) -> Color:
|
||||
return Patterns.sinewavec(uv, p_o7136_amplitude, p_o7136_frequency, p_o7136_phase)
|
||||
|
||||
func reffg():
|
||||
return false
|
||||
|
||||
func reff(bb):
|
||||
if bb:
|
||||
gen()
|
||||
|
61
game/addons/mat_maker_gd/nodes/pattern/sine_wave.gd
Normal file
61
game/addons/mat_maker_gd/nodes/pattern/sine_wave.gd
Normal file
@ -0,0 +1,61 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(float) var amplitude : float = 0.5
|
||||
export(float) var frequency : float = 2
|
||||
export(float) var phase : float = 0
|
||||
|
||||
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_float("get_amplitude", "set_amplitude", "Amplitude", 0.01)
|
||||
mm_graph_node.add_slot_float("get_frequency", "set_frequency", "Frequency", 0.1)
|
||||
mm_graph_node.add_slot_float("get_phase", "set_phase", "Phase", 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:
|
||||
var f : float = 1.0 - abs(2.0 * (uv.y - 0.5) - amplitude *sin((frequency * uv.x + phase)*6.28318530718))
|
||||
|
||||
return Color(f, f, f, 1)
|
||||
|
||||
#amplitude
|
||||
func get_amplitude() -> float:
|
||||
return amplitude
|
||||
|
||||
func set_amplitude(val : float) -> void:
|
||||
amplitude = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#frequency
|
||||
func get_frequency() -> float:
|
||||
return frequency
|
||||
|
||||
func set_frequency(val : float) -> void:
|
||||
frequency = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#phase
|
||||
func get_phase() -> float:
|
||||
return phase
|
||||
|
||||
func set_phase(val : float) -> void:
|
||||
phase = val
|
||||
|
||||
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user