Added star shape in Shape generator

This commit is contained in:
RodZill4 2018-09-20 08:32:30 +02:00
parent d9b98693da
commit e2e1a67b7e
3 changed files with 14 additions and 6 deletions

View File

@ -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;

View File

@ -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 ])

View File

@ -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"]