This commit is contained in:
Luca 2025-01-02 10:46:25 +01:00
parent 2219e943da
commit c4115b3569
40 changed files with 2035 additions and 19 deletions

View file

@ -0,0 +1,30 @@
shader_type spatial;
render_mode cull_disabled;
vec4 polygon(vec2 uv, float width, int sides)
{
// UV goes from [0 , 1], we multiply by two ( [0, 2] ) and subtract one [ -1, 1]
// So the range is centered
uv = uv * 2.0 - 1.0;
// Get the angle from the point to the center, starting with 0 at the middle left side
float angle = atan(uv.x, uv.y);
float radius = TAU / float(sides);
float dist = cos(floor(0.5 + angle / radius) * radius - angle) * length(uv);
float poly = step(width, dist);
return vec4(vec3(poly), 1.0);
}
void fragment() {
// Multiply [0, 1] range of sine to [0, 7]
float side_value = 7.0 * sin(TIME);
// shift the value to half = [3, 10]
side_value = side_value + 3.0;
ALBEDO = vec3(polygon(UV, 0.3, clamp(int(side_value), 3, 9)).rgb);
}

View file

@ -0,0 +1,15 @@
[gd_scene load_steps=4 format=3 uid="uid://2o8nbxn0x7of"]
[ext_resource type="Shader" path="res://shaders/012_polygon/polygon.gdshader" id="1_cwvsg"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4pm8x"]
render_priority = 0
shader = ExtResource("1_cwvsg")
[sub_resource type="QuadMesh" id="QuadMesh_87u1q"]
material = SubResource("ShaderMaterial_4pm8x")
[node name="Polygon" type="Node3D"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("QuadMesh_87u1q")