diff --git a/addons/compute_shader_studio/compute_shader_studio_2d.gd b/addons/compute_shader_studio/compute_shader_studio_2d.gd index f947c2f..0995189 100644 --- a/addons/compute_shader_studio/compute_shader_studio_2d.gd +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd @@ -333,3 +333,11 @@ func screen_to_data0(pos : Vector2): return pos; else: return Vector2(0,0) + + +func _on_button_pressed() -> void: + $ComputeShaderStudio2D2.pause = !$ComputeShaderStudio2D2.pause + if $ComputeShaderStudio2D2.pause: + $Button.text = "Play" + else: + $Button.text = "Pause" # Replace with function body. diff --git a/addons/compute_shader_studio/compute_shader_studio_2d.gd.uid b/addons/compute_shader_studio/compute_shader_studio_2d.gd.uid new file mode 100644 index 0000000..69d40f3 --- /dev/null +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd.uid @@ -0,0 +1 @@ +uid://ymdghjh2i2lw diff --git a/addons/compute_shader_studio/compute_shader_studio_plugin.gd.uid b/addons/compute_shader_studio/compute_shader_studio_plugin.gd.uid new file mode 100644 index 0000000..07637d4 --- /dev/null +++ b/addons/compute_shader_studio/compute_shader_studio_plugin.gd.uid @@ -0,0 +1 @@ +uid://bnu0bag13mvgw diff --git a/examples/LabelStepPass.gd.uid b/examples/LabelStepPass.gd.uid new file mode 100644 index 0000000..dc81845 --- /dev/null +++ b/examples/LabelStepPass.gd.uid @@ -0,0 +1 @@ +uid://dxa1wiefqey1t diff --git a/examples/boxes/fichier.cpp b/examples/boxes/fichier.cpp new file mode 100644 index 0000000..433b170 --- /dev/null +++ b/examples/boxes/fichier.cpp @@ -0,0 +1,103 @@ +// Adapte de https://www.shadertoy.com/view/wc2XRh +// Version optimisee pour la bibliotheque Compute Shader Studio dans Godot. +#define POINTCOUNT 8 +#define PI 3.14159 +#define iResolution vec2(float(WSX), float(WSY)) +#define inBox(low, high, point) (low.x <= point.x && low.y <= point.y && high.x > point.x && high.y > point.y) +#define toUv(point) (2.0 * (point - 0.5 * iResolution) / iResolution.y) + +void main() +{ + // Recuperer les coordonnees du pixel + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + // Calculer l'indice lineaire dans data_0 + uint p = x + y * WSX; + + // Convertir les coordonnees du pixel en coordonnees uv + vec2 fragCoord = vec2(x, y); + vec2 uv = toUv(fragCoord); + // Determiner les bornes inferieure et superieure de la cellule + vec2 low = floor(uv); + vec2 high = ceil(uv); + // Restriction de uv dans la cellule + uv = mod(uv, vec2(1.0)); + + // Calculer le temps a partir de la variable step + float t = float(step) * 0.005; + + // Creer un tableau de POINTCOUNT points + vec2 points[POINTCOUNT]; + for (int i = 0; i < POINTCOUNT; i++) + { + float fi = float(i); + points[i] = vec2( + (1.75 - 0.125 * fi) * cos(1.333 * t - (1.0 - 0.2 * t) * fi / PI), + (1.0 - 0.1 * fi) * sin((fi + 1.0) * t + PI * 0.5) + ); + } + + // Boucle de subdivision pour determiner le niveau de subdivision + int iters = 0; + while (iters < 8) + { + iters++; + bool sub = false; + // Verifier si un point se trouve dans la cellule + for (int i = 0; i < POINTCOUNT; i++) + { + if (inBox(low, high, points[i])) + { + sub = true; + break; + } + } + if (sub) + { + // Calculer le centre de la cellule + vec2 center = (high + low) * 0.5; + // Subdivision horizontale + if (uv.x > 0.5) + { + low.x = center.x; + uv.x = uv.x * 2.0 - 1.0; + } + else + { + high.x = center.x; + uv.x *= 2.0; + } + // Subdivision verticale + if (uv.y > 0.5) + { + low.y = center.y; + uv.y = uv.y * 2.0 - 1.0; + } + else + { + high.y = center.y; + uv.y *= 2.0; + } + } + else + { + break; + } + } + + // Calculer une mesure "m" de la distance par rapport au centre de la cellule + float m = max(abs(uv.x - 0.5), abs(uv.y - 0.5)) * 2.0; + // "s" est une valeur lisse en fonction du nombre d'iterations + float s = smoothstep(1.0 - 0.01 * pow(2.0, float(iters)), 1.0, m); + // Creer une couleur en niveaux de gris + vec3 col = vec3(s); + + // Conversion de la couleur en valeurs entieres (0 a 255) + int a = 255; + int r = int(clamp(col.r, 0.0, 1.0) * 255.0); + int g = int(clamp(col.g, 0.0, 1.0) * 255.0); + int b = int(clamp(col.b, 0.0, 1.0) * 255.0); + + // Stocker la couleur dans data_0 en format ARGB + data_0[p] = (a << 24) | (r << 16) | (g << 8) | b; +} \ No newline at end of file diff --git a/examples/boxes/fichier.gd b/examples/boxes/fichier.gd new file mode 100644 index 0000000..0f6cfc8 --- /dev/null +++ b/examples/boxes/fichier.gd @@ -0,0 +1,19 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_button_pressed() -> void: + $ComputeShaderStudio2D2.pause = !$ComputeShaderStudio2D2.pause + if $ComputeShaderStudio2D2.pause: + $Button.text = "Play" + else: + $Button.text = "Pause" # Replace with function body. diff --git a/examples/boxes/fichier.gd.uid b/examples/boxes/fichier.gd.uid new file mode 100644 index 0000000..569281b --- /dev/null +++ b/examples/boxes/fichier.gd.uid @@ -0,0 +1 @@ +uid://2wy07yux7xmu diff --git a/examples/boxes/fichier.tscn b/examples/boxes/fichier.tscn new file mode 100644 index 0000000..4711ba7 --- /dev/null +++ b/examples/boxes/fichier.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=6 format=3 uid="uid://cets11mlsd8hb"] + +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_cogap"] +[ext_resource type="Script" path="res://examples/boxes/fichier.gd" id="1_y3tek"] + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_pm7bb"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_nxi5j"] +width = 256 +height = 128 +noise = SubResource("FastNoiseLite_pm7bb") + +[sub_resource type="Theme" id="Theme_xvegm"] + +[node name="CompShadStudioEx5" type="Node2D"] +script = ExtResource("1_y3tek") + +[node name="ComputeShaderStudio2D2" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_cogap") +pause = true +WSX = 1152 +WSY = 648 +glsl_file = "res://examples/boxes/fichier.cpp" +data = [NodePath("../TextureRect")] + +[node name="TextureRect" type="TextureRect" parent="."] +offset_left = -5.0 +offset_top = -2.0 +offset_right = 573.0 +offset_bottom = 369.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +texture = SubResource("NoiseTexture2D_nxi5j") + +[node name="Button" type="Button" parent="."] +offset_left = 2.0 +offset_top = 8.0 +offset_right = 76.0 +offset_bottom = 41.0 +theme = SubResource("Theme_xvegm") +text = "Jouer" + +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] diff --git a/examples/cells/cells.gd.uid b/examples/cells/cells.gd.uid new file mode 100644 index 0000000..af46620 --- /dev/null +++ b/examples/cells/cells.gd.uid @@ -0,0 +1 @@ +uid://dxrckgtq1eqrv diff --git a/examples/example_mandelbrot.gd.uid b/examples/example_mandelbrot.gd.uid new file mode 100644 index 0000000..5c28a37 --- /dev/null +++ b/examples/example_mandelbrot.gd.uid @@ -0,0 +1 @@ +uid://jvjmvstxk5po diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..3bef2e6 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://773pfp1ieglx" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/screenshots/initial.png b/screenshots/initial.png new file mode 100644 index 0000000..1ea7b7b Binary files /dev/null and b/screenshots/initial.png differ diff --git a/screenshots/v2.png b/screenshots/v2.png new file mode 100644 index 0000000..a2428a4 Binary files /dev/null and b/screenshots/v2.png differ