From ea5ed2016f6c74fdffb37a690c4b5112b5644176 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:34:56 +0100 Subject: [PATCH 01/17] modif 2 --- examples/LabelStepPass.gd.uid | 1 + examples/cells/cells.gd.uid | 1 + examples/cells/example_cells.tscn | 3 +- examples/example_1.tscn | 2 +- examples/example_2.tscn | 2 +- examples/example_3.tscn | 4 +- examples/example_4.tscn | 2 +- examples/example_5.tscn | 2 +- examples/example_lenia_test.tscn | 4 +- examples/example_mandelbrot.gd.uid | 1 + examples/example_mandelbrot.tscn | 4 +- examples/example_psycho_seizure.tscn | 2 +- examples/projet/ShaderQuad.gd | 23 +++ examples/projet/ShaderQuad.gd.uid | 1 + examples/projet/node_2d.tscn | 12 ++ examples/test/test.cpp | 237 +++++++++++++++++++++++++++ examples/test/test.glsl.import | 14 ++ examples/test/test.tscn | 20 +++ 18 files changed, 323 insertions(+), 12 deletions(-) create mode 100644 examples/LabelStepPass.gd.uid create mode 100644 examples/cells/cells.gd.uid create mode 100644 examples/example_mandelbrot.gd.uid create mode 100644 examples/projet/ShaderQuad.gd create mode 100644 examples/projet/ShaderQuad.gd.uid create mode 100644 examples/projet/node_2d.tscn create mode 100644 examples/test/test.cpp create mode 100644 examples/test/test.glsl.import create mode 100644 examples/test/test.tscn diff --git a/examples/LabelStepPass.gd.uid b/examples/LabelStepPass.gd.uid new file mode 100644 index 0000000..838d418 --- /dev/null +++ b/examples/LabelStepPass.gd.uid @@ -0,0 +1 @@ +uid://q8wumduymhf6 diff --git a/examples/cells/cells.gd.uid b/examples/cells/cells.gd.uid new file mode 100644 index 0000000..5e5fc21 --- /dev/null +++ b/examples/cells/cells.gd.uid @@ -0,0 +1 @@ +uid://ce667yq7yolmp diff --git a/examples/cells/example_cells.tscn b/examples/cells/example_cells.tscn index 6959c31..c6eb547 100644 --- a/examples/cells/example_cells.tscn +++ b/examples/cells/example_cells.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://cutxgtalwsp6q"] -[ext_resource type="Script" path="res://examples/cells/cells.gd" id="1_dw4h8"] +[ext_resource type="Script" uid="uid://ce667yq7yolmp" path="res://examples/cells/cells.gd" id="1_dw4h8"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_oji6h"] [node name="Cells" type="Control" node_paths=PackedStringArray("data")] @@ -31,6 +31,7 @@ grow_vertical = 2 [node name="Display" type="Sprite2D" parent="CenterAnchor"] texture_filter = 1 +position = Vector2(-39, -32) scale = Vector2(4, 4) texture = ExtResource("2_oji6h") diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 7d67949..45fa374 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://ddr6qtwy1pesd"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_s3fct"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_dmk8h"] diff --git a/examples/example_2.tscn b/examples/example_2.tscn index 766e825..5921145 100644 --- a/examples/example_2.tscn +++ b/examples/example_2.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://cotswmubn7uvm"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_2cs40"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_2cs40"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_j6qu8"] [node name="Example2" type="Node2D"] diff --git a/examples/example_3.tscn b/examples/example_3.tscn index df2b8a6..f33d0a5 100644 --- a/examples/example_3.tscn +++ b/examples/example_3.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://cmucgsppcoo5e"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] -[ext_resource type="Script" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] +[ext_resource type="Script" uid="uid://q8wumduymhf6" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_4upxj"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/example_4.tscn b/examples/example_4.tscn index c777972..f5d35ef 100644 --- a/examples/example_4.tscn +++ b/examples/example_4.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://b2ip5eftk3aij"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_ke3fj"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_ke3fj"] [ext_resource type="Texture2D" uid="uid://2behgeplwycn" path="res://examples/grid_512x512.png" id="2_flqlh"] [node name="CompShadStudioEx4" type="Node2D"] diff --git a/examples/example_5.tscn b/examples/example_5.tscn index 43aa420..871bcc1 100644 --- a/examples/example_5.tscn +++ b/examples/example_5.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 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" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_cogap"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_pm7bb"] diff --git a/examples/example_lenia_test.tscn b/examples/example_lenia_test.tscn index 6c2caef..927b20b 100644 --- a/examples/example_lenia_test.tscn +++ b/examples/example_lenia_test.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://cljj33x767odp"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_wci4f"] -[ext_resource type="Script" path="res://examples/LabelStepPass.gd" id="2_ndkd3"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_wci4f"] +[ext_resource type="Script" uid="uid://q8wumduymhf6" path="res://examples/LabelStepPass.gd" id="2_ndkd3"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="3_orsvs"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/example_mandelbrot.gd.uid b/examples/example_mandelbrot.gd.uid new file mode 100644 index 0000000..b4d8dd4 --- /dev/null +++ b/examples/example_mandelbrot.gd.uid @@ -0,0 +1 @@ +uid://mj6p8vw40uoo diff --git a/examples/example_mandelbrot.tscn b/examples/example_mandelbrot.tscn index a5e532c..ab6c621 100644 --- a/examples/example_mandelbrot.tscn +++ b/examples/example_mandelbrot.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://d1hhshnvrt86e"] -[ext_resource type="Script" path="res://examples/example_mandelbrot.gd" id="1_5gp20"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_t5cx1"] +[ext_resource type="Script" uid="uid://mj6p8vw40uoo" path="res://examples/example_mandelbrot.gd" id="1_5gp20"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_t5cx1"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_dyrad"] [node name="example_mandelbrot" type="Node2D"] diff --git a/examples/example_psycho_seizure.tscn b/examples/example_psycho_seizure.tscn index f1e07d4..0ec1e82 100644 --- a/examples/example_psycho_seizure.tscn +++ b/examples/example_psycho_seizure.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://cdtqwwdxs783m"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_26wk6"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_26wk6"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_urrfs"] [node name="exeample_psycho_seizure" type="Node2D"] diff --git a/examples/projet/ShaderQuad.gd b/examples/projet/ShaderQuad.gd new file mode 100644 index 0000000..b416d28 --- /dev/null +++ b/examples/projet/ShaderQuad.gd @@ -0,0 +1,23 @@ +extends TextureRect + +@export var resolution: Vector2 = Vector2(640, 360) +var shader_material: ShaderMaterial +var time: float = 0.0 + +func _ready(): + # Crée et applique le matériel du shader + shader_material = ShaderMaterial.new() + shader_material.shader = preload("res://compute_shader.gdshader") + self.material = shader_material + self.stretch_mode = StretchMode.STRETCH_KEEP_ASPECT_CENTERED + + # Définir la taille du TextureRect à la résolution donnée + self.rect_size = resolution # Utilisez rect_size pour ajuster la taille du TextureRect + + # Définir les paramètres du shader au démarrage + self.material.set_shader_param("resolution", resolution) + +func _process(delta): + # Incrémente le temps à chaque frame + time += delta + self.material.set_shader_param("time", time) # Envoie le temps au shader diff --git a/examples/projet/ShaderQuad.gd.uid b/examples/projet/ShaderQuad.gd.uid new file mode 100644 index 0000000..ec74118 --- /dev/null +++ b/examples/projet/ShaderQuad.gd.uid @@ -0,0 +1 @@ +uid://cbg6f5ekjjg3t diff --git a/examples/projet/node_2d.tscn b/examples/projet/node_2d.tscn new file mode 100644 index 0000000..44b988d --- /dev/null +++ b/examples/projet/node_2d.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=3 uid="uid://83u4ieqetk01"] + +[ext_resource type="Script" uid="uid://c8nr7akmktfg8" path="res://node_2d.gd" id="1_0ilx8"] +[ext_resource type="Script" uid="uid://cbg6f5ekjjg3t" path="res://examples/projet/ShaderQuad.gd" id="2_h2mvu"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_0ilx8") + +[node name="ShaderQuad" type="TextureRect" parent="."] +offset_right = 40.0 +offset_bottom = 40.0 +script = ExtResource("2_h2mvu") diff --git a/examples/test/test.cpp b/examples/test/test.cpp new file mode 100644 index 0000000..890e132 --- /dev/null +++ b/examples/test/test.cpp @@ -0,0 +1,237 @@ +#version 450 + +// Workgroup size +layout(local_size_x = 16, local_size_y = 16) in; + +void main() +{ + // Get the current pixel coordinates + ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); + + // Input parameters (these are just placeholders) + vec2 resolution = vec2(800.0, 600.0); // Example resolution + float time = 1.0; // Example time (you can replace this with an actual uniform in your app) + + // Check if within bounds + if(pixelCoords.x >= int(resolution.x) || pixelCoords.y >= int(resolution.y)) { + return; + } + + // Normalized pixel coordinates (from 0 to 1) + vec2 fragCoord = vec2(pixelCoords); + vec2 uv = (fragCoord * 2.0 - resolution.xy) / resolution.y; + + // Time loop + float animTime = abs(8.0 - mod(time + 8.0, 16.0)); + + // Side lengths for demo + float edge_x = (0.6 + 0.4 * cos(time)) * smoothstep(1.0, 2.0, animTime); + float edge_y = (0.6 + 0.4 * sin(time)) * smoothstep(3.0, 4.0, animTime); + + // Hypotenuse edge + vec2 edge_h = vec2(edge_x, -edge_y) * smoothstep(5.0, 6.0, animTime); + + // Centered position coordinates + vec2 p = uv + 0.5 * vec2(edge_x, edge_y); + + // Distance to x-edge + float d = length(p - clamp(p, vec2(0.0), vec2(edge_x, 0))); + + // Distance to y-edge + d = min(d, length(p - clamp(p, vec2(0.0), vec2(0, edge_y)))); + + // Hypotenuse edge distance + p -= vec2(0, edge_y); + float h = clamp(dot(p, edge_h) / dot(edge_h, edge_h), 0.0, 1.0); + d = min(d, length(p - edge_h * h)); + + // Compute distance field sign + float ex = -p.x; + float ey = -edge_y - p.y; + float eh = edge_y * p.x + edge_x * p.y; + + // Use the sign of the greatest edge + float sig = sign(max(ex, max(ey, eh))); + sig = mix(1.0, sig, smoothstep(6.0, 7.0, animTime)); + + // Isolines + vec3 col = 0.95 + 0.05 * cos(d * 1e2 + vec3(0, 1, 2)); + col /= 1.0 + 20.0 * d * exp(sig * vec3(3, 0, -1)); + + // Output color (write to the image) + imageStore(image2D, pixelCoords, vec4(col, 1.0)); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// #define RADIUS 10 +// #define MAX_LENGTH 50 + + +// void main() +// { +// int x = int(gl_GlobalInvocationID.x); +// int y = int(gl_GlobalInvocationID.y); +// int p = x + y * int(WSX); +// int positions[MAX_LENGTH][2]; // Tableau pour stocker les positions du serpent + +// for (int i = 0; i < MAX_LENGTH; ++i) +// { +// positions[i][0] = 0; +// positions[i][1] = 0; +// } + +// // Initial background is black & opaque +// if (step == 0) +// { +// data_0[p] = 0xFF000000 + y; +// } +// else +// { +// // Déplacer le serpent en fonction de la souris +// for (int i = MAX_LENGTH - 1; i > 0; --i) +// { +// positions[i][0] = positions[i - 1][0]; +// positions[i][1] = positions[i - 1][1]; +// } + +// // Stocke la nouvelle position de la souris +// positions[0][0] = mousex; +// positions[0][1] = mousey; + +// // Dessiner chaque segment du serpent +// for (int i = 0; i < MAX_LENGTH; ++i) +// { +// float dx = float(positions[i][0] - x); +// float dy = float(positions[i][1] - y); +// float dist = sqrt(dx * dx + dy * dy); + +// // Dessiner un segment du serpent +// if (dist < RADIUS) +// { +// int col = 0xFF00FF00; // Vert pour le serpent +// data_0[p] = 0xFF000000 + col; +// } +// } +// } + +// step++; +// } + + + + + + + + + + + +// #define RADIUS 40 + +// void main() +// { +// int x = int(gl_GlobalInvocationID.x); +// int y = int(gl_GlobalInvocationID.y); +// int p = x + y * int(WSX); + +// // Initial background is black & opaque +// if (step == 0) +// { +// data_0[p] = 0xFF000000 + y; +// }else{ +// // Draw a fading red circle +// float dx = float(mousex - x); +// float dy = float(mousey - y); +// float dist = sqrt(dx * dx + dy * dy); + +// int pix = data_0[p]; +// int col = pix & 0x00FFFFFF; +// float r = RADIUS + 10 * sin(step / 10.0f); +// if (dist < r - 1) +// { +// col = col + 0x04; +// data_0[p] = 0xFF000000 + col; +// } + +// } +// } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// void main() { +// uint x = gl_GlobalInvocationID.x; +// uint y = gl_GlobalInvocationID.y; +// uint p = x + y * WSX; // Indexation en 1D d'une matrice 2D + +// int row = y % 2; // Alternance de lignes +// int col = x % 2; // Alternance de colonnes + +// data_0[p] = (row == col) ? 0xFFFFFF00 : 0xFF0000FF; // Motif damier +// data_1[p] = 0xFFFF0000 - int(x + y) * (step); +// } + + + +// void main() { +// uint x = gl_GlobalInvocationID.x; +// uint y = gl_GlobalInvocationID.y; +// uint p = x + y * WSX; +// data_0[p] = 0xFFFF0000 - int(x+y*1024)*(step); +// } + diff --git a/examples/test/test.glsl.import b/examples/test/test.glsl.import new file mode 100644 index 0000000..78429ff --- /dev/null +++ b/examples/test/test.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://c0c2dlutu4gln" +path="res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res" + +[deps] + +source_file="res://examples/test/test.glsl" +dest_files=["res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res"] + +[params] + diff --git a/examples/test/test.tscn b/examples/test/test.tscn new file mode 100644 index 0000000..4bb49ca --- /dev/null +++ b/examples/test/test.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://bhsg8ie7m0n18"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_tfywn"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_3uxvf"] + +[node name="Test" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(579, 337.5) +scale = Vector2(9.73438, 5.74219) +texture = ExtResource("1_tfywn") + +[node name="ComputeShaderStudio2D" type="Node" parent="Icon" node_paths=PackedStringArray("data")] +script = ExtResource("2_3uxvf") +WSX = 512 +WSY = 512 +glsl_file = "res://examples/test/test.cpp" +GLSL_code = "" +data = [NodePath("..")] +metadata/_custom_type_script = "uid://cleifuttwn5dw" From 2c0ef3c69187417d6a9102737cdf9e34ee1246de Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:45:30 +0100 Subject: [PATCH 02/17] code fonctionnel --- examples/projet/prj.cpp | 20 ++++++++++++++++++++ projet | 0 2 files changed, 20 insertions(+) create mode 100644 examples/projet/prj.cpp create mode 100644 projet diff --git a/examples/projet/prj.cpp b/examples/projet/prj.cpp new file mode 100644 index 0000000..e0b5d13 --- /dev/null +++ b/examples/projet/prj.cpp @@ -0,0 +1,20 @@ +extends Node2D + +@export var particle_count: int = 10000 +var particles: ImageTexture +var shader_material: ShaderMaterial + +func _ready(): + create_particles() + shader_material = ShaderMaterial.new() + shader_material.shader = preload("res://compute_shader.gdshader") + $Particles.material = shader_material + +func create_particles(): + var img = Image.create(particle_count, 1, false, Image.FORMAT_RGBAF) + img.lock() + for i in range(particle_count): + img.set_pixel(i, 0, Color(randf(), randf(), 0, 1)) + img.unlock() + particles = ImageTexture.create_from_image(img) + $Particles.texture = particles \ No newline at end of file diff --git a/projet b/projet new file mode 100644 index 0000000..e69de29 From acdc12f316fab591711a0beaa2bfd7620111fab2 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:54:02 +0100 Subject: [PATCH 03/17] Update test.cpp modification du code fonctionnel --- examples/test/test.cpp | 246 +++-------------------------------------- 1 file changed, 17 insertions(+), 229 deletions(-) diff --git a/examples/test/test.cpp b/examples/test/test.cpp index 890e132..1121646 100644 --- a/examples/test/test.cpp +++ b/examples/test/test.cpp @@ -1,237 +1,25 @@ -#version 450 - -// Workgroup size -layout(local_size_x = 16, local_size_y = 16) in; - -void main() -{ - // Get the current pixel coordinates - ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); - - // Input parameters (these are just placeholders) - vec2 resolution = vec2(800.0, 600.0); // Example resolution - float time = 1.0; // Example time (you can replace this with an actual uniform in your app) - - // Check if within bounds - if(pixelCoords.x >= int(resolution.x) || pixelCoords.y >= int(resolution.y)) { - return; - } - - // Normalized pixel coordinates (from 0 to 1) - vec2 fragCoord = vec2(pixelCoords); - vec2 uv = (fragCoord * 2.0 - resolution.xy) / resolution.y; - - // Time loop - float animTime = abs(8.0 - mod(time + 8.0, 16.0)); - - // Side lengths for demo - float edge_x = (0.6 + 0.4 * cos(time)) * smoothstep(1.0, 2.0, animTime); - float edge_y = (0.6 + 0.4 * sin(time)) * smoothstep(3.0, 4.0, animTime); +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; - // Hypotenuse edge - vec2 edge_h = vec2(edge_x, -edge_y) * smoothstep(5.0, 6.0, animTime); + vec2 uv = vec2(float(x) / float(WSX), float(y) / float(WSY)); + vec2 pos = uv - 0.5; + pos.x *= float(WSX) / float(WSY); - // Centered position coordinates - vec2 p = uv + 0.5 * vec2(edge_x, edge_y); + float z = float(step) * 0.01; + float l = length(pos); - // Distance to x-edge - float d = length(p - clamp(p, vec2(0.0), vec2(edge_x, 0))); + uv += pos / l * (sin(z) + 1.0) * abs(sin(l * 9.0 - z - z)); - // Distance to y-edge - d = min(d, length(p - clamp(p, vec2(0.0), vec2(0, edge_y)))); + // Adjusted colors for a more feminine palette + float r = 0.12 / length(mod(uv + 0.4, vec2(1.0)) - 0.5); // Soft pink + float g = 0.05 / length(mod(uv + 0.6, vec2(1.0)) - 0.5); // Light purple + float b = 0.10 / length(mod(uv + 0.8, vec2(1.0)) - 0.5); // Lavender - // Hypotenuse edge distance - p -= vec2(0, edge_y); - float h = clamp(dot(p, edge_h) / dot(edge_h, edge_h), 0.0, 1.0); - d = min(d, length(p - edge_h * h)); - - // Compute distance field sign - float ex = -p.x; - float ey = -edge_y - p.y; - float eh = edge_y * p.x + edge_x * p.y; - - // Use the sign of the greatest edge - float sig = sign(max(ex, max(ey, eh))); - sig = mix(1.0, sig, smoothstep(6.0, 7.0, animTime)); - - // Isolines - vec3 col = 0.95 + 0.05 * cos(d * 1e2 + vec3(0, 1, 2)); - col /= 1.0 + 20.0 * d * exp(sig * vec3(3, 0, -1)); - - // Output color (write to the image) - imageStore(image2D, pixelCoords, vec4(col, 1.0)); + int color = (int(r * 255.0) << 16) | (int(g * 255.0) << 8) | int(b * 255.0); + data_0[p] = 0xFF000000 | color; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// #define RADIUS 10 -// #define MAX_LENGTH 50 - - -// void main() -// { -// int x = int(gl_GlobalInvocationID.x); -// int y = int(gl_GlobalInvocationID.y); -// int p = x + y * int(WSX); -// int positions[MAX_LENGTH][2]; // Tableau pour stocker les positions du serpent - -// for (int i = 0; i < MAX_LENGTH; ++i) -// { -// positions[i][0] = 0; -// positions[i][1] = 0; -// } - -// // Initial background is black & opaque -// if (step == 0) -// { -// data_0[p] = 0xFF000000 + y; -// } -// else -// { -// // Déplacer le serpent en fonction de la souris -// for (int i = MAX_LENGTH - 1; i > 0; --i) -// { -// positions[i][0] = positions[i - 1][0]; -// positions[i][1] = positions[i - 1][1]; -// } - -// // Stocke la nouvelle position de la souris -// positions[0][0] = mousex; -// positions[0][1] = mousey; - -// // Dessiner chaque segment du serpent -// for (int i = 0; i < MAX_LENGTH; ++i) -// { -// float dx = float(positions[i][0] - x); -// float dy = float(positions[i][1] - y); -// float dist = sqrt(dx * dx + dy * dy); - -// // Dessiner un segment du serpent -// if (dist < RADIUS) -// { -// int col = 0xFF00FF00; // Vert pour le serpent -// data_0[p] = 0xFF000000 + col; -// } -// } -// } - -// step++; -// } - - - - - - - - - - - -// #define RADIUS 40 - -// void main() -// { -// int x = int(gl_GlobalInvocationID.x); -// int y = int(gl_GlobalInvocationID.y); -// int p = x + y * int(WSX); - -// // Initial background is black & opaque -// if (step == 0) -// { -// data_0[p] = 0xFF000000 + y; -// }else{ -// // Draw a fading red circle -// float dx = float(mousex - x); -// float dy = float(mousey - y); -// float dist = sqrt(dx * dx + dy * dy); - -// int pix = data_0[p]; -// int col = pix & 0x00FFFFFF; -// float r = RADIUS + 10 * sin(step / 10.0f); -// if (dist < r - 1) -// { -// col = col + 0x04; -// data_0[p] = 0xFF000000 + col; -// } - -// } -// } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// void main() { -// uint x = gl_GlobalInvocationID.x; -// uint y = gl_GlobalInvocationID.y; -// uint p = x + y * WSX; // Indexation en 1D d'une matrice 2D - -// int row = y % 2; // Alternance de lignes -// int col = x % 2; // Alternance de colonnes - -// data_0[p] = (row == col) ? 0xFFFFFF00 : 0xFF0000FF; // Motif damier -// data_1[p] = 0xFFFF0000 - int(x + y) * (step); -// } - - - -// void main() { -// uint x = gl_GlobalInvocationID.x; -// uint y = gl_GlobalInvocationID.y; -// uint p = x + y * WSX; -// data_0[p] = 0xFFFF0000 - int(x+y*1024)*(step); -// } - +/// comm test \ No newline at end of file From 926927f23243b7f5356a1d2c8dc26ecf544416ab Mon Sep 17 00:00:00 2001 From: Pascal Ballet Date: Tue, 26 Nov 2024 15:45:27 +0100 Subject: [PATCH 04/17] examples titles improved with instructions --- examples/example_1.tscn | 8 ++++---- examples/example_2.tscn | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 6777e95..7d67949 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -30,13 +30,13 @@ scale = Vector2(3.27344, 3.02344) texture = SubResource("NoiseTexture2D_7n3ni") [node name="Label" type="Label" parent="."] -offset_left = 395.0 +offset_left = 109.0 offset_top = 3.0 -offset_right = 626.0 +offset_right = 627.0 offset_bottom = 62.0 scale = Vector2(1.72, 1.72) -text = "Compute Shader Studio -Example 1" +text = "Compute Shader Studio - Example 1 +Select the node ComputeShader to write your GLSL code" horizontal_alignment = 1 vertical_alignment = 1 diff --git a/examples/example_2.tscn b/examples/example_2.tscn index 6d6c507..766e825 100644 --- a/examples/example_2.tscn +++ b/examples/example_2.tscn @@ -38,11 +38,12 @@ vertical_alignment = 1 [node name="Label2" type="Label" parent="."] offset_left = 29.0 -offset_top = 113.0 +offset_top = 76.0 offset_right = 336.0 -offset_bottom = 420.0 +offset_bottom = 405.0 scale = Vector2(1.72, 1.72) -text = "// Write your GLSL code HERE +text = "// Select the node ComputeShader +// to write your GLSL code void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; From b4bb41abe318d0a1ff02d67333f59da9c5dbf78b Mon Sep 17 00:00:00 2001 From: Tasnime66 Date: Sun, 16 Mar 2025 17:18:37 +0100 Subject: [PATCH 05/17] =?UTF-8?q?projet=20modifi=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/projet/test.cpp | 25 +++++++++++++++++++++++++ examples/projet/test.glsl.import | 14 ++++++++++++++ examples/projet/test.tscn | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 examples/projet/test.cpp create mode 100644 examples/projet/test.glsl.import create mode 100644 examples/projet/test.tscn diff --git a/examples/projet/test.cpp b/examples/projet/test.cpp new file mode 100644 index 0000000..1121646 --- /dev/null +++ b/examples/projet/test.cpp @@ -0,0 +1,25 @@ +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + vec2 uv = vec2(float(x) / float(WSX), float(y) / float(WSY)); + vec2 pos = uv - 0.5; + pos.x *= float(WSX) / float(WSY); + + float z = float(step) * 0.01; + float l = length(pos); + + uv += pos / l * (sin(z) + 1.0) * abs(sin(l * 9.0 - z - z)); + + // Adjusted colors for a more feminine palette + float r = 0.12 / length(mod(uv + 0.4, vec2(1.0)) - 0.5); // Soft pink + float g = 0.05 / length(mod(uv + 0.6, vec2(1.0)) - 0.5); // Light purple + float b = 0.10 / length(mod(uv + 0.8, vec2(1.0)) - 0.5); // Lavender + + int color = (int(r * 255.0) << 16) | (int(g * 255.0) << 8) | int(b * 255.0); + data_0[p] = 0xFF000000 | color; +} + + +/// comm test \ No newline at end of file diff --git a/examples/projet/test.glsl.import b/examples/projet/test.glsl.import new file mode 100644 index 0000000..78429ff --- /dev/null +++ b/examples/projet/test.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://c0c2dlutu4gln" +path="res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res" + +[deps] + +source_file="res://examples/test/test.glsl" +dest_files=["res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res"] + +[params] + diff --git a/examples/projet/test.tscn b/examples/projet/test.tscn new file mode 100644 index 0000000..4bb49ca --- /dev/null +++ b/examples/projet/test.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://bhsg8ie7m0n18"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_tfywn"] +[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_3uxvf"] + +[node name="Test" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(579, 337.5) +scale = Vector2(9.73438, 5.74219) +texture = ExtResource("1_tfywn") + +[node name="ComputeShaderStudio2D" type="Node" parent="Icon" node_paths=PackedStringArray("data")] +script = ExtResource("2_3uxvf") +WSX = 512 +WSY = 512 +glsl_file = "res://examples/test/test.cpp" +GLSL_code = "" +data = [NodePath("..")] +metadata/_custom_type_script = "uid://cleifuttwn5dw" From 84fba8ef0d71790b8271c4ee9ac192fc9472f007 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Mon, 17 Mar 2025 08:11:15 +0100 Subject: [PATCH 06/17] test radar --- examples/test/test.cpp | 395 ++++++++++++++++++----------------------- 1 file changed, 173 insertions(+), 222 deletions(-) diff --git a/examples/test/test.cpp b/examples/test/test.cpp index 890e132..4d063e1 100644 --- a/examples/test/test.cpp +++ b/examples/test/test.cpp @@ -1,237 +1,188 @@ -#version 450 +#define M_PI 3.14159265358979323846 -// Workgroup size -layout(local_size_x = 16, local_size_y = 16) in; +#define blue1 vec3(0.74, 0.95, 1.00) +#define blue2 vec3(0.87, 0.98, 1.00) +#define blue3 vec3(0.35, 0.76, 0.83) +#define blue4 vec3(0.953, 0.969, 0.89) +#define red vec3(1.00, 0.38, 0.227) -void main() -{ - // Get the current pixel coordinates - ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); - - // Input parameters (these are just placeholders) - vec2 resolution = vec2(800.0, 600.0); // Example resolution - float time = 1.0; // Example time (you can replace this with an actual uniform in your app) +#define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) +#define MOV(a, b, c, d, t) (vec2(a * cos(t) + b * cos(0.1 * (t)), c * sin(t) + d * cos(0.1 * (t)))) - // Check if within bounds - if(pixelCoords.x >= int(resolution.x) || pixelCoords.y >= int(resolution.y)) { - return; - } +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; - // Normalized pixel coordinates (from 0 to 1) - vec2 fragCoord = vec2(pixelCoords); - vec2 uv = (fragCoord * 2.0 - resolution.xy) / resolution.y; + // Normalized coordinates + vec2 uv = vec2(float(x), float(y)); + vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center - // Time loop - float animTime = abs(8.0 - mod(time + 8.0, 16.0)); - - // Side lengths for demo - float edge_x = (0.6 + 0.4 * cos(time)) * smoothstep(1.0, 2.0, animTime); - float edge_y = (0.6 + 0.4 * sin(time)) * smoothstep(3.0, 4.0, animTime); + // Scale factor to match the original effect size + float scale = min(float(WSX), float(WSY)) / 650.0; - // Hypotenuse edge - vec2 edge_h = vec2(edge_x, -edge_y) * smoothstep(5.0, 6.0, animTime); + // Time variable + float time = float(step) * 0.01; - // Centered position coordinates - vec2 p = uv + 0.5 * vec2(edge_x, edge_y); + // Start with a black background + vec3 finalColor = vec3(0.0); - // Distance to x-edge - float d = length(p - clamp(p, vec2(0.0), vec2(edge_x, 0))); + // ---- Begin radar element calculations ---- - // Distance to y-edge - d = min(d, length(p - clamp(p, vec2(0.0), vec2(0, edge_y)))); + // Moving scan line + { + float theta0 = 90.0 * time; + vec2 d = uv - c; + float r = length(d); + + if (r < 240.0 * scale) { + vec2 p = 240.0 * scale * vec2(cos(theta0 * M_PI / 180.0), -sin(theta0 * M_PI / 180.0)); + float l = length(d - p * clamp(dot(d, p) / dot(p, p), 0.0, 1.0)); + d = normalize(d); + float theta = mod(180.0 * atan(d.y, d.x) / M_PI + theta0, 360.0); + float gradient = clamp(1.0 - theta / 90.0, 0.0, 1.0); + finalColor += (SMOOTH(l, 1.0) + 0.5 * gradient) * blue3; + } + } - // Hypotenuse edge distance - p -= vec2(0, edge_y); - float h = clamp(dot(p, edge_h) / dot(edge_h, edge_h), 0.0, 1.0); - d = min(d, length(p - edge_h * h)); + // Main circles + { + // Circle 1 + float r1 = length(uv - c); + finalColor += (SMOOTH(r1 - 0.5 * scale, 100.0 * scale) - SMOOTH(r1 + 0.5 * scale, 100.0 * scale)) * blue1; + + // Circle 2 + float r2 = length(uv - c); + finalColor += (SMOOTH(r2 - 0.5 * scale, 165.0 * scale) - SMOOTH(r2 + 0.5 * scale, 165.0 * scale)) * blue1; + + // Circle 3 + float r3 = length(uv - c); + finalColor += (SMOOTH(r3 - 1.0 * scale, 240.0 * scale) - SMOOTH(r3 + 1.0 * scale, 240.0 * scale)) * blue4; + } - // Compute distance field sign - float ex = -p.x; - float ey = -edge_y - p.y; - float eh = edge_y * p.x + edge_x * p.y; + // Segmented outer circle + { + vec2 d = uv - c; + float r = length(d); + + if (r > 0.0) { + d = normalize(d); + float theta = 180.0 * (atan(d.y, d.x) / M_PI); + + float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * + mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); + + float circle = SMOOTH(r - 2.0 * scale, 313.0 * scale) - SMOOTH(r + 2.0 * scale, 313.0 * scale); + + finalColor += segmentPattern * circle * blue1; + } + } - // Use the sign of the greatest edge - float sig = sign(max(ex, max(ey, eh))); - sig = mix(1.0, sig, smoothstep(6.0, 7.0, animTime)); + // Triangular elements + { + vec2 d = uv - c; + float radius = (315.0 + 30.0 * sin(time)) * scale; + + // Right triangle + float t1 = 0.0; + if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { + t1 = 1.0 - smoothstep(7.0 * scale + d.x - radius, 9.0 * scale + d.x - radius, abs(d.y)); + } + + // Left triangle + float t2 = 0.0; + if (d.x + radius >= 0.0 && d.x + radius <= 8.0 * scale) { + t2 = 1.0 - smoothstep(7.0 * scale - d.x - radius, 9.0 * scale - d.x - radius, abs(d.y)); + } + + // Bottom triangle + float t3 = 0.0; + if (d.y - radius >= -8.0 * scale && d.y - radius <= 0.0) { + t3 = 1.0 - smoothstep(7.0 * scale + d.y - radius, 9.0 * scale + d.y - radius, abs(d.x)); + } + + // Top triangle + float t4 = 0.0; + if (d.y + radius >= 0.0 && d.y + radius <= 8.0 * scale) { + t4 = 1.0 - smoothstep(7.0 * scale - d.y - radius, 9.0 * scale - d.y - radius, abs(d.x)); + } + + float trianglePattern = t1 + t2 + t3 + t4; + finalColor += trianglePattern * blue2; + } - // Isolines - vec3 col = 0.95 + 0.05 * cos(d * 1e2 + vec3(0, 1, 2)); - col /= 1.0 + 20.0 * d * exp(sig * vec3(3, 0, -1)); + // Center dot + { + float r = length(uv - c); + finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; + } - // Output color (write to the image) - imageStore(image2D, pixelCoords, vec4(col, 1.0)); -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// #define RADIUS 10 -// #define MAX_LENGTH 50 - - -// void main() -// { -// int x = int(gl_GlobalInvocationID.x); -// int y = int(gl_GlobalInvocationID.y); -// int p = x + y * int(WSX); -// int positions[MAX_LENGTH][2]; // Tableau pour stocker les positions du serpent - -// for (int i = 0; i < MAX_LENGTH; ++i) -// { -// positions[i][0] = 0; -// positions[i][1] = 0; -// } - -// // Initial background is black & opaque -// if (step == 0) -// { -// data_0[p] = 0xFF000000 + y; -// } -// else -// { -// // Déplacer le serpent en fonction de la souris -// for (int i = MAX_LENGTH - 1; i > 0; --i) -// { -// positions[i][0] = positions[i - 1][0]; -// positions[i][1] = positions[i - 1][1]; -// } - -// // Stocke la nouvelle position de la souris -// positions[0][0] = mousex; -// positions[0][1] = mousey; - -// // Dessiner chaque segment du serpent -// for (int i = 0; i < MAX_LENGTH; ++i) -// { -// float dx = float(positions[i][0] - x); -// float dy = float(positions[i][1] - y); -// float dist = sqrt(dx * dx + dy * dy); + // Semicircle with opening + { + vec2 d = uv - c; + float r = length(d); + + if (r > 0.0) { + d = normalize(d); + float opening = 0.5 + 0.2 * cos(time); -// // Dessiner un segment du serpent -// if (dist < RADIUS) -// { -// int col = 0xFF00FF00; // Vert pour le serpent -// data_0[p] = 0xFF000000 + col; -// } -// } -// } - -// step++; -// } - - - - - - - - - - - -// #define RADIUS 40 - -// void main() -// { -// int x = int(gl_GlobalInvocationID.x); -// int y = int(gl_GlobalInvocationID.y); -// int p = x + y * int(WSX); - -// // Initial background is black & opaque -// if (step == 0) -// { -// data_0[p] = 0xFF000000 + y; -// }else{ -// // Draw a fading red circle -// float dx = float(mousex - x); -// float dy = float(mousey - y); -// float dist = sqrt(dx * dx + dy * dy); - -// int pix = data_0[p]; -// int col = pix & 0x00FFFFFF; -// float r = RADIUS + 10 * sin(step / 10.0f); -// if (dist < r - 1) -// { -// col = col + 0x04; -// data_0[p] = 0xFF000000 + col; -// } - -// } -// } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// void main() { -// uint x = gl_GlobalInvocationID.x; -// uint y = gl_GlobalInvocationID.y; -// uint p = x + y * WSX; // Indexation en 1D d'une matrice 2D - -// int row = y % 2; // Alternance de lignes -// int col = x % 2; // Alternance de colonnes - -// data_0[p] = (row == col) ? 0xFFFFFF00 : 0xFF0000FF; // Motif damier -// data_1[p] = 0xFFFF0000 - int(x + y) * (step); -// } - - - -// void main() { -// uint x = gl_GlobalInvocationID.x; -// uint y = gl_GlobalInvocationID.y; -// uint p = x + y * WSX; -// data_0[p] = 0xFFFF0000 - int(x+y*1024)*(step); -// } - + if (abs(d.y) > opening) { + float circle = SMOOTH(r - 0.5 * scale, 262.0 * scale) - SMOOTH(r + 0.5 * scale, 262.0 * scale); + finalColor += 0.7 * circle * blue3; + } + } + } + + // Add blips if within radar range + if (length(uv - c) < 240.0 * scale) { + // Blip 1 + { + vec2 p = 130.0 * scale * MOV(1.3, 1.0, 1.0, 1.4, 3.0 + 0.1 * time); + float r = length(uv - (c + p)); + finalColor += SMOOTH(r, 3.0 * scale) * vec3(1, 1, 1); + } + + // Blip 2 + { + vec2 p = 130.0 * scale * MOV(0.9, -1.1, 1.7, 0.8, -2.0 + sin(0.1 * time) + 0.15 * time); + float r = length(uv - (c + p)); + finalColor += SMOOTH(r, 3.0 * scale) * vec3(1, 1, 1); + } + + // Blip 3 (animated) + { + vec2 p = 50.0 * scale * MOV(1.54, 1.7, 1.37, 1.8, sin(0.1 * time + 7.0) + 0.2 * time); + float r = length(uv - (c + p)); + float R = (8.0 + mod(87.0 * time, 80.0)) * scale; + + float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(r, 5.0 * scale) + + SMOOTH(6.0 * scale, r) - SMOOTH(8.0 * scale, r) + + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, r) - SMOOTH(R, r); + + finalColor += blip * red; + } + } + + // Add fixed targets with halos + { + vec2 targetPositions[3] = vec2[]( + c + vec2(0.3, 0.2) * float(WSX) * 0.5, + c + vec2(-0.4, -0.3) * float(WSX) * 0.5, + c + vec2(0.1, -0.5) * float(WSX) * 0.5 + ); + + for (int i = 0; i < 3; i++) { + float d = length(uv - targetPositions[i]); + finalColor += red * exp(-50.0 * d / scale) * 0.7; + } + } + + // Convert to ARGB format + int r = int(clamp(finalColor.r, 0.0, 1.0) * 255.0); + int g = int(clamp(finalColor.g, 0.0, 1.0) * 255.0); + int b = int(clamp(finalColor.b, 0.0, 1.0) * 255.0); + int color = (r << 16) | (g << 8) | b; + + // Write to output + data_0[p] = 0xFF000000 | color; +} \ No newline at end of file From b313dd3507d3d6b3d198b737332bbf1501849838 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Mon, 17 Mar 2025 08:19:51 +0100 Subject: [PATCH 07/17] suppression dir projet --- examples/projet/ShaderQuad.gd | 23 ----------------------- examples/projet/ShaderQuad.gd.uid | 1 - examples/projet/node_2d.tscn | 12 ------------ examples/projet/prj.cpp | 20 -------------------- 4 files changed, 56 deletions(-) delete mode 100644 examples/projet/ShaderQuad.gd delete mode 100644 examples/projet/ShaderQuad.gd.uid delete mode 100644 examples/projet/node_2d.tscn delete mode 100644 examples/projet/prj.cpp diff --git a/examples/projet/ShaderQuad.gd b/examples/projet/ShaderQuad.gd deleted file mode 100644 index b416d28..0000000 --- a/examples/projet/ShaderQuad.gd +++ /dev/null @@ -1,23 +0,0 @@ -extends TextureRect - -@export var resolution: Vector2 = Vector2(640, 360) -var shader_material: ShaderMaterial -var time: float = 0.0 - -func _ready(): - # Crée et applique le matériel du shader - shader_material = ShaderMaterial.new() - shader_material.shader = preload("res://compute_shader.gdshader") - self.material = shader_material - self.stretch_mode = StretchMode.STRETCH_KEEP_ASPECT_CENTERED - - # Définir la taille du TextureRect à la résolution donnée - self.rect_size = resolution # Utilisez rect_size pour ajuster la taille du TextureRect - - # Définir les paramètres du shader au démarrage - self.material.set_shader_param("resolution", resolution) - -func _process(delta): - # Incrémente le temps à chaque frame - time += delta - self.material.set_shader_param("time", time) # Envoie le temps au shader diff --git a/examples/projet/ShaderQuad.gd.uid b/examples/projet/ShaderQuad.gd.uid deleted file mode 100644 index ec74118..0000000 --- a/examples/projet/ShaderQuad.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://cbg6f5ekjjg3t diff --git a/examples/projet/node_2d.tscn b/examples/projet/node_2d.tscn deleted file mode 100644 index 44b988d..0000000 --- a/examples/projet/node_2d.tscn +++ /dev/null @@ -1,12 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://83u4ieqetk01"] - -[ext_resource type="Script" uid="uid://c8nr7akmktfg8" path="res://node_2d.gd" id="1_0ilx8"] -[ext_resource type="Script" uid="uid://cbg6f5ekjjg3t" path="res://examples/projet/ShaderQuad.gd" id="2_h2mvu"] - -[node name="Node2D" type="Node2D"] -script = ExtResource("1_0ilx8") - -[node name="ShaderQuad" type="TextureRect" parent="."] -offset_right = 40.0 -offset_bottom = 40.0 -script = ExtResource("2_h2mvu") diff --git a/examples/projet/prj.cpp b/examples/projet/prj.cpp deleted file mode 100644 index e0b5d13..0000000 --- a/examples/projet/prj.cpp +++ /dev/null @@ -1,20 +0,0 @@ -extends Node2D - -@export var particle_count: int = 10000 -var particles: ImageTexture -var shader_material: ShaderMaterial - -func _ready(): - create_particles() - shader_material = ShaderMaterial.new() - shader_material.shader = preload("res://compute_shader.gdshader") - $Particles.material = shader_material - -func create_particles(): - var img = Image.create(particle_count, 1, false, Image.FORMAT_RGBAF) - img.lock() - for i in range(particle_count): - img.set_pixel(i, 0, Color(randf(), randf(), 0, 1)) - img.unlock() - particles = ImageTexture.create_from_image(img) - $Particles.texture = particles \ No newline at end of file From bdfc87d2986f438ac6016d257728a28588b7cfb1 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Mon, 17 Mar 2025 08:58:32 +0100 Subject: [PATCH 08/17] Update test.cpp modof radar --- examples/test/test.cpp | 256 +++++++++++++++-------------------------- 1 file changed, 91 insertions(+), 165 deletions(-) diff --git a/examples/test/test.cpp b/examples/test/test.cpp index 908497b..e96892e 100644 --- a/examples/test/test.cpp +++ b/examples/test/test.cpp @@ -1,214 +1,140 @@ -<<<<<<< HEAD #define M_PI 3.14159265358979323846 +// Color definitions #define blue1 vec3(0.74, 0.95, 1.00) #define blue2 vec3(0.87, 0.98, 1.00) -#define blue3 vec3(0.35, 0.76, 0.83) +#define blue3 vec3(1.0, 1.0, 1.0) #define blue4 vec3(0.953, 0.969, 0.89) -#define red vec3(1.00, 0.38, 0.227) +#define red vec3(0.00, 0.00, 1.00) +// Helper macro #define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) -#define MOV(a, b, c, d, t) (vec2(a * cos(t) + b * cos(0.1 * (t)), c * sin(t) + d * cos(0.1 * (t)))) -======= ->>>>>>> acdc12f316fab591711a0beaa2bfd7620111fab2 void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; -<<<<<<< HEAD // Normalized coordinates vec2 uv = vec2(float(x), float(y)); vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center + vec2 d = uv - c; + float r = length(d); - // Scale factor to match the original effect size + // Scale factor and time float scale = min(float(WSX), float(WSY)) / 650.0; - - // Time variable float time = float(step) * 0.01; // Start with a black background vec3 finalColor = vec3(0.0); - // ---- Begin radar element calculations ---- + // Normalized direction (for angles) + vec2 dn = r > 0.0 ? d / r : vec2(0.0); + float angle = atan(dn.y, dn.x); + float theta = 180.0 * angle / M_PI; + + // Main circles - combined into one section + finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; + + // Center dot + finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; // Moving scan line - { + if (r < 240.0 * scale) { + float scanAngle = 90.0 * time * M_PI / 180.0; + vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); + float scanDist = dot(dn, scanDir); float theta0 = 90.0 * time; - vec2 d = uv - c; - float r = length(d); - - if (r < 240.0 * scale) { - vec2 p = 240.0 * scale * vec2(cos(theta0 * M_PI / 180.0), -sin(theta0 * M_PI / 180.0)); - float l = length(d - p * clamp(dot(d, p) / dot(p, p), 0.0, 1.0)); - d = normalize(d); - float theta = mod(180.0 * atan(d.y, d.x) / M_PI + theta0, 360.0); - float gradient = clamp(1.0 - theta / 90.0, 0.0, 1.0); - finalColor += (SMOOTH(l, 1.0) + 0.5 * gradient) * blue3; - } - } - - // Main circles - { - // Circle 1 - float r1 = length(uv - c); - finalColor += (SMOOTH(r1 - 0.5 * scale, 100.0 * scale) - SMOOTH(r1 + 0.5 * scale, 100.0 * scale)) * blue1; - - // Circle 2 - float r2 = length(uv - c); - finalColor += (SMOOTH(r2 - 0.5 * scale, 165.0 * scale) - SMOOTH(r2 + 0.5 * scale, 165.0 * scale)) * blue1; - - // Circle 3 - float r3 = length(uv - c); - finalColor += (SMOOTH(r3 - 1.0 * scale, 240.0 * scale) - SMOOTH(r3 + 1.0 * scale, 240.0 * scale)) * blue4; + float angDiff = mod(theta + theta0, 360.0); + float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); + float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; + finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); } // Segmented outer circle - { - vec2 d = uv - c; - float r = length(d); - - if (r > 0.0) { - d = normalize(d); - float theta = 180.0 * (atan(d.y, d.x) / M_PI); - - float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * - mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); - - float circle = SMOOTH(r - 2.0 * scale, 313.0 * scale) - SMOOTH(r + 2.0 * scale, 313.0 * scale); - - finalColor += segmentPattern * circle * blue1; - } - } - - // Triangular elements - { - vec2 d = uv - c; - float radius = (315.0 + 30.0 * sin(time)) * scale; - - // Right triangle - float t1 = 0.0; - if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { - t1 = 1.0 - smoothstep(7.0 * scale + d.x - radius, 9.0 * scale + d.x - radius, abs(d.y)); - } - - // Left triangle - float t2 = 0.0; - if (d.x + radius >= 0.0 && d.x + radius <= 8.0 * scale) { - t2 = 1.0 - smoothstep(7.0 * scale - d.x - radius, 9.0 * scale - d.x - radius, abs(d.y)); - } - - // Bottom triangle - float t3 = 0.0; - if (d.y - radius >= -8.0 * scale && d.y - radius <= 0.0) { - t3 = 1.0 - smoothstep(7.0 * scale + d.y - radius, 9.0 * scale + d.y - radius, abs(d.x)); - } - - // Top triangle - float t4 = 0.0; - if (d.y + radius >= 0.0 && d.y + radius <= 8.0 * scale) { - t4 = 1.0 - smoothstep(7.0 * scale - d.y - radius, 9.0 * scale - d.y - radius, abs(d.x)); - } - - float trianglePattern = t1 + t2 + t3 + t4; - finalColor += trianglePattern * blue2; - } - - // Center dot - { - float r = length(uv - c); - finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; + if (r > 310.0 * scale && r < 316.0 * scale) { + float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * + mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); + finalColor += segmentPattern * blue1; } // Semicircle with opening - { - vec2 d = uv - c; - float r = length(d); - - if (r > 0.0) { - d = normalize(d); - float opening = 0.5 + 0.2 * cos(time); - - if (abs(d.y) > opening) { - float circle = SMOOTH(r - 0.5 * scale, 262.0 * scale) - SMOOTH(r + 0.5 * scale, 262.0 * scale); - finalColor += 0.7 * circle * blue3; - } + if (r > 260.0 * scale && r < 264.0 * scale) { + float opening = 0.5 + 0.2 * cos(time); + if (abs(dn.y) > opening) { + finalColor += 0.7 * blue3; } } - - // Add blips if within radar range - if (length(uv - c) < 240.0 * scale) { + // Triangular elements - simplified + float radius = (315.0 + 30.0 * sin(time)) * scale; + // Right triangle + if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { + float t = 1.0 - smoothstep(7.0 * scale + d.x - radius, 9.0 * scale + d.x - radius, abs(d.y)); + finalColor += t * blue2; + } + // Left triangle + if (d.x + radius >= 0.0 && d.x + radius <= 8.0 * scale) { + float t = 1.0 - smoothstep(7.0 * scale - d.x - radius, 9.0 * scale - d.x - radius, abs(d.y)); + finalColor += t * blue2; + } + // Bottom triangle + if (d.y - radius >= -8.0 * scale && d.y - radius <= 0.0) { + float t = 1.0 - smoothstep(7.0 * scale + d.y - radius, 9.0 * scale + d.y - radius, abs(d.x)); + finalColor += t * blue2; + } + // Top triangle + if (d.y + radius >= 0.0 && d.y + radius <= 8.0 * scale) { + float t = 1.0 - smoothstep(7.0 * scale - d.y - radius, 9.0 * scale - d.y - radius, abs(d.x)); + finalColor += t * blue2; + } + + // Blips - simplified + if (r < 240.0 * scale) { // Blip 1 { - vec2 p = 130.0 * scale * MOV(1.3, 1.0, 1.0, 1.4, 3.0 + 0.1 * time); - float r = length(uv - (c + p)); - finalColor += SMOOTH(r, 3.0 * scale) * vec3(1, 1, 1); - } - - // Blip 2 - { - vec2 p = 130.0 * scale * MOV(0.9, -1.1, 1.7, 0.8, -2.0 + sin(0.1 * time) + 0.15 * time); - float r = length(uv - (c + p)); - finalColor += SMOOTH(r, 3.0 * scale) * vec3(1, 1, 1); + float t = time * 0.1; + vec2 pos = c + 130.0 * scale * vec2( + 1.3 * cos(t) + 1.0 * cos(0.1 * t), + 1.0 * sin(t) + 1.4 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); } - - // Blip 3 (animated) + // Blip 2 { - vec2 p = 50.0 * scale * MOV(1.54, 1.7, 1.37, 1.8, sin(0.1 * time + 7.0) + 0.2 * time); - float r = length(uv - (c + p)); + float t = sin(0.1 * time + 7.0) + 0.2 * time; + vec2 pos = c + 50.0 * scale * vec2( + 1.54 * cos(t) + 1.7 * cos(0.1 * t), + 1.37 * sin(t) + 1.8 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); float R = (8.0 + mod(87.0 * time, 80.0)) * scale; - float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(r, 5.0 * scale) - + SMOOTH(6.0 * scale, r) - SMOOTH(8.0 * scale, r) - + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, r) - SMOOTH(R, r); + float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) + + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) + + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); finalColor += blip * red; } } - // Add fixed targets with halos - { - vec2 targetPositions[3] = vec2[]( - c + vec2(0.3, 0.2) * float(WSX) * 0.5, - c + vec2(-0.4, -0.3) * float(WSX) * 0.5, - c + vec2(0.1, -0.5) * float(WSX) * 0.5 - ); - - for (int i = 0; i < 3; i++) { - float d = length(uv - targetPositions[i]); - finalColor += red * exp(-50.0 * d / scale) * 0.7; - } - } - - // Convert to ARGB format - int r = int(clamp(finalColor.r, 0.0, 1.0) * 255.0); - int g = int(clamp(finalColor.g, 0.0, 1.0) * 255.0); - int b = int(clamp(finalColor.b, 0.0, 1.0) * 255.0); - int color = (r << 16) | (g << 8) | b; - - // Write to output - data_0[p] = 0xFF000000 | color; -} -======= - vec2 uv = vec2(float(x) / float(WSX), float(y) / float(WSY)); - vec2 pos = uv - 0.5; - pos.x *= float(WSX) / float(WSY); - - float z = float(step) * 0.01; - float l = length(pos); + // Fixed targets with halos + vec2 targetPositions[3] = vec2[]( + c + vec2(0.3, 0.2) * float(WSX) * 0.5, + c + vec2(-0.4, -0.3) * float(WSX) * 0.5, + c + vec2(0.1, -0.5) * float(WSX) * 0.5 + ); - uv += pos / l * (sin(z) + 1.0) * abs(sin(l * 9.0 - z - z)); + for (int i = 0; i < 3; i++) { + float targetDist = length(uv - targetPositions[i]); + finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; + } - // Adjusted colors for a more feminine palette - float r = 0.12 / length(mod(uv + 0.4, vec2(1.0)) - 0.5); // Soft pink - float g = 0.05 / length(mod(uv + 0.6, vec2(1.0)) - 0.5); // Light purple - float b = 0.10 / length(mod(uv + 0.8, vec2(1.0)) - 0.5); // Lavender + int color = (int(clamp(finalColor.r, 0.0, 1.0) * 255.0) << 16) | + (int(clamp(finalColor.g, 0.0, 1.0) * 255.0) << 8) | + int(clamp(finalColor.b, 0.0, 1.0) * 255.0); - int color = (int(r * 255.0) << 16) | (int(g * 255.0) << 8) | int(b * 255.0); data_0[p] = 0xFF000000 | color; -} - - -/// comm test ->>>>>>> acdc12f316fab591711a0beaa2bfd7620111fab2 +} \ No newline at end of file From 68a8e1393ce82989c54378205b01ba25d00f372c Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Mon, 17 Mar 2025 09:04:05 +0100 Subject: [PATCH 09/17] Update test.cpp modif radar --- examples/test/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/test/test.cpp b/examples/test/test.cpp index e96892e..77497b3 100644 --- a/examples/test/test.cpp +++ b/examples/test/test.cpp @@ -67,7 +67,7 @@ void main() { finalColor += 0.7 * blue3; } } - // Triangular elements - simplified + // Triangular elements float radius = (315.0 + 30.0 * sin(time)) * scale; // Right triangle if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { @@ -90,7 +90,7 @@ void main() { finalColor += t * blue2; } - // Blips - simplified + // Blips if (r < 240.0 * scale) { // Blip 1 { From 431b7b04d7383d00e6b66a2b7c401a782463c862 Mon Sep 17 00:00:00 2001 From: Tasnime66 Date: Mon, 17 Mar 2025 09:50:53 +0100 Subject: [PATCH 10/17] code radar --- examples/example_1.tscn | 2 +- examples/projet/test.cpp | 123 +++++++++++++++++++++++++++++++++----- examples/projet/test.tscn | 7 +-- 3 files changed, 112 insertions(+), 20 deletions(-) diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 7d67949..6aa7e5c 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://ddr6qtwy1pesd"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[ext_resource type="Script" uid="uid://bv34hd4a2wbit" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_s3fct"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_dmk8h"] diff --git a/examples/projet/test.cpp b/examples/projet/test.cpp index 1121646..9cd22d2 100644 --- a/examples/projet/test.cpp +++ b/examples/projet/test.cpp @@ -1,25 +1,118 @@ +#define M_PI 3.14159265358979323846 + +// Color definitions +#define blue1 vec3(0.74, 0.95, 1.00) +#define blue2 vec3(0.87, 0.98, 1.00) +#define blue3 vec3(0.35, 0.76, 0.83) +#define blue4 vec3(0.953, 0.969, 0.89) +#define red vec3(1.00, 0.38, 0.227) + +// Helper macro +#define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) + void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; - vec2 uv = vec2(float(x) / float(WSX), float(y) / float(WSY)); - vec2 pos = uv - 0.5; - pos.x *= float(WSX) / float(WSY); + // Normalized coordinates + vec2 uv = vec2(float(x), float(y)); + vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center + vec2 d = uv - c; + float r = length(d); + + // Scale factor and time + float scale = min(float(WSX), float(WSY)) / 650.0; + float time = float(step) * 0.01; + + // Start with a black background + vec3 finalColor = vec3(0.0); + + // Normalized direction (for angles) + vec2 dn = r > 0.0 ? d / r : vec2(0.0); + float angle = atan(dn.y, dn.x); + float theta = 180.0 * angle / M_PI; + + // Main circles - combined into one section + finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; - float z = float(step) * 0.01; - float l = length(pos); + // Center dot + finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; - uv += pos / l * (sin(z) + 1.0) * abs(sin(l * 9.0 - z - z)); + // Moving scan line + if (r < 240.0 * scale) { + float scanAngle = 90.0 * time * M_PI / 180.0; + vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); + float scanDist = dot(dn, scanDir); + float theta0 = 90.0 * time; + float angDiff = mod(theta + theta0, 360.0); + float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); + float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; + finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); + } - // Adjusted colors for a more feminine palette - float r = 0.12 / length(mod(uv + 0.4, vec2(1.0)) - 0.5); // Soft pink - float g = 0.05 / length(mod(uv + 0.6, vec2(1.0)) - 0.5); // Light purple - float b = 0.10 / length(mod(uv + 0.8, vec2(1.0)) - 0.5); // Lavender + // Segmented outer circle + if (r > 310.0 * scale && r < 316.0 * scale) { + float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * + mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); + finalColor += segmentPattern * blue1; + } + + // Semicircle with opening + if (r > 260.0 * scale && r < 264.0 * scale) { + float opening = 0.5 + 0.2 * cos(time); + if (abs(dn.y) > opening) { + finalColor += 0.7 * blue3; + } + } + + // Blips - simplified + if (r < 240.0 * scale) { + // Blip 1 + { + float t = time * 3.1; + vec2 pos = c + 130.0 * scale * vec2( + 1.3 * cos(t) + 1.0 * cos(0.1 * t), + 1.0 * sin(t) + 1.4 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); + } + // Blip 2 + { + float t = sin(0.1 * time + 7.0) + 0.2 * time; + vec2 pos = c + 50.0 * scale * vec2( + 1.54 * cos(t) + 1.7 * cos(0.1 * t), + 1.37 * sin(t) + 1.8 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + float R = (8.0 + mod(87.0 * time, 80.0)) * scale; + + float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) + + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) + + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); + + finalColor += blip * red; + } + } + + // Fixed targets with halos + vec2 targetPositions[3] = vec2[]( + c + vec2(0.3, 0.2) * float(WSX) * 0.5, + c + vec2(-0.4, -0.3) * float(WSX) * 0.5, + c + vec2(0.1, -0.5) * float(WSX) * 0.5 + ); + + for (int i = 0; i < 3; i++) { + float targetDist = length(uv - targetPositions[i]); + finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; + } + + int color = (int(clamp(finalColor.r, 0.0, 1.0) * 255.0) << 16) | + (int(clamp(finalColor.g, 0.0, 1.0) * 255.0) << 8) | + int(clamp(finalColor.b, 0.0, 1.0) * 255.0); - int color = (int(r * 255.0) << 16) | (int(g * 255.0) << 8) | int(b * 255.0); data_0[p] = 0xFF000000 | color; -} - - -/// comm test \ No newline at end of file +} \ No newline at end of file diff --git a/examples/projet/test.tscn b/examples/projet/test.tscn index 4bb49ca..fb33c3a 100644 --- a/examples/projet/test.tscn +++ b/examples/projet/test.tscn @@ -1,12 +1,12 @@ [gd_scene load_steps=3 format=3 uid="uid://bhsg8ie7m0n18"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_tfywn"] -[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_3uxvf"] +[ext_resource type="Script" uid="uid://bv34hd4a2wbit" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_3uxvf"] [node name="Test" type="Node2D"] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(579, 337.5) +position = Vector2(625, 361) scale = Vector2(9.73438, 5.74219) texture = ExtResource("1_tfywn") @@ -14,7 +14,6 @@ texture = ExtResource("1_tfywn") script = ExtResource("2_3uxvf") WSX = 512 WSY = 512 -glsl_file = "res://examples/test/test.cpp" +glsl_file = "res://examples/projet/test.cpp" GLSL_code = "" data = [NodePath("..")] -metadata/_custom_type_script = "uid://cleifuttwn5dw" From 12ab33c38dbcc2c8ade7ef1252941165d325d738 Mon Sep 17 00:00:00 2001 From: Tasnime66 Date: Mon, 17 Mar 2025 21:52:22 +0100 Subject: [PATCH 11/17] =?UTF-8?q?fichier=20projet=20a=20=C3=A9t=C3=A9=20up?= =?UTF-8?q?date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/projet/test.cpp | 155 +++++++++++++++++++++------------------ project.godot | 4 +- 2 files changed, 85 insertions(+), 74 deletions(-) diff --git a/examples/projet/test.cpp b/examples/projet/test.cpp index 9cd22d2..3e76a6d 100644 --- a/examples/projet/test.cpp +++ b/examples/projet/test.cpp @@ -10,6 +10,9 @@ // Helper macro #define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) +// Variable to control radar state (0 = stopped, 1 = running) +int radarState = 1; // Initial state is running + void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; @@ -33,81 +36,84 @@ void main() { float angle = atan(dn.y, dn.x); float theta = 180.0 * angle / M_PI; - // Main circles - combined into one section - finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; - - // Center dot - finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; - - // Moving scan line - if (r < 240.0 * scale) { - float scanAngle = 90.0 * time * M_PI / 180.0; - vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); - float scanDist = dot(dn, scanDir); - float theta0 = 90.0 * time; - float angDiff = mod(theta + theta0, 360.0); - float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); - float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; - finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); - } - - // Segmented outer circle - if (r > 310.0 * scale && r < 316.0 * scale) { - float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * - mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); - finalColor += segmentPattern * blue1; - } - - // Semicircle with opening - if (r > 260.0 * scale && r < 264.0 * scale) { - float opening = 0.5 + 0.2 * cos(time); - if (abs(dn.y) > opening) { - finalColor += 0.7 * blue3; + // Check if radar is running + if (radarState == 1) { + // Main circles - combined into one section + finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; + + // Center dot + finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; + + // Moving scan line + if (r < 240.0 * scale) { + float scanAngle = 90.0 * time * M_PI / 180.0; + vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); + float scanDist = dot(dn, scanDir); + float theta0 = 90.0 * time; + float angDiff = mod(theta + theta0, 360.0); + float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); + float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; + finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); } - } - - // Blips - simplified - if (r < 240.0 * scale) { - // Blip 1 - { - float t = time * 3.1; - vec2 pos = c + 130.0 * scale * vec2( - 1.3 * cos(t) + 1.0 * cos(0.1 * t), - 1.0 * sin(t) + 1.4 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); + + // Segmented outer circle + if (r > 310.0 * scale && r < 316.0 * scale) { + float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * + mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); + finalColor += segmentPattern * blue1; + } + + // Semicircle with opening + if (r > 260.0 * scale && r < 264.0 * scale) { + float opening = 0.5 + 0.2 * cos(time); + if (abs(dn.y) > opening) { + finalColor += 0.7 * blue3; + } } - // Blip 2 - { - float t = sin(0.1 * time + 7.0) + 0.2 * time; - vec2 pos = c + 50.0 * scale * vec2( - 1.54 * cos(t) + 1.7 * cos(0.1 * t), - 1.37 * sin(t) + 1.8 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - float R = (8.0 + mod(87.0 * time, 80.0)) * scale; - - float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) - + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) - + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); + + // Blips - simplified + if (r < 240.0 * scale) { + // Blip 1 + { + float t = time * 3.1; + vec2 pos = c + 130.0 * scale * vec2( + 1.3 * cos(t) + 1.0 * cos(0.1 * t), + 1.0 * sin(t) + 1.4 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); + } + // Blip 2 + { + float t = sin(0.1 * time + 7.0) + 0.2 * time; + vec2 pos = c + 50.0 * scale * vec2( + 1.54 * cos(t) + 1.7 * cos(0.1 * t), + 1.37 * sin(t) + 1.8 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + float R = (8.0 + mod(87.0 * time, 80.0)) * scale; - finalColor += blip * red; + float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) + + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) + + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); + + finalColor += blip * red; + } + } + + // Fixed targets with halos + vec2 targetPositions[3] = vec2[]( + c + vec2(0.3, 0.2) * float(WSX) * 0.5, + c + vec2(-0.4, -0.3) * float(WSX) * 0.5, + c + vec2(0.1, -0.5) * float(WSX) * 0.5 + ); + + for (int i = 0; i < 3; i++) { + float targetDist = length(uv - targetPositions[i]); + finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; } - } - - // Fixed targets with halos - vec2 targetPositions[3] = vec2[]( - c + vec2(0.3, 0.2) * float(WSX) * 0.5, - c + vec2(-0.4, -0.3) * float(WSX) * 0.5, - c + vec2(0.1, -0.5) * float(WSX) * 0.5 - ); - - for (int i = 0; i < 3; i++) { - float targetDist = length(uv - targetPositions[i]); - finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; } int color = (int(clamp(finalColor.r, 0.0, 1.0) * 255.0) << 16) | @@ -115,4 +121,9 @@ void main() { int(clamp(finalColor.b, 0.0, 1.0) * 255.0); data_0[p] = 0xFF000000 | color; -} \ No newline at end of file +} + +// Function to toggle radar state (called when button is pressed) +void toggleRadarState() { + radarState = 1 - radarState; // Switch between 1 (running) and 0 (stopped) +} diff --git a/project.godot b/project.godot index 725be9c..b118d2e 100644 --- a/project.godot +++ b/project.godot @@ -11,8 +11,8 @@ config_version=5 [application] config/name="compute_shader_studio" -run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.3", "Forward Plus") +run/main_scene="uid://bhsg8ie7m0n18" +config/features=PackedStringArray("4.4", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From 3c4790405762e5260bdd03f4e862eeb2081dcf74 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Tue, 18 Mar 2025 09:09:15 +0100 Subject: [PATCH 12/17] final --- examples/test/test.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/examples/test/test.cpp b/examples/test/test.cpp index 77497b3..9677da2 100644 --- a/examples/test/test.cpp +++ b/examples/test/test.cpp @@ -15,17 +15,17 @@ void main() { uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; - // Normalized coordinates + //Calcule les coordonnées normalisées et la distance depuis le centre de l'écran (r). vec2 uv = vec2(float(x), float(y)); vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center vec2 d = uv - c; float r = length(d); - // Scale factor and time + //Définit un facteur d'échelle pour adapter les éléments à la taille de l'écran et une variable du temps float scale = min(float(WSX), float(WSY)) / 650.0; float time = float(step) * 0.01; - // Start with a black background + // arriere plan noir vec3 finalColor = vec3(0.0); // Normalized direction (for angles) @@ -33,15 +33,15 @@ void main() { float angle = atan(dn.y, dn.x); float theta = 180.0 * angle / M_PI; - // Main circles - combined into one section + //Dessine trois cercles concentriques de différentes tailles. finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; - // Center dot + // Dessine un petit point au centre. finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; - // Moving scan line + // Crée une ligne de balayage qui tourne comme un radar, avec un gradient. if (r < 240.0 * scale) { float scanAngle = 90.0 * time * M_PI / 180.0; vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); @@ -53,21 +53,23 @@ void main() { finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); } - // Segmented outer circle + // Dessine un cercle extérieur avec des segments réguliers. if (r > 310.0 * scale && r < 316.0 * scale) { float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); finalColor += segmentPattern * blue1; } - // Semicircle with opening + // Crée un demi-cercle avec une ouverture qui varie avec le temps. if (r > 260.0 * scale && r < 264.0 * scale) { float opening = 0.5 + 0.2 * cos(time); if (abs(dn.y) > opening) { finalColor += 0.7 * blue3; } } - // Triangular elements + + + // Dessine quatre triangles qui pulsent avec le temps autour d'un cercle invisible. float radius = (315.0 + 30.0 * sin(time)) * scale; // Right triangle if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { @@ -90,7 +92,7 @@ void main() { finalColor += t * blue2; } - // Blips + // Dessine deux points mobiles qui se déplacent sur des trajectoires complexes. if (r < 240.0 * scale) { // Blip 1 { @@ -120,7 +122,7 @@ void main() { } } - // Fixed targets with halos + // Dessine trois cibles fixes avec des halos lumineux. vec2 targetPositions[3] = vec2[]( c + vec2(0.3, 0.2) * float(WSX) * 0.5, c + vec2(-0.4, -0.3) * float(WSX) * 0.5, From b5fb777d0ca2fbd90fcb93b15a0a8ece553b3b67 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Tue, 18 Mar 2025 09:30:05 +0100 Subject: [PATCH 13/17] version finale --- examples/{test/test.cpp => radar/radar.cpp} | 0 examples/{test/test.glsl.import => radar/radar.glsl.import} | 0 examples/{test/test.tscn => radar/radar.tscn} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename examples/{test/test.cpp => radar/radar.cpp} (100%) rename examples/{test/test.glsl.import => radar/radar.glsl.import} (100%) rename examples/{test/test.tscn => radar/radar.tscn} (100%) diff --git a/examples/test/test.cpp b/examples/radar/radar.cpp similarity index 100% rename from examples/test/test.cpp rename to examples/radar/radar.cpp diff --git a/examples/test/test.glsl.import b/examples/radar/radar.glsl.import similarity index 100% rename from examples/test/test.glsl.import rename to examples/radar/radar.glsl.import diff --git a/examples/test/test.tscn b/examples/radar/radar.tscn similarity index 100% rename from examples/test/test.tscn rename to examples/radar/radar.tscn From af4a79e182cc054c0839bb4125b0cf8e60eab9b9 Mon Sep 17 00:00:00 2001 From: Ayad <167223214+Ayadayi@users.noreply.github.com> Date: Tue, 18 Mar 2025 09:45:21 +0100 Subject: [PATCH 14/17] version finale --- examples/radar/radar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/radar/radar.cpp b/examples/radar/radar.cpp index 9677da2..9dc7089 100644 --- a/examples/radar/radar.cpp +++ b/examples/radar/radar.cpp @@ -1,7 +1,7 @@ #define M_PI 3.14159265358979323846 // Color definitions -#define blue1 vec3(0.74, 0.95, 1.00) +#define blue1 vec3(0.74, 0.0, 0.00) #define blue2 vec3(0.87, 0.98, 1.00) #define blue3 vec3(1.0, 1.0, 1.0) #define blue4 vec3(0.953, 0.969, 0.89) From a990abadba4fc6a14bf3ab202f11bc53101180a8 Mon Sep 17 00:00:00 2001 From: Tasnime66 Date: Tue, 18 Mar 2025 10:19:42 +0100 Subject: [PATCH 15/17] version finale de projet/test.cpp --- .../compute_shader_studio_2d.gd.uid | 1 + .../compute_shader_studio_plugin.gd.uid | 1 + examples/LabelStepPass.gd.uid | 1 + examples/cells/cells.gd.uid | 1 + examples/example_mandelbrot.gd.uid | 1 + examples/projet/.vscode/c_cpp_properties.json | 18 ++ examples/projet/.vscode/launch.json | 24 +++ examples/projet/.vscode/settings.json | 60 ++++++ examples/projet/test.cpp | 189 +++++++++--------- 9 files changed, 207 insertions(+), 89 deletions(-) create mode 100644 addons/compute_shader_studio/compute_shader_studio_2d.gd.uid create mode 100644 addons/compute_shader_studio/compute_shader_studio_plugin.gd.uid create mode 100644 examples/LabelStepPass.gd.uid create mode 100644 examples/cells/cells.gd.uid create mode 100644 examples/example_mandelbrot.gd.uid create mode 100644 examples/projet/.vscode/c_cpp_properties.json create mode 100644 examples/projet/.vscode/launch.json create mode 100644 examples/projet/.vscode/settings.json 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..1074950 --- /dev/null +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd.uid @@ -0,0 +1 @@ +uid://bv34hd4a2wbit 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..e63673e --- /dev/null +++ b/addons/compute_shader_studio/compute_shader_studio_plugin.gd.uid @@ -0,0 +1 @@ +uid://bj4dail4toa6d diff --git a/examples/LabelStepPass.gd.uid b/examples/LabelStepPass.gd.uid new file mode 100644 index 0000000..962b2df --- /dev/null +++ b/examples/LabelStepPass.gd.uid @@ -0,0 +1 @@ +uid://d1nyjgfrrao0a diff --git a/examples/cells/cells.gd.uid b/examples/cells/cells.gd.uid new file mode 100644 index 0000000..65d567d --- /dev/null +++ b/examples/cells/cells.gd.uid @@ -0,0 +1 @@ +uid://b16p10g4mmytd diff --git a/examples/example_mandelbrot.gd.uid b/examples/example_mandelbrot.gd.uid new file mode 100644 index 0000000..8bd7f2a --- /dev/null +++ b/examples/example_mandelbrot.gd.uid @@ -0,0 +1 @@ +uid://cctywdtbt8h6n diff --git a/examples/projet/.vscode/c_cpp_properties.json b/examples/projet/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..cea4d3f --- /dev/null +++ b/examples/projet/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/examples/projet/.vscode/launch.json b/examples/projet/.vscode/launch.json new file mode 100644 index 0000000..98513c4 --- /dev/null +++ b/examples/projet/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/Tasnime/ComputeShaderStudio/examples/projet", + "program": "c:/Users/Tasnime/ComputeShaderStudio/examples/projet/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/projet/.vscode/settings.json b/examples/projet/.vscode/settings.json new file mode 100644 index 0000000..fd17536 --- /dev/null +++ b/examples/projet/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false, + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/examples/projet/test.cpp b/examples/projet/test.cpp index 3e76a6d..eba89e6 100644 --- a/examples/projet/test.cpp +++ b/examples/projet/test.cpp @@ -1,34 +1,31 @@ #define M_PI 3.14159265358979323846 // Color definitions -#define blue1 vec3(0.74, 0.95, 1.00) +#define blue1 vec3(0.74, 0, 1.00) #define blue2 vec3(0.87, 0.98, 1.00) -#define blue3 vec3(0.35, 0.76, 0.83) +#define blue3 vec3(1.0, 1.0, 1.0) #define blue4 vec3(0.953, 0.969, 0.89) -#define red vec3(1.00, 0.38, 0.227) +#define red vec3(0.00, 0.00, 1.00) // Helper macro #define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) -// Variable to control radar state (0 = stopped, 1 = running) -int radarState = 1; // Initial state is running - void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; - // Normalized coordinates + //Calcule les coordonnées normalisées et la distance depuis le centre de l'écran (r). vec2 uv = vec2(float(x), float(y)); vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center vec2 d = uv - c; float r = length(d); - // Scale factor and time + //Définit un facteur d'échelle pour adapter les éléments à la taille de l'écran et une variable du temps float scale = min(float(WSX), float(WSY)) / 650.0; float time = float(step) * 0.01; - // Start with a black background + // arriere plan noir vec3 finalColor = vec3(0.0); // Normalized direction (for angles) @@ -36,94 +33,108 @@ void main() { float angle = atan(dn.y, dn.x); float theta = 180.0 * angle / M_PI; - // Check if radar is running - if (radarState == 1) { - // Main circles - combined into one section - finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; - - // Center dot - finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; - - // Moving scan line - if (r < 240.0 * scale) { - float scanAngle = 90.0 * time * M_PI / 180.0; - vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); - float scanDist = dot(dn, scanDir); - float theta0 = 90.0 * time; - float angDiff = mod(theta + theta0, 360.0); - float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); - float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; - finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); - } - - // Segmented outer circle - if (r > 310.0 * scale && r < 316.0 * scale) { - float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * - mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); - finalColor += segmentPattern * blue1; + //Dessine trois cercles concentriques de différentes tailles. + finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; + finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; + + // Dessine un petit point au centre. + finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; + + // Crée une ligne de balayage qui tourne comme un radar, avec un gradient. + if (r < 240.0 * scale) { + float scanAngle = 90.0 * time * M_PI / 180.0; + vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); + float scanDist = dot(dn, scanDir); + float theta0 = 90.0 * time; + float angDiff = mod(theta + theta0, 360.0); + float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); + float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; + finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); + } + + // Segmented outer circle + if (r > 310.0 * scale && r < 316.0 * scale) { + float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * + mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); + finalColor += segmentPattern * blue1; + } + + // Semicircle with opening + if (r > 260.0 * scale && r < 264.0 * scale) { + float opening = 0.5 + 0.2 * cos(time); + if (abs(dn.y) > opening) { + finalColor += 0.7 * blue3; } - - // Semicircle with opening - if (r > 260.0 * scale && r < 264.0 * scale) { - float opening = 0.5 + 0.2 * cos(time); - if (abs(dn.y) > opening) { - finalColor += 0.7 * blue3; - } + } + // Triangular elements + float radius = (315.0 + 30.0 * sin(time)) * scale; + // Right triangle + if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { + float t = 1.0 - smoothstep(7.0 * scale + d.x - radius, 9.0 * scale + d.x - radius, abs(d.y)); + finalColor += t * blue2; + } + // Left triangle + if (d.x + radius >= 0.0 && d.x + radius <= 8.0 * scale) { + float t = 1.0 - smoothstep(7.0 * scale - d.x - radius, 9.0 * scale - d.x - radius, abs(d.y)); + finalColor += t * blue2; + } + // Bottom triangle + if (d.y - radius >= -8.0 * scale && d.y - radius <= 0.0) { + float t = 1.0 - smoothstep(7.0 * scale + d.y - radius, 9.0 * scale + d.y - radius, abs(d.x)); + finalColor += t * blue2; + } + // Top triangle + if (d.y + radius >= 0.0 && d.y + radius <= 8.0 * scale) { + float t = 1.0 - smoothstep(7.0 * scale - d.y - radius, 9.0 * scale - d.y - radius, abs(d.x)); + finalColor += t * blue2; + } + + // Blips + if (r < 240.0 * scale) { + // Blip 1 + { + float t = time * 0.1; + vec2 pos = c + 130.0 * scale * vec2( + 1.3 * cos(t) + 1.0 * cos(0.1 * t), + 1.0 * sin(t) + 1.4 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); } - - // Blips - simplified - if (r < 240.0 * scale) { - // Blip 1 - { - float t = time * 3.1; - vec2 pos = c + 130.0 * scale * vec2( - 1.3 * cos(t) + 1.0 * cos(0.1 * t), - 1.0 * sin(t) + 1.4 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); - } - // Blip 2 - { - float t = sin(0.1 * time + 7.0) + 0.2 * time; - vec2 pos = c + 50.0 * scale * vec2( - 1.54 * cos(t) + 1.7 * cos(0.1 * t), - 1.37 * sin(t) + 1.8 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - float R = (8.0 + mod(87.0 * time, 80.0)) * scale; + // Blip 2 + { + float t = sin(0.1 * time + 7.0) + 0.2 * time; + vec2 pos = c + 50.0 * scale * vec2( + 1.54 * cos(t) + 1.7 * cos(0.1 * t), + 1.37 * sin(t) + 1.8 * cos(0.1 * t) + ); + float blipDist = length(uv - pos); + float R = (8.0 + mod(87.0 * time, 80.0)) * scale; + + float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) + + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) + + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); - float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) - + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) - + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); - - finalColor += blip * red; - } - } - - // Fixed targets with halos - vec2 targetPositions[3] = vec2[]( - c + vec2(0.3, 0.2) * float(WSX) * 0.5, - c + vec2(-0.4, -0.3) * float(WSX) * 0.5, - c + vec2(0.1, -0.5) * float(WSX) * 0.5 - ); - - for (int i = 0; i < 3; i++) { - float targetDist = length(uv - targetPositions[i]); - finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; + finalColor += blip * red; } } + // Fixed targets with halos + vec2 targetPositions[3] = vec2[]( + c + vec2(0.3, 0.2) * float(WSX) * 0.5, + c + vec2(-0.4, -0.3) * float(WSX) * 0.5, + c + vec2(0.1, -0.5) * float(WSX) * 0.5 + ); + + for (int i = 0; i < 3; i++) { + float targetDist = length(uv - targetPositions[i]); + finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; + } + int color = (int(clamp(finalColor.r, 0.0, 1.0) * 255.0) << 16) | (int(clamp(finalColor.g, 0.0, 1.0) * 255.0) << 8) | int(clamp(finalColor.b, 0.0, 1.0) * 255.0); data_0[p] = 0xFF000000 | color; -} - -// Function to toggle radar state (called when button is pressed) -void toggleRadarState() { - radarState = 1 - radarState; // Switch between 1 (running) and 0 (stopped) -} +} \ No newline at end of file From 51e2a31d55b30b7038d0b9db19e3b54f4651c5b3 Mon Sep 17 00:00:00 2001 From: Tasnime66 Date: Tue, 18 Mar 2025 11:44:51 +0100 Subject: [PATCH 16/17] Vfinale --- examples/example_1.tscn | 2 +- examples/projet/.vscode/c_cpp_properties.json | 18 --- examples/projet/.vscode/launch.json | 24 --- examples/projet/.vscode/settings.json | 60 -------- examples/projet/test.cpp | 140 ------------------ examples/projet/test.glsl.import | 14 -- examples/projet/test.tscn | 19 --- 7 files changed, 1 insertion(+), 276 deletions(-) delete mode 100644 examples/projet/.vscode/c_cpp_properties.json delete mode 100644 examples/projet/.vscode/launch.json delete mode 100644 examples/projet/.vscode/settings.json delete mode 100644 examples/projet/test.cpp delete mode 100644 examples/projet/test.glsl.import delete mode 100644 examples/projet/test.tscn diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 45fa374..6aa7e5c 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://ddr6qtwy1pesd"] -[ext_resource type="Script" uid="uid://cleifuttwn5dw" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[ext_resource type="Script" uid="uid://bv34hd4a2wbit" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_s3fct"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_dmk8h"] diff --git a/examples/projet/.vscode/c_cpp_properties.json b/examples/projet/.vscode/c_cpp_properties.json deleted file mode 100644 index cea4d3f..0000000 --- a/examples/projet/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "configurations": [ - { - "name": "windows-gcc-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "gcc", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "windows-gcc-x64", - "compilerArgs": [ - "" - ] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/examples/projet/.vscode/launch.json b/examples/projet/.vscode/launch.json deleted file mode 100644 index 98513c4..0000000 --- a/examples/projet/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "externalConsole": true, - "cwd": "c:/Users/Tasnime/ComputeShaderStudio/examples/projet", - "program": "c:/Users/Tasnime/ComputeShaderStudio/examples/projet/build/Debug/outDebug", - "MIMode": "gdb", - "miDebuggerPath": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/projet/.vscode/settings.json b/examples/projet/.vscode/settings.json deleted file mode 100644 index fd17536..0000000 --- a/examples/projet/.vscode/settings.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "gcc", - "C_Cpp_Runner.cppCompilerPath": "g++", - "C_Cpp_Runner.debuggerPath": "gdb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false, - "C_Cpp.errorSquiggles": "disabled" -} \ No newline at end of file diff --git a/examples/projet/test.cpp b/examples/projet/test.cpp deleted file mode 100644 index eba89e6..0000000 --- a/examples/projet/test.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#define M_PI 3.14159265358979323846 - -// Color definitions -#define blue1 vec3(0.74, 0, 1.00) -#define blue2 vec3(0.87, 0.98, 1.00) -#define blue3 vec3(1.0, 1.0, 1.0) -#define blue4 vec3(0.953, 0.969, 0.89) -#define red vec3(0.00, 0.00, 1.00) - -// Helper macro -#define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) - -void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - - //Calcule les coordonnées normalisées et la distance depuis le centre de l'écran (r). - vec2 uv = vec2(float(x), float(y)); - vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center - vec2 d = uv - c; - float r = length(d); - - //Définit un facteur d'échelle pour adapter les éléments à la taille de l'écran et une variable du temps - float scale = min(float(WSX), float(WSY)) / 650.0; - float time = float(step) * 0.01; - - // arriere plan noir - vec3 finalColor = vec3(0.0); - - // Normalized direction (for angles) - vec2 dn = r > 0.0 ? d / r : vec2(0.0); - float angle = atan(dn.y, dn.x); - float theta = 180.0 * angle / M_PI; - - //Dessine trois cercles concentriques de différentes tailles. - finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; - - // Dessine un petit point au centre. - finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; - - // Crée une ligne de balayage qui tourne comme un radar, avec un gradient. - if (r < 240.0 * scale) { - float scanAngle = 90.0 * time * M_PI / 180.0; - vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); - float scanDist = dot(dn, scanDir); - float theta0 = 90.0 * time; - float angDiff = mod(theta + theta0, 360.0); - float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); - float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; - finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); - } - - // Segmented outer circle - if (r > 310.0 * scale && r < 316.0 * scale) { - float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * - mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); - finalColor += segmentPattern * blue1; - } - - // Semicircle with opening - if (r > 260.0 * scale && r < 264.0 * scale) { - float opening = 0.5 + 0.2 * cos(time); - if (abs(dn.y) > opening) { - finalColor += 0.7 * blue3; - } - } - // Triangular elements - float radius = (315.0 + 30.0 * sin(time)) * scale; - // Right triangle - if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { - float t = 1.0 - smoothstep(7.0 * scale + d.x - radius, 9.0 * scale + d.x - radius, abs(d.y)); - finalColor += t * blue2; - } - // Left triangle - if (d.x + radius >= 0.0 && d.x + radius <= 8.0 * scale) { - float t = 1.0 - smoothstep(7.0 * scale - d.x - radius, 9.0 * scale - d.x - radius, abs(d.y)); - finalColor += t * blue2; - } - // Bottom triangle - if (d.y - radius >= -8.0 * scale && d.y - radius <= 0.0) { - float t = 1.0 - smoothstep(7.0 * scale + d.y - radius, 9.0 * scale + d.y - radius, abs(d.x)); - finalColor += t * blue2; - } - // Top triangle - if (d.y + radius >= 0.0 && d.y + radius <= 8.0 * scale) { - float t = 1.0 - smoothstep(7.0 * scale - d.y - radius, 9.0 * scale - d.y - radius, abs(d.x)); - finalColor += t * blue2; - } - - // Blips - if (r < 240.0 * scale) { - // Blip 1 - { - float t = time * 0.1; - vec2 pos = c + 130.0 * scale * vec2( - 1.3 * cos(t) + 1.0 * cos(0.1 * t), - 1.0 * sin(t) + 1.4 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); - } - // Blip 2 - { - float t = sin(0.1 * time + 7.0) + 0.2 * time; - vec2 pos = c + 50.0 * scale * vec2( - 1.54 * cos(t) + 1.7 * cos(0.1 * t), - 1.37 * sin(t) + 1.8 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - float R = (8.0 + mod(87.0 * time, 80.0)) * scale; - - float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) - + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) - + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); - - finalColor += blip * red; - } - } - - // Fixed targets with halos - vec2 targetPositions[3] = vec2[]( - c + vec2(0.3, 0.2) * float(WSX) * 0.5, - c + vec2(-0.4, -0.3) * float(WSX) * 0.5, - c + vec2(0.1, -0.5) * float(WSX) * 0.5 - ); - - for (int i = 0; i < 3; i++) { - float targetDist = length(uv - targetPositions[i]); - finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; - } - - int color = (int(clamp(finalColor.r, 0.0, 1.0) * 255.0) << 16) | - (int(clamp(finalColor.g, 0.0, 1.0) * 255.0) << 8) | - int(clamp(finalColor.b, 0.0, 1.0) * 255.0); - - data_0[p] = 0xFF000000 | color; -} \ No newline at end of file diff --git a/examples/projet/test.glsl.import b/examples/projet/test.glsl.import deleted file mode 100644 index 78429ff..0000000 --- a/examples/projet/test.glsl.import +++ /dev/null @@ -1,14 +0,0 @@ -[remap] - -importer="glsl" -type="RDShaderFile" -uid="uid://c0c2dlutu4gln" -path="res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res" - -[deps] - -source_file="res://examples/test/test.glsl" -dest_files=["res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res"] - -[params] - diff --git a/examples/projet/test.tscn b/examples/projet/test.tscn deleted file mode 100644 index fb33c3a..0000000 --- a/examples/projet/test.tscn +++ /dev/null @@ -1,19 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://bhsg8ie7m0n18"] - -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_tfywn"] -[ext_resource type="Script" uid="uid://bv34hd4a2wbit" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_3uxvf"] - -[node name="Test" type="Node2D"] - -[node name="Icon" type="Sprite2D" parent="."] -position = Vector2(625, 361) -scale = Vector2(9.73438, 5.74219) -texture = ExtResource("1_tfywn") - -[node name="ComputeShaderStudio2D" type="Node" parent="Icon" node_paths=PackedStringArray("data")] -script = ExtResource("2_3uxvf") -WSX = 512 -WSY = 512 -glsl_file = "res://examples/projet/test.cpp" -GLSL_code = "" -data = [NodePath("..")] From 6aa50c7e4ae360f1ed991903fe17ec3c4bbd40b9 Mon Sep 17 00:00:00 2001 From: Tasnime66 <168435398+Tasnime66@users.noreply.github.com> Date: Tue, 18 Mar 2025 11:46:09 +0100 Subject: [PATCH 17/17] version finale --- examples/projet/.vscode/c_cpp_properties.json | 18 --- examples/projet/.vscode/launch.json | 24 --- examples/projet/.vscode/settings.json | 60 -------- examples/projet/test.cpp | 140 ------------------ examples/projet/test.glsl.import | 14 -- examples/projet/test.tscn | 19 --- 6 files changed, 275 deletions(-) delete mode 100644 examples/projet/.vscode/c_cpp_properties.json delete mode 100644 examples/projet/.vscode/launch.json delete mode 100644 examples/projet/.vscode/settings.json delete mode 100644 examples/projet/test.cpp delete mode 100644 examples/projet/test.glsl.import delete mode 100644 examples/projet/test.tscn diff --git a/examples/projet/.vscode/c_cpp_properties.json b/examples/projet/.vscode/c_cpp_properties.json deleted file mode 100644 index cea4d3f..0000000 --- a/examples/projet/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "configurations": [ - { - "name": "windows-gcc-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "gcc", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "windows-gcc-x64", - "compilerArgs": [ - "" - ] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/examples/projet/.vscode/launch.json b/examples/projet/.vscode/launch.json deleted file mode 100644 index 98513c4..0000000 --- a/examples/projet/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "externalConsole": true, - "cwd": "c:/Users/Tasnime/ComputeShaderStudio/examples/projet", - "program": "c:/Users/Tasnime/ComputeShaderStudio/examples/projet/build/Debug/outDebug", - "MIMode": "gdb", - "miDebuggerPath": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/projet/.vscode/settings.json b/examples/projet/.vscode/settings.json deleted file mode 100644 index fd17536..0000000 --- a/examples/projet/.vscode/settings.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "gcc", - "C_Cpp_Runner.cppCompilerPath": "g++", - "C_Cpp_Runner.debuggerPath": "gdb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false, - "C_Cpp.errorSquiggles": "disabled" -} \ No newline at end of file diff --git a/examples/projet/test.cpp b/examples/projet/test.cpp deleted file mode 100644 index eba89e6..0000000 --- a/examples/projet/test.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#define M_PI 3.14159265358979323846 - -// Color definitions -#define blue1 vec3(0.74, 0, 1.00) -#define blue2 vec3(0.87, 0.98, 1.00) -#define blue3 vec3(1.0, 1.0, 1.0) -#define blue4 vec3(0.953, 0.969, 0.89) -#define red vec3(0.00, 0.00, 1.00) - -// Helper macro -#define SMOOTH(r, R) (1.0 - smoothstep(R - 1.0, R + 1.0, r)) - -void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - - //Calcule les coordonnées normalisées et la distance depuis le centre de l'écran (r). - vec2 uv = vec2(float(x), float(y)); - vec2 c = vec2(float(WSX) / 2.0, float(WSY) / 2.0); // Center - vec2 d = uv - c; - float r = length(d); - - //Définit un facteur d'échelle pour adapter les éléments à la taille de l'écran et une variable du temps - float scale = min(float(WSX), float(WSY)) / 650.0; - float time = float(step) * 0.01; - - // arriere plan noir - vec3 finalColor = vec3(0.0); - - // Normalized direction (for angles) - vec2 dn = r > 0.0 ? d / r : vec2(0.0); - float angle = atan(dn.y, dn.x); - float theta = 180.0 * angle / M_PI; - - //Dessine trois cercles concentriques de différentes tailles. - finalColor += (SMOOTH(r - 0.5 * scale, 100.0 * scale) - SMOOTH(r + 0.5 * scale, 100.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 0.5 * scale, 165.0 * scale) - SMOOTH(r + 0.5 * scale, 165.0 * scale)) * blue1; - finalColor += (SMOOTH(r - 1.0 * scale, 240.0 * scale) - SMOOTH(r + 1.0 * scale, 240.0 * scale)) * blue4; - - // Dessine un petit point au centre. - finalColor += (SMOOTH(r - 0.5 * scale, 10.0 * scale) - SMOOTH(r + 0.5 * scale, 10.0 * scale)) * blue3; - - // Crée une ligne de balayage qui tourne comme un radar, avec un gradient. - if (r < 240.0 * scale) { - float scanAngle = 90.0 * time * M_PI / 180.0; - vec2 scanDir = vec2(cos(scanAngle), -sin(scanAngle)); - float scanDist = dot(dn, scanDir); - float theta0 = 90.0 * time; - float angDiff = mod(theta + theta0, 360.0); - float gradient = clamp(1.0 - angDiff / 90.0, 0.0, 1.0); - float scanLine = SMOOTH(1.0 - scanDist, 0.03) * 0.75; - finalColor += (scanLine + 0.5 * gradient) * blue3 * smoothstep(240.0 * scale, 220.0 * scale, r); - } - - // Segmented outer circle - if (r > 310.0 * scale && r < 316.0 * scale) { - float segmentPattern = smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0)) * - mix(0.5, 1.0, float(abs(mod(theta, 180.0) - 90.0) > 45.0)); - finalColor += segmentPattern * blue1; - } - - // Semicircle with opening - if (r > 260.0 * scale && r < 264.0 * scale) { - float opening = 0.5 + 0.2 * cos(time); - if (abs(dn.y) > opening) { - finalColor += 0.7 * blue3; - } - } - // Triangular elements - float radius = (315.0 + 30.0 * sin(time)) * scale; - // Right triangle - if (d.x - radius >= -8.0 * scale && d.x - radius <= 0.0) { - float t = 1.0 - smoothstep(7.0 * scale + d.x - radius, 9.0 * scale + d.x - radius, abs(d.y)); - finalColor += t * blue2; - } - // Left triangle - if (d.x + radius >= 0.0 && d.x + radius <= 8.0 * scale) { - float t = 1.0 - smoothstep(7.0 * scale - d.x - radius, 9.0 * scale - d.x - radius, abs(d.y)); - finalColor += t * blue2; - } - // Bottom triangle - if (d.y - radius >= -8.0 * scale && d.y - radius <= 0.0) { - float t = 1.0 - smoothstep(7.0 * scale + d.y - radius, 9.0 * scale + d.y - radius, abs(d.x)); - finalColor += t * blue2; - } - // Top triangle - if (d.y + radius >= 0.0 && d.y + radius <= 8.0 * scale) { - float t = 1.0 - smoothstep(7.0 * scale - d.y - radius, 9.0 * scale - d.y - radius, abs(d.x)); - finalColor += t * blue2; - } - - // Blips - if (r < 240.0 * scale) { - // Blip 1 - { - float t = time * 0.1; - vec2 pos = c + 130.0 * scale * vec2( - 1.3 * cos(t) + 1.0 * cos(0.1 * t), - 1.0 * sin(t) + 1.4 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - finalColor += SMOOTH(blipDist, 3.0 * scale) * vec3(1, 1, 1); - } - // Blip 2 - { - float t = sin(0.1 * time + 7.0) + 0.2 * time; - vec2 pos = c + 50.0 * scale * vec2( - 1.54 * cos(t) + 1.7 * cos(0.1 * t), - 1.37 * sin(t) + 1.8 * cos(0.1 * t) - ); - float blipDist = length(uv - pos); - float R = (8.0 + mod(87.0 * time, 80.0)) * scale; - - float blip = (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(blipDist, 5.0 * scale) - + SMOOTH(6.0 * scale, blipDist) - SMOOTH(8.0 * scale, blipDist) - + smoothstep(max(8.0 * scale, R - 20.0 * scale), R, blipDist) - SMOOTH(R, blipDist); - - finalColor += blip * red; - } - } - - // Fixed targets with halos - vec2 targetPositions[3] = vec2[]( - c + vec2(0.3, 0.2) * float(WSX) * 0.5, - c + vec2(-0.4, -0.3) * float(WSX) * 0.5, - c + vec2(0.1, -0.5) * float(WSX) * 0.5 - ); - - for (int i = 0; i < 3; i++) { - float targetDist = length(uv - targetPositions[i]); - finalColor += red * exp(-50.0 * targetDist / scale) * 0.7; - } - - int color = (int(clamp(finalColor.r, 0.0, 1.0) * 255.0) << 16) | - (int(clamp(finalColor.g, 0.0, 1.0) * 255.0) << 8) | - int(clamp(finalColor.b, 0.0, 1.0) * 255.0); - - data_0[p] = 0xFF000000 | color; -} \ No newline at end of file diff --git a/examples/projet/test.glsl.import b/examples/projet/test.glsl.import deleted file mode 100644 index 78429ff..0000000 --- a/examples/projet/test.glsl.import +++ /dev/null @@ -1,14 +0,0 @@ -[remap] - -importer="glsl" -type="RDShaderFile" -uid="uid://c0c2dlutu4gln" -path="res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res" - -[deps] - -source_file="res://examples/test/test.glsl" -dest_files=["res://.godot/imported/test.glsl-ccd8d19c47d7f1edc36578aab1bf31da.res"] - -[params] - diff --git a/examples/projet/test.tscn b/examples/projet/test.tscn deleted file mode 100644 index fb33c3a..0000000 --- a/examples/projet/test.tscn +++ /dev/null @@ -1,19 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://bhsg8ie7m0n18"] - -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_tfywn"] -[ext_resource type="Script" uid="uid://bv34hd4a2wbit" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_3uxvf"] - -[node name="Test" type="Node2D"] - -[node name="Icon" type="Sprite2D" parent="."] -position = Vector2(625, 361) -scale = Vector2(9.73438, 5.74219) -texture = ExtResource("1_tfywn") - -[node name="ComputeShaderStudio2D" type="Node" parent="Icon" node_paths=PackedStringArray("data")] -script = ExtResource("2_3uxvf") -WSX = 512 -WSY = 512 -glsl_file = "res://examples/projet/test.cpp" -GLSL_code = "" -data = [NodePath("..")]