From c1f63f7f3a3ee99df6e9e57a5cc0998f7c8d3704 Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Wed, 5 Mar 2025 11:25:01 +0100 Subject: [PATCH 01/11] Ajout du dossier de notre projet --- examples/project_SEF/project.c | 0 project.godot | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 examples/project_SEF/project.c diff --git a/examples/project_SEF/project.c b/examples/project_SEF/project.c new file mode 100644 index 0000000..e69de29 diff --git a/project.godot b/project.godot index 725be9c..0436dd7 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.3", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From b9f1930644e0b7ad4adae076d75a89ac3807659a Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Tue, 11 Mar 2025 12:14:55 +0100 Subject: [PATCH 02/11] exemple de bas --- .../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/cells/example_cells.tscn | 4 ++-- examples/example_1.tscn | 4 ++-- examples/example_2.tscn | 4 ++-- examples/example_3.tscn | 6 +++--- examples/example_4.tscn | 2 +- examples/example_5.tscn | 2 +- examples/example_lenia_test.tscn | 6 +++--- examples/example_mandelbrot.gd.uid | 1 + examples/example_mandelbrot.tscn | 6 +++--- examples/example_psycho_seizure.tscn | 4 ++-- examples/{ => project_RainFX}/icon.svg | 0 examples/{ => project_RainFX}/icon.svg.import | 6 +++--- examples/project_RainFX/project.c | 6 ++++++ examples/project_RainFX/rainfx.tscn | 17 +++++++++++++++++ examples/project_SEF/project.c | 0 project.godot | 4 ++-- 20 files changed, 52 insertions(+), 24 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 rename examples/{ => project_RainFX}/icon.svg (100%) rename examples/{ => project_RainFX}/icon.svg.import (75%) create mode 100644 examples/project_RainFX/project.c create mode 100644 examples/project_RainFX/rainfx.tscn delete mode 100644 examples/project_SEF/project.c 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..3c0c8b9 --- /dev/null +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd.uid @@ -0,0 +1 @@ +uid://ctdqncychsdep 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..91b4763 --- /dev/null +++ b/addons/compute_shader_studio/compute_shader_studio_plugin.gd.uid @@ -0,0 +1 @@ +uid://dhln33jbr2byv diff --git a/examples/LabelStepPass.gd.uid b/examples/LabelStepPass.gd.uid new file mode 100644 index 0000000..91652e7 --- /dev/null +++ b/examples/LabelStepPass.gd.uid @@ -0,0 +1 @@ +uid://0ax0xb1gbjof diff --git a/examples/cells/cells.gd.uid b/examples/cells/cells.gd.uid new file mode 100644 index 0000000..e2b076c --- /dev/null +++ b/examples/cells/cells.gd.uid @@ -0,0 +1 @@ +uid://cwp31gi5aca3p diff --git a/examples/cells/example_cells.tscn b/examples/cells/example_cells.tscn index 6959c31..698aee4 100644 --- a/examples/cells/example_cells.tscn +++ b/examples/cells/example_cells.tscn @@ -1,7 +1,7 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_oji6h"] +[ext_resource type="Script" uid="uid://cwp31gi5aca3p" path="res://examples/cells/cells.gd" id="1_dw4h8"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_oji6h"] [node name="Cells" type="Control" node_paths=PackedStringArray("data")] layout_mode = 3 diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 7d67949..73c2acc 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -1,7 +1,7 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_s3fct"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/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..043f0d4 100644 --- a/examples/example_2.tscn +++ b/examples/example_2.tscn @@ -1,7 +1,7 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_j6qu8"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_2cs40"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_j6qu8"] [node name="Example2" type="Node2D"] diff --git a/examples/example_3.tscn b/examples/example_3.tscn index df2b8a6..bc0e714 100644 --- a/examples/example_3.tscn +++ b/examples/example_3.tscn @@ -1,8 +1,8 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_4upxj"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] +[ext_resource type="Script" uid="uid://0ax0xb1gbjof" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_4upxj"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/example_4.tscn b/examples/example_4.tscn index c777972..b5bc5ca 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://ctdqncychsdep" 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..ef11118 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://ctdqncychsdep" 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..b57b50c 100644 --- a/examples/example_lenia_test.tscn +++ b/examples/example_lenia_test.tscn @@ -1,8 +1,8 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="3_orsvs"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_wci4f"] +[ext_resource type="Script" uid="uid://0ax0xb1gbjof" path="res://examples/LabelStepPass.gd" id="2_ndkd3"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/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..51bcfa8 --- /dev/null +++ b/examples/example_mandelbrot.gd.uid @@ -0,0 +1 @@ +uid://b7q2bfveobmmm diff --git a/examples/example_mandelbrot.tscn b/examples/example_mandelbrot.tscn index a5e532c..88a6871 100644 --- a/examples/example_mandelbrot.tscn +++ b/examples/example_mandelbrot.tscn @@ -1,8 +1,8 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_dyrad"] +[ext_resource type="Script" uid="uid://b7q2bfveobmmm" path="res://examples/example_mandelbrot.gd" id="1_5gp20"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_t5cx1"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_dyrad"] [node name="example_mandelbrot" type="Node2D"] script = ExtResource("1_5gp20") diff --git a/examples/example_psycho_seizure.tscn b/examples/example_psycho_seizure.tscn index f1e07d4..c619554 100644 --- a/examples/example_psycho_seizure.tscn +++ b/examples/example_psycho_seizure.tscn @@ -1,7 +1,7 @@ [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="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_urrfs"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_26wk6"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_urrfs"] [node name="exeample_psycho_seizure" type="Node2D"] diff --git a/examples/icon.svg b/examples/project_RainFX/icon.svg similarity index 100% rename from examples/icon.svg rename to examples/project_RainFX/icon.svg diff --git a/examples/icon.svg.import b/examples/project_RainFX/icon.svg.import similarity index 75% rename from examples/icon.svg.import rename to examples/project_RainFX/icon.svg.import index 5daa621..f3da817 100644 --- a/examples/icon.svg.import +++ b/examples/project_RainFX/icon.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://demftcowdd5c6" -path="res://.godot/imported/icon.svg-acd25bcdc80d9b3e751da37b20890fa9.ctex" +path="res://.godot/imported/icon.svg-f3d71014fa0786529dac6a0f25addece.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://examples/icon.svg" -dest_files=["res://.godot/imported/icon.svg-acd25bcdc80d9b3e751da37b20890fa9.ctex"] +source_file="res://examples/project_RainFX/icon.svg" +dest_files=["res://.godot/imported/icon.svg-f3d71014fa0786529dac6a0f25addece.ctex"] [params] diff --git a/examples/project_RainFX/project.c b/examples/project_RainFX/project.c new file mode 100644 index 0000000..ae789b4 --- /dev/null +++ b/examples/project_RainFX/project.c @@ -0,0 +1,6 @@ + +void main() { + uint pos = gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * WSX; + int color = 0xFFFF0000; + data_0[pos]=color; +} diff --git a/examples/project_RainFX/rainfx.tscn b/examples/project_RainFX/rainfx.tscn new file mode 100644 index 0000000..b554c07 --- /dev/null +++ b/examples/project_RainFX/rainfx.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://bpmms2lv1wfgk"] + +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_q8eks"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_k6v1r"] + +[node name="Rainfx" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_q8eks") +glsl_file = "res://examples/project_RainFX/project.c" +GLSL_code = "" +data = [NodePath("../Icon")] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(518, 300) +scale = Vector2(2.70313, 2.1875) +texture = ExtResource("2_k6v1r") diff --git a/examples/project_SEF/project.c b/examples/project_SEF/project.c deleted file mode 100644 index e69de29..0000000 diff --git a/project.godot b/project.godot index 0436dd7..1973aaf 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.2", "Forward Plus") +run/main_scene="uid://bpmms2lv1wfgk" +config/features=PackedStringArray("4.4", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From c68613d233eb78c81eca3ab01a196f0f27853f4b Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Sat, 15 Mar 2025 11:46:42 +0100 Subject: [PATCH 03/11] Modifications basic --- examples/cells/example_cells.tscn | 2 +- examples/circle_project/circle.cpp | 31 +++++++++++++++++++ .../circle.tscn} | 14 ++++----- .../icon.svg | 0 .../icon.svg.import | 6 ++-- examples/example_1.tscn | 2 +- examples/example_2.tscn | 2 +- examples/example_3.tscn | 2 +- examples/example_lenia_test.tscn | 2 +- examples/example_mandelbrot.tscn | 2 +- examples/example_psycho_seizure.tscn | 2 +- examples/project_RainFX/project.c | 6 ---- 12 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 examples/circle_project/circle.cpp rename examples/{project_RainFX/rainfx.tscn => circle_project/circle.tscn} (65%) rename examples/{project_RainFX => circle_project}/icon.svg (100%) rename examples/{project_RainFX => circle_project}/icon.svg.import (75%) delete mode 100644 examples/project_RainFX/project.c diff --git a/examples/cells/example_cells.tscn b/examples/cells/example_cells.tscn index 698aee4..083951f 100644 --- a/examples/cells/example_cells.tscn +++ b/examples/cells/example_cells.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://cutxgtalwsp6q"] [ext_resource type="Script" uid="uid://cwp31gi5aca3p" path="res://examples/cells/cells.gd" id="1_dw4h8"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_oji6h"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_oji6h"] [node name="Cells" type="Control" node_paths=PackedStringArray("data")] layout_mode = 3 diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp new file mode 100644 index 0000000..bcee147 --- /dev/null +++ b/examples/circle_project/circle.cpp @@ -0,0 +1,31 @@ +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + float centerX = WSX / 2.0; + float centerY = WSY / 2.0; + float radius = WSX / 4.0; + + float dx = float(x) - centerX; + float dy = float(y) - centerY; + + float angle = step * 0.05; + float cosA = cos(angle); + float sinA = sin(angle); + + float rotatedX = cosA * dx - sinA * dy; + float rotatedY = sinA * dx + cosA * dy; + + float dist = sqrt(rotatedX * rotatedX + rotatedY * rotatedY); + + float intensity = exp(-pow((dist - radius) / 10.0, 2.0)); + float twistFactor = sin(dist * 0.1 + step * 0.02); + + int red = int(255.0 * intensity); + int green = int(150.0 * intensity * twistFactor); + int blue = int(255.0 * (1.0 - intensity)); + int alpha = 255; + + data_0[p] = (alpha << 24) | (red << 16) | (green << 8) | blue; +} diff --git a/examples/project_RainFX/rainfx.tscn b/examples/circle_project/circle.tscn similarity index 65% rename from examples/project_RainFX/rainfx.tscn rename to examples/circle_project/circle.tscn index b554c07..cbdac8a 100644 --- a/examples/project_RainFX/rainfx.tscn +++ b/examples/circle_project/circle.tscn @@ -1,17 +1,17 @@ [gd_scene load_steps=3 format=3 uid="uid://bpmms2lv1wfgk"] -[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_q8eks"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_k6v1r"] +[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_htga1"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_l2oj0"] [node name="Rainfx" type="Node2D"] [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] -script = ExtResource("1_q8eks") -glsl_file = "res://examples/project_RainFX/project.c" +script = ExtResource("1_htga1") +glsl_file = "res://examples/circle_project/circle.cpp" GLSL_code = "" data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(518, 300) -scale = Vector2(2.70313, 2.1875) -texture = ExtResource("2_k6v1r") +position = Vector2(600, 325) +scale = Vector2(3.58008, 3.17676) +texture = ExtResource("2_l2oj0") diff --git a/examples/project_RainFX/icon.svg b/examples/circle_project/icon.svg similarity index 100% rename from examples/project_RainFX/icon.svg rename to examples/circle_project/icon.svg diff --git a/examples/project_RainFX/icon.svg.import b/examples/circle_project/icon.svg.import similarity index 75% rename from examples/project_RainFX/icon.svg.import rename to examples/circle_project/icon.svg.import index f3da817..4b8f50c 100644 --- a/examples/project_RainFX/icon.svg.import +++ b/examples/circle_project/icon.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://demftcowdd5c6" -path="res://.godot/imported/icon.svg-f3d71014fa0786529dac6a0f25addece.ctex" +path="res://.godot/imported/icon.svg-fee4a03ef203a88ee6af7ad51a73f62f.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://examples/project_RainFX/icon.svg" -dest_files=["res://.godot/imported/icon.svg-f3d71014fa0786529dac6a0f25addece.ctex"] +source_file="res://examples/circle_project/icon.svg" +dest_files=["res://.godot/imported/icon.svg-fee4a03ef203a88ee6af7ad51a73f62f.ctex"] [params] diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 73c2acc..f7c2b98 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=3 uid="uid://ddr6qtwy1pesd"] [ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_s3fct"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/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 043f0d4..5e53a98 100644 --- a/examples/example_2.tscn +++ b/examples/example_2.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://cotswmubn7uvm"] [ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_2cs40"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_j6qu8"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_j6qu8"] [node name="Example2" type="Node2D"] diff --git a/examples/example_3.tscn b/examples/example_3.tscn index bc0e714..7b7c77e 100644 --- a/examples/example_3.tscn +++ b/examples/example_3.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] [ext_resource type="Script" uid="uid://0ax0xb1gbjof" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_4upxj"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_4upxj"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/example_lenia_test.tscn b/examples/example_lenia_test.tscn index b57b50c..a4782f1 100644 --- a/examples/example_lenia_test.tscn +++ b/examples/example_lenia_test.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_wci4f"] [ext_resource type="Script" uid="uid://0ax0xb1gbjof" path="res://examples/LabelStepPass.gd" id="2_ndkd3"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="3_orsvs"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="3_orsvs"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/example_mandelbrot.tscn b/examples/example_mandelbrot.tscn index 88a6871..15aa503 100644 --- a/examples/example_mandelbrot.tscn +++ b/examples/example_mandelbrot.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" uid="uid://b7q2bfveobmmm" path="res://examples/example_mandelbrot.gd" id="1_5gp20"] [ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_t5cx1"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_dyrad"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_dyrad"] [node name="example_mandelbrot" type="Node2D"] script = ExtResource("1_5gp20") diff --git a/examples/example_psycho_seizure.tscn b/examples/example_psycho_seizure.tscn index c619554..5a46685 100644 --- a/examples/example_psycho_seizure.tscn +++ b/examples/example_psycho_seizure.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://cdtqwwdxs783m"] [ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_26wk6"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/project_RainFX/icon.svg" id="2_urrfs"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_urrfs"] [node name="exeample_psycho_seizure" type="Node2D"] diff --git a/examples/project_RainFX/project.c b/examples/project_RainFX/project.c deleted file mode 100644 index ae789b4..0000000 --- a/examples/project_RainFX/project.c +++ /dev/null @@ -1,6 +0,0 @@ - -void main() { - uint pos = gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * WSX; - int color = 0xFFFF0000; - data_0[pos]=color; -} From da34127b9c1376e1ede1735e6a55b2cb9b1cec38 Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Sun, 16 Mar 2025 14:07:03 +0100 Subject: [PATCH 04/11] =?UTF-8?q?Ajout=20d'une=20sph=C3=A8re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/circle_project/circle.cpp | 77 +++++++++++++++++++---------- examples/circle_project/circle.tscn | 4 +- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index bcee147..9ead789 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -1,31 +1,54 @@ -void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - - float centerX = WSX / 2.0; - float centerY = WSY / 2.0; - float radius = WSX / 4.0; - - float dx = float(x) - centerX; - float dy = float(y) - centerY; - - float angle = step * 0.05; - float cosA = cos(angle); - float sinA = sin(angle); - - float rotatedX = cosA * dx - sinA * dy; - float rotatedY = sinA * dx + cosA * dy; +float PI = 3.14159; - float dist = sqrt(rotatedX * rotatedX + rotatedY * rotatedY); - - float intensity = exp(-pow((dist - radius) / 10.0, 2.0)); - float twistFactor = sin(dist * 0.1 + step * 0.02); +float sdSphere(vec3 p, float s) { + return length(p) - s; +} - int red = int(255.0 * intensity); - int green = int(150.0 * intensity * twistFactor); - int blue = int(255.0 * (1.0 - intensity)); - int alpha = 255; +int packARGB(vec3 c) { + int R = int(clamp(c.x, 0.0, 1.0) * 255.0); + int G = int(clamp(c.y, 0.0, 1.0) * 255.0); + int B = int(clamp(c.z, 0.0, 1.0) * 255.0); + int A = 255; + return (A << 24) | (R << 16) | (G << 8) | B; +} - data_0[p] = (alpha << 24) | (red << 16) | (green << 8) | blue; +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + if(x >= WSX || y >= WSY) return; + uint index = x + y * WSX; + + vec2 fragCoord = vec2(float(x), float(y)); + vec2 iResolution = vec2(float(WSX), float(WSY)); + float t = float(step) * 0.01; + + vec2 uv = (fragCoord - 0.5 * iResolution) / iResolution.y; + vec3 col = vec3(0.0); + vec3 camPos = vec3(0.0, 0.0, 3.5); + vec3 rayDir = normalize(vec3(uv, -1.0)); + float depth = 0.0; + vec3 p = vec3(0.0); + float d = 0.0; + + for (int i = 0; i < 50; i++){ + p = camPos + depth * rayDir; + d = sdSphere(p, 1.25); + depth += d; + if (d < 0.001 || depth > 10.0) break; + } + + if (d > 10.0) { + col = vec3(0.0); + } else { + float theta = atan(p.x, p.z); + float phi = acos(p.y / length(p)); + float wireDelta = PI / 18.0; + float wireWidth = 0.02; + float colTheta = smoothstep(wireWidth, 0.0, abs(mod(theta, wireDelta) - wireDelta/2.0)); + float colPhi = smoothstep(wireWidth, 0.0, abs(mod(phi, wireDelta) - wireDelta/2.0)); + col += vec3(max(colTheta, colPhi)); + } + + col = mix(5.5 * col, vec3(0.0), smoothstep(0.0, 3.6, depth)); + data_0[index] = packARGB(col); } diff --git a/examples/circle_project/circle.tscn b/examples/circle_project/circle.tscn index cbdac8a..abf310a 100644 --- a/examples/circle_project/circle.tscn +++ b/examples/circle_project/circle.tscn @@ -12,6 +12,6 @@ GLSL_code = "" data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(600, 325) -scale = Vector2(3.58008, 3.17676) +position = Vector2(558, 313) +scale = Vector2(5.07129, 4.26807) texture = ExtResource("2_l2oj0") From 05f497a41004addaacc33e883277f54be4a9e5dd Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Sun, 16 Mar 2025 15:28:45 +0100 Subject: [PATCH 05/11] modif --- examples/circle_project/circle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index 9ead789..da020a9 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -51,4 +51,4 @@ void main() { col = mix(5.5 * col, vec3(0.0), smoothstep(0.0, 3.6, depth)); data_0[index] = packARGB(col); -} +} \ No newline at end of file From e9a6336a39096d7ce7cd27ebe997322523edaab8 Mon Sep 17 00:00:00 2001 From: ECHERARHIHAMZA Date: Sun, 16 Mar 2025 15:30:46 +0100 Subject: [PATCH 06/11] Commentaire --- examples/circle_project/circle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index da020a9..5df4fc5 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -3,7 +3,7 @@ float PI = 3.14159; float sdSphere(vec3 p, float s) { return length(p) - s; } - +//hamza int packARGB(vec3 c) { int R = int(clamp(c.x, 0.0, 1.0) * 255.0); int G = int(clamp(c.y, 0.0, 1.0) * 255.0); From ccb3a2914d18c3af1e1d28c290e186954d7ca5fa Mon Sep 17 00:00:00 2001 From: ECHERARHIHAMZA Date: Sun, 16 Mar 2025 15:47:28 +0100 Subject: [PATCH 07/11] ajout rotation normale --- examples/circle_project/circle.cpp | 24 ++++++++++++++++++++++-- examples/circle_project/circle.tscn | 5 +++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index 5df4fc5..90f4762 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -1,9 +1,16 @@ float PI = 3.14159; +// Fonction de rotation 2D : retourne une matrice de rotation pour un angle donné +mat2 rotation(float rad) { + return mat2(cos(rad), sin(rad), -sin(rad), cos(rad)); +} + +// Fonction SDF pour une sphère : calcule la distance signée d'un point à la surface d'une sphère de rayon s float sdSphere(vec3 p, float s) { return length(p) - s; } -//hamza + +// Convertit un vecteur couleur (composantes entre 0 et 1) en entier ARGB 32 bits int packARGB(vec3 c) { int R = int(clamp(c.x, 0.0, 1.0) * 255.0); int G = int(clamp(c.y, 0.0, 1.0) * 255.0); @@ -13,33 +20,45 @@ int packARGB(vec3 c) { } void main() { + // Récupération des coordonnées du pixel uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; if(x >= WSX || y >= WSY) return; uint index = x + y * WSX; + // Définition de la résolution et du pixel courant vec2 fragCoord = vec2(float(x), float(y)); vec2 iResolution = vec2(float(WSX), float(WSY)); + + // t est un facteur de temps calculé à partir de 'step' float t = float(step) * 0.01; + // uv : coordonnées normalisées centrées sur l'écran vec2 uv = (fragCoord - 0.5 * iResolution) / iResolution.y; + vec3 col = vec3(0.0); vec3 camPos = vec3(0.0, 0.0, 3.5); + // Direction du rayon issu du pixel vec3 rayDir = normalize(vec3(uv, -1.0)); float depth = 0.0; vec3 p = vec3(0.0); float d = 0.0; + // Raymarching : on lance un rayon depuis la caméra et on avance jusqu'à toucher la sphère for (int i = 0; i < 50; i++){ p = camPos + depth * rayDir; + // On applique une rotation sur le plan xz de p pour faire tourner la scène + p.xz = rotation(t) * p.xz; d = sdSphere(p, 1.25); depth += d; - if (d < 0.001 || depth > 10.0) break; + if(d < 0.001 || depth > 10.0) break; } + // Si le rayon n'a pas touché la sphère, la couleur est noire if (d > 10.0) { col = vec3(0.0); } else { + // Calcul d'un motif wireframe sur la surface de la sphère float theta = atan(p.x, p.z); float phi = acos(p.y / length(p)); float wireDelta = PI / 18.0; @@ -49,6 +68,7 @@ void main() { col += vec3(max(colTheta, colPhi)); } + // Mix final avec du noir selon la profondeur pour atténuer l'effet col = mix(5.5 * col, vec3(0.0), smoothstep(0.0, 3.6, depth)); data_0[index] = packARGB(col); } \ No newline at end of file diff --git a/examples/circle_project/circle.tscn b/examples/circle_project/circle.tscn index abf310a..ae2946e 100644 --- a/examples/circle_project/circle.tscn +++ b/examples/circle_project/circle.tscn @@ -4,6 +4,7 @@ [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_l2oj0"] [node name="Rainfx" type="Node2D"] +position = Vector2(-1608, -548) [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] script = ExtResource("1_htga1") @@ -12,6 +13,6 @@ GLSL_code = "" data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(558, 313) -scale = Vector2(5.07129, 4.26807) +position = Vector2(2205, 906) +scale = Vector2(3.56448, 3.25) texture = ExtResource("2_l2oj0") From 6300d1f8755782a80d9dc74c6aa544ec74b2dda2 Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Mon, 17 Mar 2025 08:50:32 +0100 Subject: [PATCH 08/11] =?UTF-8?q?Rotation=20avec=20diff=C3=A9rente=20direc?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/circle_project/circle.cpp | 22 +++++----------------- examples/circle_project/circle.tscn | 5 ++--- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index 90f4762..5edc85d 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -1,16 +1,13 @@ float PI = 3.14159; -// Fonction de rotation 2D : retourne une matrice de rotation pour un angle donné mat2 rotation(float rad) { return mat2(cos(rad), sin(rad), -sin(rad), cos(rad)); } -// Fonction SDF pour une sphère : calcule la distance signée d'un point à la surface d'une sphère de rayon s float sdSphere(vec3 p, float s) { return length(p) - s; } -// Convertit un vecteur couleur (composantes entre 0 et 1) en entier ARGB 32 bits int packARGB(vec3 c) { int R = int(clamp(c.x, 0.0, 1.0) * 255.0); int G = int(clamp(c.y, 0.0, 1.0) * 255.0); @@ -20,45 +17,37 @@ int packARGB(vec3 c) { } void main() { - // Récupération des coordonnées du pixel uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; if(x >= WSX || y >= WSY) return; uint index = x + y * WSX; - // Définition de la résolution et du pixel courant vec2 fragCoord = vec2(float(x), float(y)); vec2 iResolution = vec2(float(WSX), float(WSY)); - - // t est un facteur de temps calculé à partir de 'step' float t = float(step) * 0.01; - // uv : coordonnées normalisées centrées sur l'écran vec2 uv = (fragCoord - 0.5 * iResolution) / iResolution.y; - vec3 col = vec3(0.0); vec3 camPos = vec3(0.0, 0.0, 3.5); - // Direction du rayon issu du pixel vec3 rayDir = normalize(vec3(uv, -1.0)); float depth = 0.0; vec3 p = vec3(0.0); float d = 0.0; - // Raymarching : on lance un rayon depuis la caméra et on avance jusqu'à toucher la sphère + // Raymarching loop with two independent rotations: + // Rotation in xz plane with angle t and in yz plane with a different angle. for (int i = 0; i < 50; i++){ p = camPos + depth * rayDir; - // On applique une rotation sur le plan xz de p pour faire tourner la scène - p.xz = rotation(t) * p.xz; + p.xz = rotation(t) * p.xz; // Rotation sur le plan xz + p.yz = rotation(-t * 1.2) * p.yz; // Rotation sur le plan yz (différente vitesse et direction) d = sdSphere(p, 1.25); depth += d; - if(d < 0.001 || depth > 10.0) break; + if (d < 0.001 || depth > 10.0) break; } - // Si le rayon n'a pas touché la sphère, la couleur est noire if (d > 10.0) { col = vec3(0.0); } else { - // Calcul d'un motif wireframe sur la surface de la sphère float theta = atan(p.x, p.z); float phi = acos(p.y / length(p)); float wireDelta = PI / 18.0; @@ -68,7 +57,6 @@ void main() { col += vec3(max(colTheta, colPhi)); } - // Mix final avec du noir selon la profondeur pour atténuer l'effet col = mix(5.5 * col, vec3(0.0), smoothstep(0.0, 3.6, depth)); data_0[index] = packARGB(col); } \ No newline at end of file diff --git a/examples/circle_project/circle.tscn b/examples/circle_project/circle.tscn index ae2946e..f8c85f3 100644 --- a/examples/circle_project/circle.tscn +++ b/examples/circle_project/circle.tscn @@ -4,7 +4,6 @@ [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_l2oj0"] [node name="Rainfx" type="Node2D"] -position = Vector2(-1608, -548) [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] script = ExtResource("1_htga1") @@ -13,6 +12,6 @@ GLSL_code = "" data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(2205, 906) -scale = Vector2(3.56448, 3.25) +position = Vector2(552, 324) +scale = Vector2(5.28736, 4.38342) texture = ExtResource("2_l2oj0") From cdb4a38140b846aa53272823dae86284751b71f6 Mon Sep 17 00:00:00 2001 From: ECHERARHIHAMZA Date: Mon, 17 Mar 2025 12:38:20 +0100 Subject: [PATCH 09/11] version_v1 --- examples/circle_project/circle.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index 5edc85d..8d0ce82 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -27,6 +27,15 @@ void main() { float t = float(step) * 0.01; vec2 uv = (fragCoord - 0.5 * iResolution) / iResolution.y; + + // Calcul du centre de l'écran et de la direction de la souris + vec2 screenCenter = 0.5 * iResolution; + float mouseDir = atan(float(mousey) - screenCenter.y, float(mousex) - screenCenter.x); + + // Angle final = rotation intrinsèque + direction de la souris + float rotAngleXZ = t + mouseDir; // Rotation dans le plan xz + float rotAngleYZ = -t * 1.2 + mouseDir; // Rotation dans le plan yz avec une vitesse différente + vec3 col = vec3(0.0); vec3 camPos = vec3(0.0, 0.0, 3.5); vec3 rayDir = normalize(vec3(uv, -1.0)); @@ -34,12 +43,10 @@ void main() { vec3 p = vec3(0.0); float d = 0.0; - // Raymarching loop with two independent rotations: - // Rotation in xz plane with angle t and in yz plane with a different angle. for (int i = 0; i < 50; i++){ p = camPos + depth * rayDir; - p.xz = rotation(t) * p.xz; // Rotation sur le plan xz - p.yz = rotation(-t * 1.2) * p.yz; // Rotation sur le plan yz (différente vitesse et direction) + p.xz = rotation(rotAngleXZ) * p.xz; + p.yz = rotation(rotAngleYZ) * p.yz; d = sdSphere(p, 1.25); depth += d; if (d < 0.001 || depth > 10.0) break; From 337a447289776498fa960b1ff354482544629c07 Mon Sep 17 00:00:00 2001 From: ECHERARHIHAMZA Date: Tue, 18 Mar 2025 00:28:24 +0100 Subject: [PATCH 10/11] version final --- examples/circle_project/circle.cpp | 69 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/examples/circle_project/circle.cpp b/examples/circle_project/circle.cpp index 8d0ce82..8ec5213 100644 --- a/examples/circle_project/circle.cpp +++ b/examples/circle_project/circle.cpp @@ -1,69 +1,102 @@ +/* + * Définition de la constante PI utilisée pour les calculs trigonométriques. + */ float PI = 3.14159; +/* + * Fonction qui retourne une matrice de rotation 2D autour de l'origine + * en fonction d'un angle donné en radians. + */ mat2 rotation(float rad) { return mat2(cos(rad), sin(rad), -sin(rad), cos(rad)); } +/* + * Fonction qui calcule la distance signée d'un point `p` à la surface d'une sphère de rayon `s`. + * La distance est positive à l'extérieur de la sphère et négative à l'intérieur. + */ float sdSphere(vec3 p, float s) { return length(p) - s; } +/* + * Fonction qui encode une couleur (vec3) en un entier au format ARGB (32 bits). + * Les composantes RGB sont clampées entre 0 et 1, puis converties en valeurs entières (0-255). + */ int packARGB(vec3 c) { int R = int(clamp(c.x, 0.0, 1.0) * 255.0); int G = int(clamp(c.y, 0.0, 1.0) * 255.0); int B = int(clamp(c.z, 0.0, 1.0) * 255.0); - int A = 255; + int A = 255; // Alpha toujours à 255 (opaque) return (A << 24) | (R << 16) | (G << 8) | B; } void main() { + // Récupération des coordonnées du thread en cours d'exécution uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; + + // Vérification des limites de l'écran if(x >= WSX || y >= WSY) return; + + // Calcul de l'index du pixel dans le buffer de sortie uint index = x + y * WSX; + // Coordonnées du pixel en espace normalisé (0,0) en bas à gauche vec2 fragCoord = vec2(float(x), float(y)); vec2 iResolution = vec2(float(WSX), float(WSY)); - float t = float(step) * 0.01; + float t = float(step) * 0.01; // Temps écoulé normalisé + // Normalisation des coordonnées UV (-1 à 1 sur l'axe y) vec2 uv = (fragCoord - 0.5 * iResolution) / iResolution.y; // Calcul du centre de l'écran et de la direction de la souris vec2 screenCenter = 0.5 * iResolution; float mouseDir = atan(float(mousey) - screenCenter.y, float(mousex) - screenCenter.x); - // Angle final = rotation intrinsèque + direction de la souris + // Application des rotations en fonction du temps et de la souris float rotAngleXZ = t + mouseDir; // Rotation dans le plan xz - float rotAngleYZ = -t * 1.2 + mouseDir; // Rotation dans le plan yz avec une vitesse différente + float rotAngleYZ = -t * 1.2 + mouseDir; // Rotation dans le plan yz avec un facteur d'ajustement + // Initialisation de la couleur de sortie et des paramètres de la caméra vec3 col = vec3(0.0); - vec3 camPos = vec3(0.0, 0.0, 3.5); - vec3 rayDir = normalize(vec3(uv, -1.0)); - float depth = 0.0; + vec3 camPos = vec3(0.0, 0.0, 3.5); // Position de la caméra + vec3 rayDir = normalize(vec3(uv, -1.0)); // Direction du rayon normalisé + float depth = 0.0; // Distance parcourue par le rayon vec3 p = vec3(0.0); float d = 0.0; - for (int i = 0; i < 50; i++){ - p = camPos + depth * rayDir; - p.xz = rotation(rotAngleXZ) * p.xz; - p.yz = rotation(rotAngleYZ) * p.yz; - d = sdSphere(p, 1.25); - depth += d; - if (d < 0.001 || depth > 10.0) break; + // Boucle de lancer de rayon (Raymarching) pour estimer l'intersection avec la sphère + for (int i = 0; i < 50; i++) { + p = camPos + depth * rayDir; // Calcul de la position actuelle du rayon + p.xz = rotation(rotAngleXZ) * p.xz; // Rotation sur l'axe XZ + p.yz = rotation(rotAngleYZ) * p.yz; // Rotation sur l'axe YZ + d = sdSphere(p, 1.25); // Calcul de la distance signée à la sphère + depth += d; // Avancement du rayon + if (d < 0.001 || depth > 10.0) break; // Arrêt si trop proche ou trop loin } + // Détermination de la couleur finale selon la profondeur atteinte if (d > 10.0) { - col = vec3(0.0); + col = vec3(0.0); // Fond noir si aucune intersection } else { + // Calcul des coordonnées sphériques de l'intersection float theta = atan(p.x, p.z); float phi = acos(p.y / length(p)); - float wireDelta = PI / 18.0; - float wireWidth = 0.02; + + // Paramètres de l'effet de quadrillage + float wireDelta = PI / 18.0; // Distance entre les lignes du quadrillage + float wireWidth = 0.02; // Largeur des lignes + + // Calcul de la couleur en fonction du quadrillage float colTheta = smoothstep(wireWidth, 0.0, abs(mod(theta, wireDelta) - wireDelta/2.0)); float colPhi = smoothstep(wireWidth, 0.0, abs(mod(phi, wireDelta) - wireDelta/2.0)); col += vec3(max(colTheta, colPhi)); } + // Application d'un effet de profondeur pour assombrir avec la distance col = mix(5.5 * col, vec3(0.0), smoothstep(0.0, 3.6, depth)); + + // Stockage de la couleur dans le buffer de sortie data_0[index] = packARGB(col); -} \ No newline at end of file +} From 7bdccf1d927aecafa66f2b6145e750be3450a9bf Mon Sep 17 00:00:00 2001 From: Faraji Anass Date: Tue, 18 Mar 2025 09:14:42 +0100 Subject: [PATCH 11/11] =?UTF-8?q?Derni=C3=A8re=20modification=20(Version?= =?UTF-8?q?=20Finale)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/{circle_project => WireSphere}/icon.svg | 0 examples/{circle_project => WireSphere}/icon.svg.import | 6 +++--- .../circle.cpp => WireSphere/wireSphere.cpp} | 0 .../circle.tscn => WireSphere/wireSphere.tscn} | 6 +++--- project.godot | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename examples/{circle_project => WireSphere}/icon.svg (100%) rename examples/{circle_project => WireSphere}/icon.svg.import (75%) rename examples/{circle_project/circle.cpp => WireSphere/wireSphere.cpp} (100%) rename examples/{circle_project/circle.tscn => WireSphere/wireSphere.tscn} (65%) diff --git a/examples/circle_project/icon.svg b/examples/WireSphere/icon.svg similarity index 100% rename from examples/circle_project/icon.svg rename to examples/WireSphere/icon.svg diff --git a/examples/circle_project/icon.svg.import b/examples/WireSphere/icon.svg.import similarity index 75% rename from examples/circle_project/icon.svg.import rename to examples/WireSphere/icon.svg.import index 4b8f50c..0af654d 100644 --- a/examples/circle_project/icon.svg.import +++ b/examples/WireSphere/icon.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://demftcowdd5c6" -path="res://.godot/imported/icon.svg-fee4a03ef203a88ee6af7ad51a73f62f.ctex" +path="res://.godot/imported/icon.svg-77bc4927ce52de7de2571412d91961de.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://examples/circle_project/icon.svg" -dest_files=["res://.godot/imported/icon.svg-fee4a03ef203a88ee6af7ad51a73f62f.ctex"] +source_file="res://examples/WireSphere/icon.svg" +dest_files=["res://.godot/imported/icon.svg-77bc4927ce52de7de2571412d91961de.ctex"] [params] diff --git a/examples/circle_project/circle.cpp b/examples/WireSphere/wireSphere.cpp similarity index 100% rename from examples/circle_project/circle.cpp rename to examples/WireSphere/wireSphere.cpp diff --git a/examples/circle_project/circle.tscn b/examples/WireSphere/wireSphere.tscn similarity index 65% rename from examples/circle_project/circle.tscn rename to examples/WireSphere/wireSphere.tscn index f8c85f3..3957193 100644 --- a/examples/circle_project/circle.tscn +++ b/examples/WireSphere/wireSphere.tscn @@ -1,13 +1,13 @@ [gd_scene load_steps=3 format=3 uid="uid://bpmms2lv1wfgk"] -[ext_resource type="Script" uid="uid://ctdqncychsdep" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_htga1"] -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/circle_project/icon.svg" id="2_l2oj0"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_htga1"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/WireSphere/icon.svg" id="2_l2oj0"] [node name="Rainfx" type="Node2D"] [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] script = ExtResource("1_htga1") -glsl_file = "res://examples/circle_project/circle.cpp" +glsl_file = "res://examples/WireSphere/wireSphere.cpp" GLSL_code = "" data = [NodePath("../Icon")] diff --git a/project.godot b/project.godot index 1973aaf..e41abd7 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="uid://bpmms2lv1wfgk" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins]