From e2e1a67b7e4cb759376583c8c04177ca8488e634 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Thu, 20 Sep 2018 08:32:30 +0200 Subject: [PATCH] Added star shape in Shape generator --- addons/material_maker/common.shader | 10 +++++++++- addons/material_maker/nodes/shape.gd | 2 +- addons/material_maker/nodes/shape.tscn | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/material_maker/common.shader b/addons/material_maker/common.shader index be75386..37e008b 100644 --- a/addons/material_maker/common.shader +++ b/addons/material_maker/common.shader @@ -15,8 +15,9 @@ vec3 rand3(vec2 x) { float circle(vec2 uv, float sides, float radius, float edge) { uv = 2.0*uv-1.0; + edge = max(edge, 1.0e-8); float distance = length(uv); - return clamp(1.0-distance/(edge*radius), 0.0, 1.0); + return clamp((1.0-distance/radius)/edge, 0.0, 1.0); } float polygon(vec2 uv, float sides, float radius, float edge) { @@ -27,6 +28,13 @@ float polygon(vec2 uv, float sides, float radius, float edge) { } float star(vec2 uv, float sides, float radius, float edge) { + uv = 2.0*uv-1.0; + float angle = atan(uv.x, uv.y); + float slice = 6.28318530718/sides; + return clamp((radius-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*radius), 0.0, 1.0); +} + +float curved_star(vec2 uv, float sides, float radius, float edge) { uv = 2.0*uv-1.0; float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359); float slice = 6.28318530718/sides; diff --git a/addons/material_maker/nodes/shape.gd b/addons/material_maker/nodes/shape.gd index 2938a10..8350f47 100644 --- a/addons/material_maker/nodes/shape.gd +++ b/addons/material_maker/nodes/shape.gd @@ -6,7 +6,7 @@ var sides var radius var edge -const SHAPES = [ "circle", "polygon", "star" ] +const SHAPES = [ "circle", "polygon", "star", "curved_star" ] func _ready(): initialize_properties([ $shape, $sides, $radius, $edge ]) diff --git a/addons/material_maker/nodes/shape.tscn b/addons/material_maker/nodes/shape.tscn index 623eeb9..75f202b 100644 --- a/addons/material_maker/nodes/shape.tscn +++ b/addons/material_maker/nodes/shape.tscn @@ -12,9 +12,9 @@ anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 1.0 -margin_top = 4.0 -margin_right = 98.0 -margin_bottom = 53.0 +margin_top = 1.0 +margin_right = 108.0 +margin_bottom = 101.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 @@ -81,7 +81,7 @@ group = null text = "Circle" flat = false align = 0 -items = [ "Circle", null, false, 0, null, "Polygon", null, false, 1, null, "Star", null, false, -1, null ] +items = [ "Circle", null, false, 0, null, "Polygon", null, false, 1, null, "Star", null, false, 2, null, "Curved star", null, false, 3, null ] selected = 0 [node name="sides" type="HSlider" parent="." index="1"]