Added the current shader code from material maker as a comment to shapes.

This commit is contained in:
Relintai 2021-10-05 11:54:16 +02:00
parent 54003493f2
commit 9f41deb164

View File

@ -3,6 +3,12 @@ extends Reference
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd") const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
#float shape_circle(vec2 uv, float sides, float size, float edge) {
# uv = 2.0*uv-1.0;edge = max(edge, 1.0e-8);
# float distance = length(uv);
# return clamp((1.0-distance/size)/edge, 0.0, 1.0);
#}
static func shape_circle(uv : Vector2, sides : float, size : float, edge : float) -> float: static func shape_circle(uv : Vector2, sides : float, size : float, edge : float) -> float:
uv.x = 2.0 * uv.x - 1.0 uv.x = 2.0 * uv.x - 1.0
uv.y = 2.0 * uv.y - 1.0 uv.y = 2.0 * uv.y - 1.0
@ -13,6 +19,13 @@ static func shape_circle(uv : Vector2, sides : float, size : float, edge : float
return clamp((1.0 - distance / size) / edge, 0.0, 1.0) return clamp((1.0 - distance / size) / edge, 0.0, 1.0)
#float shape_polygon(vec2 uv, float sides, float size, float edge) {
# uv = 2.0*uv-1.0;edge = max(edge, 1.0e-8);
# float angle = atan(uv.x, uv.y)+3.14159265359;
# float slice = 6.28318530718/sides;
# return clamp((1.0-(cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/size)/edge, 0.0, 1.0);
#}
static func shape_polygon(uv : Vector2, sides : float, size : float, edge : float) -> float: static func shape_polygon(uv : Vector2, sides : float, size : float, edge : float) -> float:
uv.x = 2.0 * uv.x - 1.0 uv.x = 2.0 * uv.x - 1.0
uv.y = 2.0 * uv.y - 1.0 uv.y = 2.0 * uv.y - 1.0
@ -27,6 +40,13 @@ static func shape_polygon(uv : Vector2, sides : float, size : float, edge : floa
return clamp((size - cos(floor(0.5 + angle / slice) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0) return clamp((size - cos(floor(0.5 + angle / slice) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0)
#float shape_star(vec2 uv, float sides, float size, float edge) {
# uv = 2.0*uv-1.0;edge = max(edge, 1.0e-8);
# float angle = atan(uv.x, uv.y);
# float slice = 6.28318530718/sides;
# return clamp((1.0-(cos(floor(angle*sides/6.28318530718-0.5+2.0*step(fract(angle*sides/6.28318530718), 0.5))*slice-angle)*length(uv))/size)/edge, 0.0, 1.0);
#}
static func shape_star(uv : Vector2, sides : float, size : float, edge : float) -> float: static func shape_star(uv : Vector2, sides : float, size : float, edge : float) -> float:
uv.x = 2.0 * uv.x - 1.0 uv.x = 2.0 * uv.x - 1.0
uv.y = 2.0 * uv.y - 1.0 uv.y = 2.0 * uv.y - 1.0
@ -41,6 +61,13 @@ static func shape_star(uv : Vector2, sides : float, size : float, edge : float)
return clamp((size - cos(floor(1.5 + angle / slice - 2.0 * Commons.step(0.5 * slice, Commons.modf(angle, slice))) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0); return clamp((size - cos(floor(1.5 + angle / slice - 2.0 * Commons.step(0.5 * slice, Commons.modf(angle, slice))) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0);
#float shape_curved_star(vec2 uv, float sides, float size, float edge) {
# uv = 2.0*uv-1.0;edge = max(edge, 1.0e-8);
# float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359);
# float slice = 6.28318530718/sides;
# return clamp((1.0-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv)/size)/edge, 0.0, 1.0);
#}
static func shape_curved_star(uv : Vector2, sides : float, size : float, edge : float) -> float: static func shape_curved_star(uv : Vector2, sides : float, size : float, edge : float) -> float:
uv.x = 2.0 * uv.x - 1.0 uv.x = 2.0 * uv.x - 1.0
uv.y = 2.0 * uv.y - 1.0 uv.y = 2.0 * uv.y - 1.0
@ -55,6 +82,11 @@ static func shape_curved_star(uv : Vector2, sides : float, size : float, edge :
return clamp((size - cos(floor(0.5 + 0.5 * angle / slice) * 2.0 * slice - angle) * uv.length())/(edge * size), 0.0, 1.0); return clamp((size - cos(floor(0.5 + 0.5 * angle / slice) * 2.0 * slice - angle) * uv.length())/(edge * size), 0.0, 1.0);
#float shape_rays(vec2 uv, float sides, float size, float edge) {
# uv = 2.0*uv-1.0;edge = 0.5*max(edge, 1.0e-8)*size;float slice = 6.28318530718/sides;
# float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice;
# return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0);
#}
static func shape_rays(uv : Vector2, sides : float, size : float, edge : float) -> float: static func shape_rays(uv : Vector2, sides : float, size : float, edge : float) -> float: