Added kaleidoscope scene

This commit is contained in:
Otto 2024-10-02 16:08:45 +03:00
parent 496b205573
commit 32a517ec22
9 changed files with 310 additions and 83 deletions

View file

@ -1,16 +0,0 @@
shader_type spatial;
render_mode unshaded;
instance uniform int id;
void vertex() {
// Called for every vertex the material is visible on.
}
void fragment() {
ALBEDO = vec3(cos(TIME + float(id) * 0.01), sin(TIME + float(id) * 0.01), tan(TIME + float(id) * 0.01));
}
void light() {
DIFFUSE_LIGHT = vec3(1.0, 1.0, 1.0);
}

View file

@ -0,0 +1,57 @@
shader_type canvas_item;
group_uniforms segments;
uniform float segments: hint_range(2.0, 48.0, 1.0) = 6.0;
uniform bool segmentReflect = true;
group_uniforms;
group_uniforms polar;
uniform vec2 polarOffset = vec2(0.5, 0.5);
uniform float polarAngle: hint_range(0.0, 360.0) = 0.0;
group_uniforms;
group_uniforms source;
uniform vec2 sourceOffset = vec2(0.5, 0.5);
uniform float sourceScale = 2.0;
uniform float sourceAngle: hint_range(0.0, 360.0) = 0.0;
group_uniforms;
vec2 simpleRotate(vec2 uv, float rotation) {
return vec2(
cos(rotation) * uv.x + sin(rotation) * uv.y,
cos(rotation) * uv.y - sin(rotation) * uv.x
);
}
vec2 kaleid(vec2 uv, float addAngle, vec2 origin, float segCount, bool doReflect) {
uv -= origin;
float radius = sqrt(dot(uv, uv));
float angle = atan(uv.y, uv.x) + addAngle;
float segmentAngle = TAU / segCount;
angle -= segmentAngle * floor(angle / segmentAngle);
if (doReflect) {
angle = min(angle, segmentAngle - angle);
}
return vec2(cos(angle), sin(angle)) * radius;
}
void fragment() {
vec2 newUV = kaleid(UV, radians(polarAngle), polarOffset, segments, segmentReflect);
newUV = simpleRotate(newUV, radians(sourceAngle));
newUV += sourceOffset;
newUV *= sourceScale;
vec4 finalColor = texture(TEXTURE, fract(newUV * sourceScale - sourceOffset));
COLOR = finalColor;
}

154
entities/kaleido_scope.tscn Normal file
View file

@ -0,0 +1,154 @@
[gd_scene load_steps=9 format=3 uid="uid://b761uk7sjprrp"]
[ext_resource type="Shader" path="res://assets/shaders/kaleidoscope.gdshader" id="1_nwvg1"]
[ext_resource type="PackedScene" uid="uid://qehbjfkqs5pl" path="res://entities/ParticlesCool.tscn" id="1_yc1r8"]
[sub_resource type="GDScript" id="GDScript_mtsk5"]
script/source = "extends Control
func _on_timer_timeout() -> void:
$AnimationPlayer.play(\"kaleidoskope_1\");
"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_a6cuy"]
shader = ExtResource("1_nwvg1")
shader_parameter/segments = 6.0
shader_parameter/segmentReflect = true
shader_parameter/polarOffset = Vector2(0.5, 0.5)
shader_parameter/polarAngle = 0.0
shader_parameter/sourceOffset = Vector2(0.5, 0.5)
shader_parameter/sourceScale = 2.0
shader_parameter/sourceAngle = 0.0
[sub_resource type="ViewportTexture" id="ViewportTexture_1y4ry"]
viewport_path = NodePath("SubViewport")
[sub_resource type="Animation" id="Animation_olvxy"]
resource_name = "kaleidoskope_1"
length = 20.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("TextureRect:material:shader_parameter/segments")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.0333334, 1.06667, 2.1, 3.06667, 4.06667, 5.06667, 6.03333, 7.1, 8.13333, 9.1),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [4.0, 6.0, 8.0, 10.0, 12.0, 8.0, 4.0, 6.0, 8.0, 6.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("TextureRect:material:shader_parameter/sourceAngle")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 1.03333),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0.0, 0.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("TextureRect:material:shader_parameter/sourceOffset")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.0333333, 9.1, 11.5333, 15.0667),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Vector2(0.5, 0.5), Vector2(0.5, 0.5), Vector2(0.5, 0), Vector2(1, -1)]
}
[sub_resource type="Animation" id="Animation_1yxhh"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("TextureRect:material:shader_parameter/segments")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [6.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("TextureRect:material:shader_parameter/sourceAngle")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("TextureRect:material:shader_parameter/sourceOffset")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0.5, 0.5)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_4qo5x"]
_data = {
"RESET": SubResource("Animation_1yxhh"),
"kaleidoskope_1": SubResource("Animation_olvxy")
}
[node name="KaleidoScope" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = SubResource("GDScript_mtsk5")
[node name="TextureRect" type="TextureRect" parent="."]
material = SubResource("ShaderMaterial_a6cuy")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("ViewportTexture_1y4ry")
[node name="SubViewport" type="SubViewport" parent="."]
size = Vector2i(1152, 648)
[node name="Camera3D" type="Camera3D" parent="SubViewport"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.31619)
[node name="Node3D" parent="SubViewport" instance=ExtResource("1_yc1r8")]
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.910979, 0.412453, 0, -0.412453, 0.910979, 0, 0, 0)
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_4qo5x")
}
[node name="Timer" type="Timer" parent="."]
wait_time = 2.0
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View file

