Add exponent to all gradients, cleanup

This commit is contained in:
Abe Pazos
2020-04-07 19:03:35 +02:00
parent 5d3eadd156
commit fa51fad405
4 changed files with 105 additions and 50 deletions

View File

@@ -12,8 +12,8 @@ class LinearGradient(
color0: ColorRGBa,
color1: ColorRGBa,
offset: Vector2,
rotation: Double,
exponent: Double) : ShadeStyle() {
rotation: Double = 0.0,
exponent: Double = 1.0) : ShadeStyle() {
@ColorParameter("start color", order = 0)
var color0: ColorRGBa by Parameter()
@@ -33,11 +33,13 @@ class LinearGradient(
this.exponent = exponent
fragmentTransform = """
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset);
vec2 coord = (c_boundsPosition.xy - 0.5 + p_offset);
float cr = cos(radians(p_rotation));
float sr = sin(radians(p_rotation));
mat2 rm = mat2(cr, -sr, sr, cr);
float f = clamp((rm * coord).y + 0.5, 0.0, 1.0);
vec2 rc = rm * coord;
float f = clamp(rc.y + 0.5, 0.0, 1.0);
vec4 color0 = p_color0;
color0.rgb *= color0.a;
@@ -57,9 +59,12 @@ class LinearGradient(
}
}
fun linearGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 =
Vector2.ZERO, rotation: Double = 0.0, exponent: Double = 1.0) =
LinearGradient(color0, color1, offset, rotation, exponent)
fun linearGradient(
color0: ColorRGBa,
color1: ColorRGBa,
offset: Vector2 = Vector2.ZERO,
rotation: Double = 0.0,
exponent: Double = 1.0
) : ShadeStyle {
return LinearGradient(color0, color1, offset, rotation, exponent)
}