Implemented circular gradient node, and fixed circular gradient calculation.

This commit is contained in:
Relintai 2021-10-17 17:40:16 +02:00
parent 6a241d3051
commit f74ad34219
2 changed files with 64 additions and 4 deletions

View File

@ -64,16 +64,16 @@ static func normal_gradient_type_4(uv : Vector2, repeat : float, rotate : float,
static func circular_gradient_type_1(uv : Vector2, repeat : float, data : PoolRealArray) -> Color:
return gradient_type_1(Commons.fractf(repeat * 0.15915494309 * atan((uv.x - 0.5) / uv.y - 0.5)), data)
return gradient_type_1(Commons.fractf(repeat * 0.15915494309 * atan2((uv.y - 0.5), uv.x - 0.5)), data)
static func circular_gradient_type_2(uv : Vector2, repeat : float, data : PoolRealArray) -> Color:
return gradient_type_2(Commons.fractf(repeat * 0.15915494309 * atan((uv.x - 0.5) / uv.y - 0.5)), data)
return gradient_type_2(Commons.fractf(repeat * 0.15915494309 * atan2((uv.y - 0.5), uv.x - 0.5)), data)
static func circular_gradient_type_3(uv : Vector2, repeat : float, data : PoolRealArray) -> Color:
return gradient_type_3(Commons.fractf(repeat * 0.15915494309 * atan((uv.x - 0.5) / uv.y - 0.5)), data)
return gradient_type_3(Commons.fractf(repeat * 0.15915494309 * atan2((uv.y - 0.5), uv.x - 0.5)), data)
static func circular_gradient_type_4(uv : Vector2, repeat : float, data : PoolRealArray) -> Color:
return gradient_type_4(Commons.fractf(repeat * 0.15915494309 * atan((uv.x - 0.5) / uv.y - 0.5)), data)
return gradient_type_4(Commons.fractf(repeat * 0.15915494309 * atan2((uv.y - 0.5), uv.x - 0.5)), data)
static func gradient_type_1(x : float, data : PoolRealArray) -> Color:

View File

@ -0,0 +1,60 @@
tool
extends "res://addons/mat_maker_gd/nodes/bases/gradient_base.gd"
var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd")
export(Resource) var image : Resource
export(float) var repeat : float = 1
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_repeat", "set_repeat", "repeat")
mm_graph_node.add_slot_gradient()
func _render(material) -> void:
var img : Image = render_image(material)
image.set_value(img)
func get_value_for(uv : Vector2, pseed : int) -> Color:
if interpolation_type == 0:
return Gradients.circular_gradient_type_1(uv, repeat, points)
elif interpolation_type == 1:
return Gradients.circular_gradient_type_2(uv, repeat, points)
elif interpolation_type == 2:
return Gradients.circular_gradient_type_3(uv, repeat, points)
elif interpolation_type == 3:
return Gradients.circular_gradient_type_4(uv, repeat, points)
return Color(1, 1, 1, 1)
func get_gradient_color(x : float) -> Color:
if interpolation_type == 0:
return Gradients.gradient_type_1(x, points)
elif interpolation_type == 1:
return Gradients.gradient_type_2(x, points)
elif interpolation_type == 2:
return Gradients.gradient_type_3(x, points)
elif interpolation_type == 3:
return Gradients.gradient_type_4(x, points)
return Color(1, 1, 1, 1)
func get_repeat() -> float:
return repeat
func set_repeat(val : float) -> void:
repeat = val
set_dirty(true)