@ -4,7 +4,7 @@
[sub_resource type="Animation" id="Animation_qy15n"] [sub_resource type="Animation" id="Animation_qy15n"]
resource_name = "timeline" resource_name = "timeline"
length = 20.0 length = 60.0
tracks/0/type = "method" tracks/0/type = "method"
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
@ -12,7 +12,7 @@ tracks/0/path = NodePath(".")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 10, 20), "times": PackedFloat32Array(0, 10, 60.0333),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1, 1, 1),
"values": [{ "values": [{
"args": [0], "args": [0],

View file

@ -1,48 +0,0 @@
[gd_scene load_steps=8 format=3 uid="uid://lcp4gqi6nigy"]
[ext_resource type="Script" path="res://scripts/shape_dance.gd" id="1_g2fd3"]
[ext_resource type="Shader" path="res://assets/shaders/ShapeDanceShapes.gdshader" id="2_jw15c"]
[sub_resource type="Curve3D" id="Curve3D_kx25u"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, -6.635, 0, 14.74, 0, 0, 0, 60, 0, 1.8),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2
[sub_resource type="ShaderMaterial" id="ShaderMaterial_r1n2u"]
render_priority = 0
shader = ExtResource("2_jw15c")
[sub_resource type="BoxMesh" id="BoxMesh_ysqih"]
material = SubResource("ShaderMaterial_r1n2u")
[sub_resource type="Sky" id="Sky_ux7r0"]
[sub_resource type="Environment" id="Environment_1wa4s"]
background_mode = 2
sky = SubResource("Sky_ux7r0")
[node name="ShapeDance" type="Node3D"]
script = ExtResource("1_g2fd3")
amount = 20
offset = 2.8
shape_shader = ExtResource("2_jw15c")
[node name="Path" type="Path3D" parent="."]
curve = SubResource("Curve3D_kx25u")
[node name="PathFollow3D" type="PathFollow3D" parent="Path"]
transform = Transform3D(-0.0299847, 0, -0.999484, 0, 0.999932, 0, 0.999487, 0, -0.0299846, 0, 0, 0)
[node name="MeshInstance3D" type="MeshInstance3D" parent="Path/PathFollow3D"]
mesh = SubResource("BoxMesh_ysqih")
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(0.394721, 0.132523, -0.909194, -0.0542735, 0.991179, 0.120911, 0.917197, 0.00161915, 0.398431, -0.411877, 1.41195, 2.2298)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_1wa4s")
[node name="ShowLight" type="DirectionalLight3D" parent="."]
visible = false

View file

@ -1,15 +1,16 @@
[gd_scene load_steps=4 format=3 uid="uid://dfvl3luba7j4"] [gd_scene load_steps=8 format=3 uid="uid://dfvl3luba7j4"]
[ext_resource type="Texture2D" uid="uid://5hxbsfm0aa0" path="res://icon.svg" id="1_3phrh"] [ext_resource type="Texture2D" uid="uid://5hxbsfm0aa0" path="res://icon.svg" id="1_3phrh"]
[sub_resource type="GDScript" id="GDScript_axp0a"] [sub_resource type="GDScript" id="GDScript_axp0a"]
resource_name = "Test" resource_name = "Test"
script/source = "extends Node2D script/source = "extends Control
func _ready() -> void: func _ready() -> void:
$ScramblingText.infinite = true $ScramblingText.infinite = true
$ScramblingText.start() $ScramblingText.start()
$AnimationPlayer.play(\"blink\");
func _on_timer_timeout() -> void: func _on_timer_timeout() -> void:
@ -19,23 +20,94 @@ func _on_timer_timeout() -> void:
[sub_resource type="LabelSettings" id="LabelSettings_w3bnc"] [sub_resource type="LabelSettings" id="LabelSettings_w3bnc"]
font_size = 48 font_size = 48
[node name="Test" type="Node2D"] [sub_resource type="LabelSettings" id="LabelSettings_78g6a"]
font_size = 48
[sub_resource type="Animation" id="Animation_t3ulj"]
resource_name = "blink"
length = 2.0
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Label:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [false, true]
}
[sub_resource type="Animation" id="Animation_dirfa"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Label:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_jgx00"]
_data = {
"RESET": SubResource("Animation_dirfa"),
"blink": SubResource("Animation_t3ulj")
}
[node name="Test" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = SubResource("GDScript_axp0a") script = SubResource("GDScript_axp0a")
[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 1)
[node name="Icon" type="Sprite2D" parent="."] [node name="Icon" type="Sprite2D" parent="."]
position = Vector2(534, 309) position = Vector2(534, 309)
texture = ExtResource("1_3phrh") texture = ExtResource("1_3phrh")
[node name="ScramblingText" type="ScramblingText" parent="."] [node name="ScramblingText" type="ScramblingText" parent="."]
speed = 5.0
duration = 0.05
infinite = false infinite = false
offset_right = 40.0 offset_right = 40.0
offset_bottom = 23.0 offset_bottom = 23.0
text = "HELLO WORLD" text = "LOADING DEMO..."
label_settings = SubResource("LabelSettings_w3bnc") label_settings = SubResource("LabelSettings_w3bnc")
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
wait_time = 3.0 wait_time = 1.5
one_shot = true one_shot = true
autostart = true autostart = true
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_top = 93.0
offset_right = 40.0
offset_bottom = 116.0
text = "PLEASE WAIT"
label_settings = SubResource("LabelSettings_78g6a")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_jgx00")
}
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View file

@ -3,25 +3,26 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://5hxbsfm0aa0" uid="uid://5hxbsfm0aa0"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" path.s3tc="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"
metadata={ metadata={
"vram_texture": false "imported_formats": ["s3tc_bptc"],
"vram_texture": true
} }
[deps] [deps]
source_file="res://icon.svg" source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"]
[params] [params]
compress/mode=0 compress/mode=2
compress/high_quality=false compress/high_quality=false
compress/lossy_quality=0.7 compress/lossy_quality=0.7
compress/hdr_compression=1 compress/hdr_compression=1
compress/normal_map=0 compress/normal_map=0
compress/channel_pack=0 compress/channel_pack=0
mipmaps/generate=false mipmaps/generate=true
mipmaps/limit=-1 mipmaps/limit=-1
roughness/mode=0 roughness/mode=0
roughness/src_normal="" roughness/src_normal=""
@ -31,7 +32,7 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=0
svg/scale=1.0 svg/scale=1.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View file

@ -1,9 +1,10 @@
extends Manager extends Manager
var scene1: PackedScene = preload("res://entities/test.tscn"); var scene1: PackedScene = preload("res://entities/test.tscn");
var scene2: PackedScene = preload("res://entities/shape_dance.tscn"); var scene2: PackedScene = preload("res://entities/kaleido_scope.tscn");
var scene3: PackedScene = preload("res://entities/ParticlesCool.tscn"); var scene3: PackedScene = preload("res://entities/ParticlesCool.tscn");
var scene4: PackedScene = preload("res://entities/test.tscn") var scene4: PackedScene = preload("res://entities/test.tscn")
var scene5: PackedScene = preload("res://entities/shape_dance.tscn");
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
@ -12,5 +13,6 @@ func _ready() -> void:
register_scene(scene2); register_scene(scene2);
register_scene(scene3); register_scene(scene3);
register_scene(scene4); register_scene(scene4);
register_scene(scene5);
start_audio(); start_audio();
$AnimationPlayer.play("timeline"); $AnimationPlayer.play("timeline");

View file

@ -4,8 +4,11 @@ extends Node3D
@export var offset: float = 2.0; @export var offset: float = 2.0;
@export var shape_shader: Shader; @export var shape_shader: Shader;
var nodes: Array[PathFollow3D];
@onready var path: Path3D = $Path @onready var path: Path3D = $Path
@onready var shape_material: ShaderMaterial = ShaderMaterial.new(); @onready var shape_material: ShaderMaterial = ShaderMaterial.new();
@onready var shapes: Array[PrimitiveMesh] = [BoxMesh.new(), PrismMesh.new(), TorusMesh.new(), CylinderMesh.new()];
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
@ -13,20 +16,22 @@ func _ready() -> void:
shape_material.set_shader(shape_shader); shape_material.set_shader(shape_shader);
var path_length: float = (path as Path3D).get_curve().get_baked_length(); var path_length: float = (path as Path3D).get_curve().get_baked_length();
for i in range(amount): for i in range(amount):
var instance: PathFollow3D = PathFollow3D.new(); var instance: PathFollow3D = PathFollow3D.new();
var mesh_instance: MeshInstance3D = MeshInstance3D.new(); var mesh_instance: MeshInstance3D = MeshInstance3D.new();
mesh_instance.mesh = BoxMesh.new(); mesh_instance.mesh = shapes.pick_random();
mesh_instance.set_surface_override_material(0, shape_material); mesh_instance.set_surface_override_material(0, shape_material);
mesh_instance.set_instance_shader_parameter("id", i); mesh_instance.set_instance_shader_parameter("id", i);
print("kaka" + str((mesh_instance.get_surface_override_material(0) as Material).get_shader_parameter("id")))
instance.add_child(mesh_instance); instance.add_child(mesh_instance);
path.add_child(instance); path.add_child(instance);
instance.set_progress_ratio(offset / 100 * i); instance.set_progress_ratio(offset / 100 * i);
#print(instance.progress_ratio);
nodes.push_back(instance);
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
pass for i in nodes.size():
nodes[i].rotate(Vector3(1.0, 0.0, 0.0), 10 * delta);