mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-18 01:06:47 +01:00
Moved circular gradient calculations to gradients.gd. This time the logic had to be changed extensively and the new logic still has bugs. It will be fixed later.
This commit is contained in:
parent
b3604ffebc
commit
0fc71e0f2c
87
game/addons/mat_maker_gd/nodes/common/gradients.gd
Normal file
87
game/addons/mat_maker_gd/nodes/common/gradients.gd
Normal file
@ -0,0 +1,87 @@
|
||||
extends Reference
|
||||
|
||||
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
|
||||
#note: data : PoolRealArray -> pos, r, g, b, a, pos, r, g, b, a ....
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
static func gradient_type_1(x : float, data : PoolRealArray) -> Color:
|
||||
if data.size() % 5 != 0 || data.size() == 0:
|
||||
return Color()
|
||||
|
||||
for i in range(0, data.size() - 5, 5):
|
||||
if x < 0.5 * (data[i] + data[i + 5]):
|
||||
return Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
|
||||
var ds = data.size() - 5
|
||||
return Color(data[ds + 1], data[ds + 2], data[ds + 3], data[ds + 4])
|
||||
|
||||
static func gradient_type_2(x : float, data : PoolRealArray) -> Color:
|
||||
if data.size() % 5 != 0 || data.size() == 0:
|
||||
return Color()
|
||||
|
||||
for i in range(0, data.size() - 5, 5):
|
||||
if x < data[i]:
|
||||
if i == 0:
|
||||
return Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
|
||||
var cprev : Color = Color(data[i - 4], data[i - 3], data[i - 2], data[i - 1])
|
||||
var ccurr : Color = Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
return lerp(cprev, ccurr, (x - data[i - 5]) / (data[i] - data[i - 5]));
|
||||
|
||||
var ds = data.size() - 5
|
||||
return Color(data[ds + 1], data[ds + 2], data[ds + 3], data[ds + 4])
|
||||
|
||||
static func gradient_type_3(x : float, data : PoolRealArray) -> Color:
|
||||
if data.size() % 5 != 0 || data.size() == 0:
|
||||
return Color()
|
||||
|
||||
for i in range(0, data.size() - 5, 5):
|
||||
if x < data[i]:
|
||||
if i == 0:
|
||||
return Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
|
||||
var cprev : Color = Color(data[i - 4], data[i - 3], data[i - 2], data[i - 1])
|
||||
var ccurr : Color = Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
return lerp(cprev, ccurr, 0.5 - 0.5 * cos(3.14159265359 * ((x - data[i - 5]) / (data[i] - data[i - 5]))))
|
||||
|
||||
var ds = data.size() - 5
|
||||
return Color(data[ds + 1], data[ds + 2], data[ds + 3], data[ds + 4])
|
||||
|
||||
#todo, logic is not yet finished
|
||||
static func gradient_type_4(x : float, data : PoolRealArray) -> Color:
|
||||
if data.size() % 5 != 0 || data.size() == 0:
|
||||
return Color()
|
||||
|
||||
for i in range(0, data.size() - 5, 5):
|
||||
if x < data[i]:
|
||||
if i == 0:
|
||||
return Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
|
||||
var cprev : Color = Color(data[i - 4], data[i - 3], data[i - 2], data[i - 1])
|
||||
var ccurr : Color = Color(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
|
||||
return lerp(cprev, ccurr, 0.5 - 0.5 * cos(3.14159265359 * ((x - data[i - 5]) / (data[i] - data[i - 5]))))
|
||||
|
||||
var ds = data.size() - 5
|
||||
return Color(data[ds + 1], data[ds + 2], data[ds + 3], data[ds + 4])
|
||||
|
||||
|
||||
# if (x < gradient_0_pos):
|
||||
# return Color(gradient_0_r,gradient_0_g,gradient_0_b,gradient_0_a);
|
||||
# elif (x < gradient_1_pos):
|
||||
# return lerp(lerp(Color(gradient_1_r,gradient_1_g,gradient_1_b,gradient_1_a), Color(gradient_2_r,gradient_2_g,gradient_2_b,gradient_2_a), (x-gradient_1_pos)/(gradient_2_pos-gradient_1_pos)), lerp(Color(gradient_0_r,gradient_0_g,gradient_0_b,gradient_0_a), Color(gradient_1_r,gradient_1_g,gradient_1_b,gradient_1_a), (x-gradient_0_pos)/(gradient_1_pos-gradient_0_pos)), 1.0-0.5*(x-gradient_0_pos)/(gradient_1_pos-gradient_0_pos));
|
||||
# elif (x < gradient_2_pos):
|
||||
# return lerp(lerp(Color(gradient_0_r,gradient_0_g,gradient_0_b,gradient_0_a), Color(gradient_1_r,gradient_1_g,gradient_1_b,gradient_1_a), (x-gradient_0_pos)/(gradient_1_pos-gradient_0_pos)), lerp(Color(gradient_1_r,gradient_1_g,gradient_1_b,gradient_1_a), Color(gradient_2_r,gradient_2_g,gradient_2_b,gradient_2_a), (x-gradient_1_pos)/(gradient_2_pos-gradient_1_pos)), 0.5+0.5*(x-gradient_1_pos)/(gradient_2_pos-gradient_1_pos));
|
||||
#
|
||||
# return Color(gradient_2_r,gradient_2_g,gradient_2_b,gradient_2_a);
|
@ -1,6 +1,7 @@
|
||||
tool
|
||||
extends TextureRect
|
||||
|
||||
var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd")
|
||||
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
|
||||
var image : Image
|
||||
@ -48,6 +49,27 @@ func gen() -> void:
|
||||
# var bmin : Vector2 = Vector2(0.1, 0.1)
|
||||
# var bmax : Vector2 = Vector2(1, 1)
|
||||
|
||||
var data : PoolRealArray = PoolRealArray()
|
||||
data.resize(15)
|
||||
var i : int = 0
|
||||
data[i + 0] = p_o95415_gradient_0_pos
|
||||
data[i + 1] = p_o95415_gradient_0_r
|
||||
data[i + 2] = p_o95415_gradient_0_g
|
||||
data[i + 3] = p_o95415_gradient_0_b
|
||||
data[i + 4] = p_o95415_gradient_0_a
|
||||
i += 5
|
||||
data[i + 0] = p_o95415_gradient_1_pos
|
||||
data[i + 1] = p_o95415_gradient_1_r
|
||||
data[i + 2] = p_o95415_gradient_1_g
|
||||
data[i + 3] = p_o95415_gradient_1_b
|
||||
data[i + 4] = p_o95415_gradient_1_a
|
||||
i += 5
|
||||
data[i + 0] = p_o95415_gradient_2_pos
|
||||
data[i + 1] = p_o95415_gradient_2_r
|
||||
data[i + 2] = p_o95415_gradient_2_g
|
||||
data[i + 3] = p_o95415_gradient_2_b
|
||||
data[i + 4] = p_o95415_gradient_2_a
|
||||
|
||||
image.lock()
|
||||
|
||||
var w : float = image.get_width()
|
||||
@ -57,15 +79,16 @@ func gen() -> void:
|
||||
|
||||
for x in range(image.get_width()):
|
||||
for y in range(image.get_height()):
|
||||
var v : Vector2 = Vector2(x / w, y / h)
|
||||
var uv : Vector2 = Vector2(x / w, y / h)
|
||||
|
||||
#branchless fix for division by zero
|
||||
v.y += 0.000001
|
||||
uv.y += 0.000001
|
||||
|
||||
# var col : Color = gradient_type_1(fractf(p_o95415_repeat * 0.15915494309 * atan((v.x - 0.5) / (v.y - 0.5))));
|
||||
# var col : Color = gradient_type_2(fractf(p_o95415_repeat * 0.15915494309 * atan((v.x - 0.5) / (v.y - 0.5))));
|
||||
# var col : Color = gradient_type_3(fractf(p_o95415_repeat * 0.15915494309 * atan((v.x - 0.5) / (v.y - 0.5))));
|
||||
var col : Color = gradient_type_4(Commons.fractf(p_o95415_repeat * 0.15915494309 * atan((v.x - 0.5) / v.y - 0.5)));
|
||||
# var col : Color = gradient_type_1(Commons.fractf(p_o95415_repeat * 0.15915494309 * atan((uv.x - 0.5) / (uv.y - 0.5))));
|
||||
# var col : Color = gradient_type_2(Commons.fractf(p_o95415_repeat * 0.15915494309 * atan((uv.x - 0.5) / (uv.y - 0.5))));
|
||||
# var col : Color = gradient_type_3(Commons.fractf(p_o95415_repeat * 0.15915494309 * atan((uv.x - 0.5) / (uv.y - 0.5))));
|
||||
# var col : Color = gradient_type_4(Commons.fractf(p_o95415_repeat * 0.15915494309 * atan((uv.x - 0.5) / uv.y - 0.5)));
|
||||
var col : Color = Gradients.circular_gradient_type_1(uv, p_o95415_repeat, data);
|
||||
|
||||
image.set_pixel(x, y, col)
|
||||
|
||||
@ -74,6 +97,7 @@ func gen() -> void:
|
||||
tex.create_from_image(image)
|
||||
texture = tex
|
||||
|
||||
|
||||
func gradient_type_1(x : float) -> Color:
|
||||
if (x < 0.5*(p_o95415_gradient_0_pos+p_o95415_gradient_1_pos)):
|
||||
return Color(p_o95415_gradient_0_r,p_o95415_gradient_0_g,p_o95415_gradient_0_b,p_o95415_gradient_0_a);
|
||||
@ -113,6 +137,7 @@ func gradient_type_4(x : float) -> Color:
|
||||
|
||||
return Color(p_o95415_gradient_2_r,p_o95415_gradient_2_g,p_o95415_gradient_2_b,p_o95415_gradient_2_a);
|
||||
|
||||
|
||||
func reffg():
|
||||
return false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user