From 6209b0ec8c09b408650a06d410f0e52878011942 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Wed, 5 Mar 2025 11:25:16 +0100 Subject: [PATCH 01/37] creation du projet --- examples/heart/heart.cpp | 0 examples/heart/heart.tscn | 0 project.godot | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 examples/heart/heart.cpp create mode 100644 examples/heart/heart.tscn diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp new file mode 100644 index 0000000..e69de29 diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn new file mode 100644 index 0000000..e69de29 diff --git a/project.godot b/project.godot index 725be9c..f0250a9 100644 --- a/project.godot +++ b/project.godot @@ -17,4 +17,4 @@ config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] -enabled=PackedStringArray("res://addons/compute_shader_studio/plugin.cfg") +enabled=PackedStringArray() From 7040de86333999261f6cb79a583d912dec545170 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Tue, 11 Mar 2025 10:49:39 +0100 Subject: [PATCH 02/37] test de git --- examples/heart/heart.cpp | 1 + examples/heart/heart.tscn | 0 2 files changed, 1 insertion(+) create mode 100644 examples/heart/heart.cpp create mode 100644 examples/heart/heart.tscn diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp new file mode 100644 index 0000000..a0140ee --- /dev/null +++ b/examples/heart/heart.cpp @@ -0,0 +1 @@ +// c'est un test de git \ No newline at end of file diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn new file mode 100644 index 0000000..e69de29 From ad724865d81ebc8fc0c19d3b994fb32ba784e0c9 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Tue, 11 Mar 2025 10:55:34 +0100 Subject: [PATCH 03/37] test 2 --- examples/example_1.tscn | 2 +- examples/example_2.tscn | 2 +- examples/example_5.tscn | 2 +- examples/example_lenia_test.tscn | 4 ++-- examples/example_mandelbrot.tscn | 4 ++-- examples/example_psycho_seizure.tscn | 2 +- examples/heart/heart.cpp | 3 ++- project.godot | 4 ++-- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 88ce9e3..7d67949 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://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[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"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_dmk8h"] diff --git a/examples/example_2.tscn b/examples/example_2.tscn index a843389..766e825 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_2cs40"] +[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"] [node name="Example2" type="Node2D"] diff --git a/examples/example_5.tscn b/examples/example_5.tscn index b1d6e72..43aa420 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_cogap"] +[ext_resource type="Script" 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 118ec4d..6c2caef 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_wci4f"] -[ext_resource type="Script" uid="uid://jw3o2qu3a0pl" path="res://examples/LabelStepPass.gd" id="2_ndkd3"] +[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"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/example_mandelbrot.tscn b/examples/example_mandelbrot.tscn index 1b0fb27..a5e532c 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" uid="uid://bib00xk6p8oo4" path="res://examples/example_mandelbrot.gd" id="1_5gp20"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_t5cx1"] +[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"] [node name="example_mandelbrot" type="Node2D"] diff --git a/examples/example_psycho_seizure.tscn b/examples/example_psycho_seizure.tscn index 760210b..f1e07d4 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_26wk6"] +[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"] [node name="exeample_psycho_seizure" type="Node2D"] diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index a0140ee..ceeb563 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1 +1,2 @@ -// c'est un test de git \ No newline at end of file +// c'est un test de git +//test de git diff --git a/project.godot b/project.godot index 1617345..f0250a9 100644 --- a/project.godot +++ b/project.godot @@ -12,9 +12,9 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] -enabled=PackedStringArray("res://addons/compute_shader_studio/plugin.cfg") +enabled=PackedStringArray() From 4ea052fd4f7e923c7fc266e56536c6a9aaaa8665 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Tue, 11 Mar 2025 10:57:14 +0100 Subject: [PATCH 04/37] okkchange --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..f912847 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x86", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/MinGW/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x86", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c4e333d --- /dev/null +++ b/.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/dihia/Documents/GitHub/ComputeShaderStudio/examples/heart", + "program": "c:/Users/dihia/Documents/GitHub/ComputeShaderStudio/examples/heart/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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "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 +} \ No newline at end of file From cbeb739b22b71dd8967f126f823f801841fc677b Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Tue, 11 Mar 2025 11:01:17 +0100 Subject: [PATCH 05/37] rien1 --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..f912847 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x86", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/MinGW/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x86", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c4e333d --- /dev/null +++ b/.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/dihia/Documents/GitHub/ComputeShaderStudio/examples/heart", + "program": "c:/Users/dihia/Documents/GitHub/ComputeShaderStudio/examples/heart/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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "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 +} \ No newline at end of file From 8d8be74ad6dedf54a8136404fde824c0f49068cf Mon Sep 17 00:00:00 2001 From: radia0203 Date: Tue, 11 Mar 2025 11:55:27 +0100 Subject: [PATCH 06/37] essai icon --- examples/heart/.vscode/settings.json | 3 +++ examples/heart/heart.cpp | 28 ++++++++++++++++++++++++++-- node_2d.tscn | 17 +++++++++++++++++ project.godot | 4 ++-- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 examples/heart/.vscode/settings.json create mode 100644 node_2d.tscn diff --git a/examples/heart/.vscode/settings.json b/examples/heart/.vscode/settings.json new file mode 100644 index 0000000..70e34ec --- /dev/null +++ b/examples/heart/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index ceeb563..3469f67 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,2 +1,26 @@ -// c'est un test de git -//test de git + +// Write your code HERE +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + data_0[p] = 0xFFF00FFF - int(p)*(step+1); +} + + + + + + + +/* + + + + + + + + + +*/ \ No newline at end of file diff --git a/node_2d.tscn b/node_2d.tscn new file mode 100644 index 0000000..b62c4fa --- /dev/null +++ b/node_2d.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://cudof00lg11dw"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_wccwy"] +[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_0e48y"] + +[node name="Node2D" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(480, 175) +texture = ExtResource("1_wccwy") + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("2_0e48y") +glsl_file = "res://examples/heart/heart.cpp" +GLSL_code = "" +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" diff --git a/project.godot b/project.godot index f0250a9..1617345 100644 --- a/project.godot +++ b/project.godot @@ -12,9 +12,9 @@ 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.4", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] -enabled=PackedStringArray() +enabled=PackedStringArray("res://addons/compute_shader_studio/plugin.cfg") From 4a74f70caab54cd31bcbd52b51d304f47d5b5296 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Tue, 11 Mar 2025 11:57:55 +0100 Subject: [PATCH 07/37] icon 1 --- examples/heart/heart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 3469f67..0acb4bd 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -8,7 +8,7 @@ void main() { } - +///// test icon From 18c4f3299a7f2b63d86f4be28c24c797a03d37f6 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Tue, 11 Mar 2025 12:15:46 +0100 Subject: [PATCH 08/37] changed --- .vscode/settings.json | 3 +- examples/example_1.tscn | 2 +- examples/example_5.tscn | 2 +- examples/heart/heart.cpp | 90 +++++++++++++++++++++++++++++++-------- examples/heart/heart.tscn | 17 ++++++++ 5 files changed, 94 insertions(+), 20 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bb879da..fd17536 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -55,5 +55,6 @@ "C_Cpp_Runner.useLeakSanitizer": false, "C_Cpp_Runner.showCompilationTime": false, "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false + "C_Cpp_Runner.msvcSecureNoWarnings": false, + "C_Cpp.errorSquiggles": "disabled" } \ No newline at end of file diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 7d67949..88ce9e3 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://c8esqdv0y26yp" 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_5.tscn b/examples/example_5.tscn index 43aa420..b1d6e72 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://c8esqdv0y26yp" 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/heart/heart.cpp b/examples/heart/heart.cpp index 3469f67..d098b0b 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,26 +1,82 @@ + // Compute Shader pour un effet de cœur lumineux en Godot 4 -// Write your code HERE -void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - data_0[p] = 0xFFF00FFF - int(p)*(step+1); -} - - - - - - - -/* - +@compute +shader_type compute; +// Texture de sortie +layout(rgba32f) uniform image2D Result; +// Paramètres uniformes +uniform float iTime; +uniform vec2 iResolution; +#define POINT_COUNT 8 +#define PI 3.14159265359 +const float speed = -0.5; +const float len = 0.25; +const float scale = 0.012; +const float intensity = 1.3; +const float radius = 0.015; +vec2 getHeartPosition(float t) { + return vec2( + 16.0 * pow(sin(t), 3.0), + -(13.0 * cos(t) - 5.0 * cos(2.0 * t) - 2.0 * cos(3.0 * t) - cos(4.0 * t)) + ); +} +float getGlow(float dist, float radius, float intensity) { + return pow(radius / max(dist, 0.0001), intensity); +} +float getSegment(float t, vec2 pos, float offset) { + vec2 points[POINT_COUNT]; + for (int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i) * len + mod(speed * t, 6.28)); + } + + vec2 c = (points[0] + points[1]) / 2.0; + vec2 c_prev; + float dist = 10000.0; + + for (int i = 0; i < POINT_COUNT - 1; i++) { + c_prev = c; + c = (points[i] + points[i + 1]) / 2.0; + vec2 d = pos - scale * c; + dist = min(dist, length(d)); + } + return max(0.0, dist); +} -*/ \ No newline at end of file +// Fonction principale du Compute Shader +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + if (x >= uint(iResolution.x) || y >= uint(iResolution.y)) return; + + vec2 uv = vec2(x, y) / iResolution; + float widthHeightRatio = iResolution.x / iResolution.y; + vec2 centre = vec2(0.5, 0.5); + vec2 pos = centre - uv; + pos.y /= widthHeightRatio; + pos.y += 0.03; + + float t = iTime; + float dist = getSegment(t, pos, 0.0); + float glow = getGlow(dist, radius, intensity); + + vec3 col = vec3(0.0); + col += 10.0 * smoothstep(0.006, 0.003, dist); + col += glow * vec3(1.0, 0.05, 0.3); + + dist = getSegment(t, pos, 3.4); + glow = getGlow(dist, radius, intensity); + col += 10.0 * smoothstep(0.006, 0.003, dist); + col += glow * vec3(0.1, 0.4, 1.0); + + col = 1.0 - exp(-col); + col = pow(col, vec3(0.4545)); + + imageStore(Result, ivec2(x, y), vec4(col, 1.0)); +} diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index e69de29..f107b80 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://c26owfiw41nbe"] + +[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_xqxl4"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_7c68l"] + +[node name="Node2D" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_xqxl4") +glsl_file = "res://examples/heart/heart.cpp" +GLSL_code = " " +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(443, 109) +texture = ExtResource("2_7c68l") From 70d1a8bba2cf3d9074916e3735f606358468d013 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Wed, 12 Mar 2025 16:27:57 +0100 Subject: [PATCH 09/37] code a modifier j'ai enleve les premieres lignes, il faut adapter le code --- examples/example_5.tscn | 2 +- examples/heart/heart.cpp | 151 +++++++++++++++++++++++++++++++++----- examples/heart/heart.tscn | 17 +++++ heart.tscn | 17 +++++ node_2d.tscn | 16 +--- 5 files changed, 167 insertions(+), 36 deletions(-) create mode 100644 heart.tscn diff --git a/examples/example_5.tscn b/examples/example_5.tscn index 43aa420..b1d6e72 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://c8esqdv0y26yp" 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/heart/heart.cpp b/examples/heart/heart.cpp index 0acb4bd..2c3fd7e 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,26 +1,137 @@ -// Write your code HERE -void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - data_0[p] = 0xFFF00FFF - int(p)*(step+1); +#define POINT_COUNT 8 +const float speed = -0.5; +const float len = 0.25; +const float scale = 0.012; +float intensity = 1.3; +float radius = 0.015; + +// Signed distance to a quadratic bezier +float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { + vec2 a = B - A; + vec2 b = A - 2.0*B + C; + vec2 c = a * 2.0; + vec2 d = A - pos; + float kk = 1.0 / dot(b,b); + float kx = kk * dot(a,b); + float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0; + float kz = kk * dot(d,a); + float res = 0.0; + float p = ky - kx*kx; + float p3 = p*p*p; + float q = kx*(2.0*kx*kx - 3.0*ky) + kz; + float h = q*q + 4.0*p3; + if(h >= 0.0){ + h = sqrt(h); + vec2 x = (vec2(h, -h) - q) / 2.0; + vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); + float t = uv.x + uv.y - kx; + t = clamp( t, 0.0, 1.0 ); + // 1 root + vec2 qos = d + (c + b*t)*t; + res = length(qos); + } else { + float z = sqrt(-p); + float v = acos( q/(p*z*2.0) ) / 3.0; + float m = cos(v); + float n = sin(v)*1.732050808; + vec3 t = vec3(m + m, -n - m, n - m) * z - kx; + t = clamp( t, 0.0, 1.0 ); + // 3 roots + vec2 qos = d + (c + b*t.x)*t.x; + float dis = dot(qos,qos); + + res = dis; + qos = d + (c + b*t.y)*t.y; + dis = dot(qos,qos); + res = min(res,dis); + qos = d + (c + b*t.z)*t.z; + dis = dot(qos,qos); + res = min(res,dis); + res = sqrt( res ); + } + + return res; } +// Function to get the heart position +vec2 getHeartPosition(float t) { + return vec2(16.0 * sin(t) * sin(t) * sin(t), + -(13.0 * cos(t) - 5.0 * cos(2.0*t) + - 2.0 * cos(3.0*t) - cos(4.0*t))); +} -///// test icon - - - - -/* - - - - - - - +// Function to get the glow +float getGlow(float dist, float radius, float intensity) { + return pow(radius/dist, intensity); +} +float getSegment(float t, vec2 pos, float offset) { + vec2 points[POINT_COUNT]; + for(int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i)*len + fract(speed * t) * 6.28); + } + + vec2 c = (points[0] + points[1]) / 2.0; + vec2 c_prev; + float dist = 10000.0; + + for(int i = 0; i < POINT_COUNT-1; i++) { + c_prev = c; + c = (points[i] + points[i+1]) / 2.0; + dist = min(dist, sdBezier(pos, scale * c_prev, scale * points[i], scale * c)); + } + return max(0.0, dist); +} -*/ \ No newline at end of file +void main() { + // Get pixel coordinates + ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); + vec2 fragCoord = vec2(pixelCoords); + + // Check if we're within the image bounds + if (pixelCoords.x >= int(iResolution.x) || pixelCoords.y >= int(iResolution.y)) { + return; + } + + // Execute the shader + vec2 uv = fragCoord / iResolution.xy; + float widthHeightRatio = iResolution.x / iResolution.y; + vec2 centre = vec2(0.5, 0.5); + vec2 pos = centre - uv; + pos.y /= widthHeightRatio; + + // Shift upwards to center the heart + pos.y += 0.03; + + float t = iTime; + + // Get first segment + float dist = getSegment(t, pos, 0.0); + float glow = getGlow(dist, radius, intensity); + + vec3 col = vec3(0.0); + + // White core + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); + // Pink glow + col += glow * vec3(1.0, 0.05, 0.3); + + // Get second segment + dist = getSegment(t, pos, 3.4); + glow = getGlow(dist, radius, intensity); + + // White core + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); + // Blue glow + col += glow * vec3(0.1, 0.4, 1.0); + + // Tone mapping + col = 1.0 - exp(-col); + + // Gamma + col = pow(col, vec3(0.4545)); + + // Write to output image + imageStore(outputTexture, pixelCoords, vec4(col, 1.0)); +} \ No newline at end of file diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index e69de29..3769a13 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://2uk2l8hsinhg"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_7p8dj"] +[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] + +[node name="heart_2D" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(423, 168) +texture = ExtResource("1_7p8dj") + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("2_pembh") +glsl_file = "res://examples/heart/heart.cpp" +GLSL_code = "" +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" diff --git a/heart.tscn b/heart.tscn new file mode 100644 index 0000000..e99e7bd --- /dev/null +++ b/heart.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://byuanpgesqcq1"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_7p8dj"] +[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] + +[node name="heart_2D" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(423, 168) +texture = ExtResource("1_7p8dj") + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("2_pembh") +glsl_file = "res://examples/heart/heart.cpp" +GLSL_code = "" +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" diff --git a/node_2d.tscn b/node_2d.tscn index b62c4fa..1dc95b1 100644 --- a/node_2d.tscn +++ b/node_2d.tscn @@ -1,17 +1,3 @@ -[gd_scene load_steps=3 format=3 uid="uid://cudof00lg11dw"] - -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_wccwy"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_0e48y"] +[gd_scene format=3 uid="uid://cudof00lg11dw"] [node name="Node2D" type="Node2D"] - -[node name="Icon" type="Sprite2D" parent="."] -position = Vector2(480, 175) -texture = ExtResource("1_wccwy") - -[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] -script = ExtResource("2_0e48y") -glsl_file = "res://examples/heart/heart.cpp" -GLSL_code = "" -data = [NodePath("../Icon")] -metadata/_custom_type_script = "uid://c8esqdv0y26yp" From 96c4a8a4d1ba738204a897cc98e129c8805c2e76 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Wed, 12 Mar 2025 16:31:59 +0100 Subject: [PATCH 10/37] code a modifier --- examples/heart/heart.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 2c3fd7e..1b4b992 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,4 +1,7 @@ +<<<<<<< Updated upstream +======= +>>>>>>> Stashed changes #define POINT_COUNT 8 const float speed = -0.5; const float len = 0.25; From 5a585d3cbbb0c25a5e1ca33923ef9bcab3e8db8f Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Wed, 12 Mar 2025 16:50:02 +0100 Subject: [PATCH 11/37] =?UTF-8?q?code-modifi=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit j'ai retiré les elements qui correspondent pas à compute shader --- examples/example_1.tscn | 2 +- examples/heart/heart.cpp | 160 +++++++++++++++++++------------------- examples/heart/heart.tscn | 3 +- 3 files changed, 84 insertions(+), 81 deletions(-) diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 88ce9e3..3baeef0 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://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" 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/heart/heart.cpp b/examples/heart/heart.cpp index 1b4b992..1d20849 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,140 +1,144 @@ -<<<<<<< Updated upstream +@compute + +// Layout pour Godot Compute Shader +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +// Textures pour l'entrée/sortie des données +layout(rgba32f, binding = 0) uniform writeonly image2D outputTexture; + +// Uniforms pour la résolution et le temps +uniform vec2 resolution; +uniform float time; -======= ->>>>>>> Stashed changes #define POINT_COUNT 8 const float speed = -0.5; const float len = 0.25; const float scale = 0.012; -float intensity = 1.3; -float radius = 0.015; +const float intensity = 1.3; +const float radius = 0.015; -// Signed distance to a quadratic bezier -float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { +// Distance signée à une courbe quadratique de Bézier +float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { vec2 a = B - A; - vec2 b = A - 2.0*B + C; + vec2 b = A - 2.0 * B + C; vec2 c = a * 2.0; vec2 d = A - pos; - float kk = 1.0 / dot(b,b); - float kx = kk * dot(a,b); - float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0; - float kz = kk * dot(d,a); - float res = 0.0; - float p = ky - kx*kx; - float p3 = p*p*p; - float q = kx*(2.0*kx*kx - 3.0*ky) + kz; - float h = q*q + 4.0*p3; - if(h >= 0.0){ + float kk = 1.0 / dot(b, b); + float kx = kk * dot(a, b); + float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0; + float kz = kk * dot(d, a); + float p = ky - kx * kx; + float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz; + float h = q * q + 4.0 * p * p * p; + float res; + + if (h >= 0.0) { h = sqrt(h); vec2 x = (vec2(h, -h) - q) / 2.0; - vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); + vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0)); float t = uv.x + uv.y - kx; - t = clamp( t, 0.0, 1.0 ); - // 1 root - vec2 qos = d + (c + b*t)*t; + t = clamp(t, 0.0, 1.0); + vec2 qos = d + (c + b * t) * t; res = length(qos); } else { float z = sqrt(-p); - float v = acos( q/(p*z*2.0) ) / 3.0; + float v = acos(q / (p * z * 2.0)) / 3.0; float m = cos(v); - float n = sin(v)*1.732050808; + float n = sin(v) * 1.732050808; vec3 t = vec3(m + m, -n - m, n - m) * z - kx; - t = clamp( t, 0.0, 1.0 ); - // 3 roots - vec2 qos = d + (c + b*t.x)*t.x; - float dis = dot(qos,qos); - + t = clamp(t, 0.0, 1.0); + vec2 qos = d + (c + b * t.x) * t.x; + float dis = dot(qos, qos); res = dis; - qos = d + (c + b*t.y)*t.y; - dis = dot(qos,qos); - res = min(res,dis); - qos = d + (c + b*t.z)*t.z; - dis = dot(qos,qos); - res = min(res,dis); - res = sqrt( res ); + qos = d + (c + b * t.y) * t.y; + dis = dot(qos, qos); + res = min(res, dis); + qos = d + (c + b * t.z) * t.z; + dis = dot(qos, qos); + res = min(res, dis); + res = sqrt(res); } - + return res; } -// Function to get the heart position +// Fonction pour obtenir la position d'un cœur vec2 getHeartPosition(float t) { return vec2(16.0 * sin(t) * sin(t) * sin(t), - -(13.0 * cos(t) - 5.0 * cos(2.0*t) - - 2.0 * cos(3.0*t) - cos(4.0*t))); + -(13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t))); } -// Function to get the glow +// Fonction pour créer un effet de glow float getGlow(float dist, float radius, float intensity) { - return pow(radius/dist, intensity); + return pow(radius / dist, intensity); } +// Fonction pour calculer un segment du cœur float getSegment(float t, vec2 pos, float offset) { vec2 points[POINT_COUNT]; - for(int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i)*len + fract(speed * t) * 6.28); + for (int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); } vec2 c = (points[0] + points[1]) / 2.0; vec2 c_prev; float dist = 10000.0; - - for(int i = 0; i < POINT_COUNT-1; i++) { + + for (int i = 0; i < POINT_COUNT - 1; i++) { c_prev = c; - c = (points[i] + points[i+1]) / 2.0; + c = (points[i] + points[i + 1]) / 2.0; dist = min(dist, sdBezier(pos, scale * c_prev, scale * points[i], scale * c)); } + return max(0.0, dist); } void main() { - // Get pixel coordinates + // Récupère la position du pixel actuel ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); - vec2 fragCoord = vec2(pixelCoords); - - // Check if we're within the image bounds - if (pixelCoords.x >= int(iResolution.x) || pixelCoords.y >= int(iResolution.y)) { + if (pixelCoords.x >= int(resolution.x) || pixelCoords.y >= int(resolution.y)) { return; } - - // Execute the shader - vec2 uv = fragCoord / iResolution.xy; - float widthHeightRatio = iResolution.x / iResolution.y; + + vec2 fragCoord = vec2(pixelCoords); + vec2 uv = fragCoord / resolution; + float widthHeightRatio = resolution.x / resolution.y; vec2 centre = vec2(0.5, 0.5); vec2 pos = centre - uv; pos.y /= widthHeightRatio; - - // Shift upwards to center the heart + + // Ajustement pour bien centrer le cœur pos.y += 0.03; - - float t = iTime; - - // Get first segment + + float t = time; + + // Calcul du premier segment du cœur float dist = getSegment(t, pos, 0.0); float glow = getGlow(dist, radius, intensity); - + vec3 col = vec3(0.0); - - // White core + + // Couleur blanche au centre col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Pink glow + // Glow rose col += glow * vec3(1.0, 0.05, 0.3); - - // Get second segment + + // Calcul du second segment du cœur dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); - - // White core + + // Couleur blanche col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Blue glow + // Glow bleu col += glow * vec3(0.1, 0.4, 1.0); - - // Tone mapping + + // Tone Mapping col = 1.0 - exp(-col); - - // Gamma + + // Correction gamma col = pow(col, vec3(0.4545)); - - // Write to output image + + // Stockage du pixel dans la texture de sortie imageStore(outputTexture, pixelCoords, vec4(col, 1.0)); -} \ No newline at end of file +} diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index 3769a13..2f73509 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://2uk2l8hsinhg"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_7p8dj"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] [node name="heart_2D" type="Node2D"] @@ -14,4 +14,3 @@ script = ExtResource("2_pembh") glsl_file = "res://examples/heart/heart.cpp" GLSL_code = "" data = [NodePath("../Icon")] -metadata/_custom_type_script = "uid://c8esqdv0y26yp" From b45be87ba4f6a781a43cdaa3f5ced769c308d12e Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Wed, 12 Mar 2025 17:06:55 +0100 Subject: [PATCH 12/37] essaie-push --- examples/circles/circles.tscn | 3 +- examples/example_3.tscn | 4 +- examples/example_4.tscn | 2 +- examples/example_5.tscn | 2 +- examples/example_lenia_test.tscn | 4 +- examples/example_psycho_seizure.tscn | 2 +- examples/heart/heart.cpp | 189 +++++++-------------------- examples/heart/heart.tscn | 3 +- 8 files changed, 60 insertions(+), 149 deletions(-) diff --git a/examples/circles/circles.tscn b/examples/circles/circles.tscn index c66e724..ec54187 100644 --- a/examples/circles/circles.tscn +++ b/examples/circles/circles.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://c1ux4sgouixua"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_amro2"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_amro2"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_ntl1q"] [node name="Circles" type="Node2D"] @@ -12,7 +12,6 @@ WSY = 256 glsl_file = "res://examples/circles/circles.cpp" GLSL_code = "" data = [NodePath("../Icon")] -metadata/_custom_type_script = "uid://c8esqdv0y26yp" [node name="Label" type="Label" parent="."] offset_left = 278.0 diff --git a/examples/example_3.tscn b/examples/example_3.tscn index 680ce1e..3cf4a4f 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] -[ext_resource type="Script" uid="uid://jw3o2qu3a0pl" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] +[ext_resource type="Script" uid="uid://bqujiuru3j13y" 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 1d7e26f..23b7a88 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_ke3fj"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" 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 b1d6e72..83c022e 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" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_cogap"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" 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..8bcf25f 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://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_wci4f"] +[ext_resource type="Script" uid="uid://bqujiuru3j13y" 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_psycho_seizure.tscn b/examples/example_psycho_seizure.tscn index f1e07d4..c55272d 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://bxee45ox6kfs2" 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/heart/heart.cpp b/examples/heart/heart.cpp index 1d20849..8b67e8c 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,144 +1,55 @@ -@compute +#define RADIUS 40 -// Layout pour Godot Compute Shader -layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; - -// Textures pour l'entrée/sortie des données -layout(rgba32f, binding = 0) uniform writeonly image2D outputTexture; - -// Uniforms pour la résolution et le temps -uniform vec2 resolution; -uniform float time; - -#define POINT_COUNT 8 -const float speed = -0.5; -const float len = 0.25; -const float scale = 0.012; -const float intensity = 1.3; -const float radius = 0.015; - -// Distance signée à une courbe quadratique de Bézier -float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { - vec2 a = B - A; - vec2 b = A - 2.0 * B + C; - vec2 c = a * 2.0; - vec2 d = A - pos; - float kk = 1.0 / dot(b, b); - float kx = kk * dot(a, b); - float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0; - float kz = kk * dot(d, a); - float p = ky - kx * kx; - float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz; - float h = q * q + 4.0 * p * p * p; - float res; +void main() { + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + int p = x + y * int(WSX); - if (h >= 0.0) { - h = sqrt(h); - vec2 x = (vec2(h, -h) - q) / 2.0; - vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0)); - float t = uv.x + uv.y - kx; - t = clamp(t, 0.0, 1.0); - vec2 qos = d + (c + b * t) * t; - res = length(qos); + // Fond initial en noir opaque + if (step == 0) { + data_0[p] = 0xFF000000 + y; } else { - float z = sqrt(-p); - float v = acos(q / (p * z * 2.0)) / 3.0; - float m = cos(v); - float n = sin(v) * 1.732050808; - vec3 t = vec3(m + m, -n - m, n - m) * z - kx; - t = clamp(t, 0.0, 1.0); - vec2 qos = d + (c + b * t.x) * t.x; - float dis = dot(qos, qos); - res = dis; - qos = d + (c + b * t.y) * t.y; - dis = dot(qos, qos); - res = min(res, dis); - qos = d + (c + b * t.z) * t.z; - dis = dot(qos, qos); - res = min(res, dis); - res = sqrt(res); - } - - return res; -} - -// Fonction pour obtenir la position d'un cœur -vec2 getHeartPosition(float t) { - return vec2(16.0 * sin(t) * sin(t) * sin(t), - -(13.0 * cos(t) - 5.0 * cos(2.0 * t) - - 2.0 * cos(3.0 * t) - cos(4.0 * t))); -} - -// Fonction pour créer un effet de glow -float getGlow(float dist, float radius, float intensity) { - return pow(radius / dist, intensity); -} - -// Fonction pour calculer un segment du cœur -float getSegment(float t, vec2 pos, float offset) { - vec2 points[POINT_COUNT]; - for (int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); - } - - vec2 c = (points[0] + points[1]) / 2.0; - vec2 c_prev; - float dist = 10000.0; - - for (int i = 0; i < POINT_COUNT - 1; i++) { - c_prev = c; - c = (points[i] + points[i + 1]) / 2.0; - dist = min(dist, sdBezier(pos, scale * c_prev, scale * points[i], scale * c)); + // Coordonnées relatives par rapport à la position de la souris (centre du cœur) + float dx = float(x - mousex); + float dy = float(y - mousey); + + // Variation dynamique de la taille du cœur pour un effet pulsant + float r = RADIUS + 10.0 * sin(step / 10.0); + + // Mise à l'échelle pour adapter l'équation du cœur + float sx = dx / r; + float sy = dy / r; + + // Équation implicite du cœur : (x²+y²-1)³ - x²*y³ = 0 + float f = pow(sx * sx + sy * sy - 1.0, 3.0) - sx * sx * pow(sy, 3.0); + + // Utilisation de smoothstep pour adoucir la transition au niveau du contour + // borderBlend passe de 0 (à l'intérieur) à 1 (à l'extérieur) sur une petite plage autour de f=0 + float borderBlend = smoothstep(-0.02, 0.02, f); + // outsideBlend permet de faire disparaître progressivement les couleurs à l'extérieur du cœur + float outsideBlend = smoothstep(0.02, 0.05, f); + + // Définition des couleurs (composantes entre 0 et 1) + vec3 red = vec3(1.0, 0.0, 0.0); + vec3 blue = vec3(0.0, 0.0, 1.0); + vec3 black = vec3(0.0, 0.0, 0.0); + + // Mélange du rouge (intérieur) et du bleu (contour) selon borderBlend + vec3 mixedColor = mix(red, blue, borderBlend); + // Fait disparaître la couleur en fondu vers le noir à l'extérieur + vec3 finalColor = mix(mixedColor, black, outsideBlend); + + // Optionnel : on peut rehausser légèrement la luminosité à l'intérieur du cœur + if (f < -0.02) { + finalColor += vec3(0.1); + finalColor = clamp(finalColor, 0.0, 1.0); + } + + // Conversion en couleur 32 bits 0xAARRGGBB + int a = 255; + int rInt = int(finalColor.r * 255.0); + int gInt = int(finalColor.g * 255.0); + int bInt = int(finalColor.b * 255.0); + data_0[p] = (a << 24) + (rInt << 16) + (gInt << 8) + bInt; } - - return max(0.0, dist); -} - -void main() { - // Récupère la position du pixel actuel - ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); - if (pixelCoords.x >= int(resolution.x) || pixelCoords.y >= int(resolution.y)) { - return; - } - - vec2 fragCoord = vec2(pixelCoords); - vec2 uv = fragCoord / resolution; - float widthHeightRatio = resolution.x / resolution.y; - vec2 centre = vec2(0.5, 0.5); - vec2 pos = centre - uv; - pos.y /= widthHeightRatio; - - // Ajustement pour bien centrer le cœur - pos.y += 0.03; - - float t = time; - - // Calcul du premier segment du cœur - float dist = getSegment(t, pos, 0.0); - float glow = getGlow(dist, radius, intensity); - - vec3 col = vec3(0.0); - - // Couleur blanche au centre - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Glow rose - col += glow * vec3(1.0, 0.05, 0.3); - - // Calcul du second segment du cœur - dist = getSegment(t, pos, 3.4); - glow = getGlow(dist, radius, intensity); - - // Couleur blanche - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Glow bleu - col += glow * vec3(0.1, 0.4, 1.0); - - // Tone Mapping - col = 1.0 - exp(-col); - - // Correction gamma - col = pow(col, vec3(0.4545)); - - // Stockage du pixel dans la texture de sortie - imageStore(outputTexture, pixelCoords, vec4(col, 1.0)); } diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index 2f73509..cf2460d 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -6,7 +6,8 @@ [node name="heart_2D" type="Node2D"] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(423, 168) +position = Vector2(557, 159.75) +scale = Vector2(4.89063, 3.26953) texture = ExtResource("1_7p8dj") [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] From 6bd95c01f0930be7be71961c39330f34bebdb218 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Wed, 12 Mar 2025 17:21:04 +0100 Subject: [PATCH 13/37] delete branch islam --- examples/heart/heart.cpp | 46 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 1b4b992..e3415b5 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,7 +1,6 @@ -<<<<<<< Updated upstream +#[compute] +#version 450 -======= ->>>>>>> Stashed changes #define POINT_COUNT 8 const float speed = -0.5; const float len = 0.25; @@ -10,7 +9,7 @@ float intensity = 1.3; float radius = 0.015; // Signed distance to a quadratic bezier -float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { +float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { vec2 a = B - A; vec2 b = A - 2.0*B + C; vec2 c = a * 2.0; @@ -24,22 +23,22 @@ float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { float p3 = p*p*p; float q = kx*(2.0*kx*kx - 3.0*ky) + kz; float h = q*q + 4.0*p3; - if(h >= 0.0){ + if(h >= 0.0) { h = sqrt(h); vec2 x = (vec2(h, -h) - q) / 2.0; vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); float t = uv.x + uv.y - kx; - t = clamp( t, 0.0, 1.0 ); + t = clamp(t, 0.0, 1.0); // 1 root vec2 qos = d + (c + b*t)*t; res = length(qos); } else { float z = sqrt(-p); - float v = acos( q/(p*z*2.0) ) / 3.0; + float v = acos(q/(p*z*2.0)) / 3.0; float m = cos(v); float n = sin(v)*1.732050808; vec3 t = vec3(m + m, -n - m, n - m) * z - kx; - t = clamp( t, 0.0, 1.0 ); + t = clamp(t, 0.0, 1.0); // 3 roots vec2 qos = d + (c + b*t.x)*t.x; float dis = dot(qos,qos); @@ -51,20 +50,20 @@ float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { qos = d + (c + b*t.z)*t.z; dis = dot(qos,qos); res = min(res,dis); - res = sqrt( res ); + res = sqrt(res); } return res; } -// Function to get the heart position +// Heart curve function vec2 getHeartPosition(float t) { return vec2(16.0 * sin(t) * sin(t) * sin(t), -(13.0 * cos(t) - 5.0 * cos(2.0*t) - 2.0 * cos(3.0*t) - cos(4.0*t))); } -// Function to get the glow +// Glow function float getGlow(float dist, float radius, float intensity) { return pow(radius/dist, intensity); } @@ -88,26 +87,25 @@ float getSegment(float t, vec2 pos, float offset) { } void main() { - // Get pixel coordinates - ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); - vec2 fragCoord = vec2(pixelCoords); + // Get the current pixel coordinates + ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); - // Check if we're within the image bounds - if (pixelCoords.x >= int(iResolution.x) || pixelCoords.y >= int(iResolution.y)) { + // Make sure we don't try to write outside the texture + if (pixel_coords.x >= int(resolution.x) || pixel_coords.y >= int(resolution.y)) { return; } - // Execute the shader - vec2 uv = fragCoord / iResolution.xy; - float widthHeightRatio = iResolution.x / iResolution.y; + // Convert to normalized coordinates (0.0 to 1.0) + vec2 uv = vec2(pixel_coords) / resolution; + float widthHeightRatio = resolution.x / resolution.y; vec2 centre = vec2(0.5, 0.5); vec2 pos = centre - uv; pos.y /= widthHeightRatio; - // Shift upwards to center the heart + // Shift upwards to center heart pos.y += 0.03; - float t = iTime; + float t = time; // Get first segment float dist = getSegment(t, pos, 0.0); @@ -128,13 +126,13 @@ void main() { col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); // Blue glow col += glow * vec3(0.1, 0.4, 1.0); - + // Tone mapping col = 1.0 - exp(-col); // Gamma col = pow(col, vec3(0.4545)); - // Write to output image - imageStore(outputTexture, pixelCoords, vec4(col, 1.0)); + // Write the result to the output texture + imageStore(output_texture, pixel_coords, vec4(col, 1.0)); } \ No newline at end of file From 076e9bfbe6053f5560353aa899038722ef393c75 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Wed, 12 Mar 2025 17:22:46 +0100 Subject: [PATCH 14/37] modification_heart j'ai modifie le coeur --- examples/heart/heart.cpp | 187 ++++++++++++++++++++++++++++----------- 1 file changed, 137 insertions(+), 50 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 8b67e8c..99c41c0 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,55 +1,142 @@ -#define RADIUS 40 + // Compute shader 2D pour Godot 4.4, inspiré de Gelami -void main() { - int x = int(gl_GlobalInvocationID.x); - int y = int(gl_GlobalInvocationID.y); - int p = x + y * int(WSX); +#define POINT_COUNT 8 + +vec2 points[POINT_COUNT]; +const float speed = -0.5; +const float len = 0.25; +const float baseScale = 0.012; +float intensity = 1.3; +float radius = 0.015; + +// Distance signée à une courbe de Bézier quadratique +float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { + vec2 a = B - A; + vec2 b = A - 2.0 * B + C; + vec2 c = a * 2.0; + vec2 d = A - pos; + + float kk = 1.0 / dot(b, b); + float kx = kk * dot(a, b); + float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0; + float kz = kk * dot(d, a); - // Fond initial en noir opaque - if (step == 0) { - data_0[p] = 0xFF000000 + y; + float res = 0.0; + float p = ky - kx * kx; + float p3 = p * p * p; + float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz; + float h = q * q + 4.0 * p3; + + if (h >= 0.0) { + h = sqrt(h); + vec2 x = (vec2(h, -h) - q) / 2.0; + vec2 uv = sign(x) * pow(abs(x), vec2(1.0/3.0)); + float t = uv.x + uv.y - kx; + t = clamp(t, 0.0, 1.0); + vec2 qos = d + (c + b * t) * t; + res = length(qos); } else { - // Coordonnées relatives par rapport à la position de la souris (centre du cœur) - float dx = float(x - mousex); - float dy = float(y - mousey); - - // Variation dynamique de la taille du cœur pour un effet pulsant - float r = RADIUS + 10.0 * sin(step / 10.0); - - // Mise à l'échelle pour adapter l'équation du cœur - float sx = dx / r; - float sy = dy / r; - - // Équation implicite du cœur : (x²+y²-1)³ - x²*y³ = 0 - float f = pow(sx * sx + sy * sy - 1.0, 3.0) - sx * sx * pow(sy, 3.0); - - // Utilisation de smoothstep pour adoucir la transition au niveau du contour - // borderBlend passe de 0 (à l'intérieur) à 1 (à l'extérieur) sur une petite plage autour de f=0 - float borderBlend = smoothstep(-0.02, 0.02, f); - // outsideBlend permet de faire disparaître progressivement les couleurs à l'extérieur du cœur - float outsideBlend = smoothstep(0.02, 0.05, f); - - // Définition des couleurs (composantes entre 0 et 1) - vec3 red = vec3(1.0, 0.0, 0.0); - vec3 blue = vec3(0.0, 0.0, 1.0); - vec3 black = vec3(0.0, 0.0, 0.0); - - // Mélange du rouge (intérieur) et du bleu (contour) selon borderBlend - vec3 mixedColor = mix(red, blue, borderBlend); - // Fait disparaître la couleur en fondu vers le noir à l'extérieur - vec3 finalColor = mix(mixedColor, black, outsideBlend); - - // Optionnel : on peut rehausser légèrement la luminosité à l'intérieur du cœur - if (f < -0.02) { - finalColor += vec3(0.1); - finalColor = clamp(finalColor, 0.0, 1.0); - } - - // Conversion en couleur 32 bits 0xAARRGGBB - int a = 255; - int rInt = int(finalColor.r * 255.0); - int gInt = int(finalColor.g * 255.0); - int bInt = int(finalColor.b * 255.0); - data_0[p] = (a << 24) + (rInt << 16) + (gInt << 8) + bInt; + float z = sqrt(-p); + float v = acos(q / (p * z * 2.0)) / 3.0; + float m = cos(v); + float n = sin(v) * 1.732050808; + vec3 t = vec3(m + m, -n - m, n - m) * z - kx; + t = clamp(t, 0.0, 1.0); + vec2 qos = d + (c + b * t.x) * t.x; + float dis = dot(qos, qos); + res = dis; + qos = d + (c + b * t.y) * t.y; + dis = dot(qos, qos); + res = min(res, dis); + qos = d + (c + b * t.z) * t.z; + dis = dot(qos, qos); + res = min(res, dis); + res = sqrt(res); } + + return res; +} + +// Position sur la courbe du cœur (paramétrisation classique) +vec2 getHeartPosition(float t) { + return vec2(16.0 * sin(t) * sin(t) * sin(t), + -(13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t))); +} + +// Calcul du glow en fonction de la distance à la courbe +float getGlow(float dist, float radius, float intensity) { + return pow(radius / max(dist, 0.0001), intensity); +} + +// Calcule la distance minimale d'un segment de la courbe, en utilisant des courbes de Bézier pour adoucir le contour. +// Le paramètre scaleFactor permet de faire varier la taille du segment. +float getSegment(float t, vec2 pos, float offset, float scaleFactor) { + for (int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); + } + + vec2 c = (points[0] + points[1]) / 2.0; + vec2 c_prev; + float dist = 10000.0; + + for (int i = 0; i < POINT_COUNT - 1; i++) { + c_prev = c; + c = (points[i] + points[i+1]) / 2.0; + dist = min(dist, sdBezier(pos, scaleFactor * c_prev, scaleFactor * points[i], scaleFactor * c)); + } + return max(0.0, dist); +} + +void main() { + uint ix = gl_GlobalInvocationID.x; + uint iy = gl_GlobalInvocationID.y; + int p = int(ix + iy * WSX); + + // Coordonnées normalisées et centrage + vec2 fragCoord = vec2(float(ix), float(iy)); + vec2 uv = fragCoord / vec2(float(WSX), float(WSY)); + float aspect = float(WSX) / float(WSY); + vec2 centre = vec2(0.5, 0.5); + vec2 pos = centre - uv; + pos.y /= aspect; + pos.y += 0.03; + + // Temps (utilisé pour l'animation) + float t = float(step); + + // Effet de pulsation : variation de la taille du cœur + float pulse = 1.0 + 0.15 * sin(t * 2.0); + float dynamicScale = baseScale * pulse; + // On fait aussi varier le rayon du glow pour renforcer l'animation + float dynamicRadius = radius * (1.0 + 0.2 * sin(t * 3.0)); + + // Offsets animés pour les deux segments + float offset0 = 0.0 + 0.1 * sin(t * 1.5); + float offset1 = 3.4 + 0.1 * cos(t * 1.3); + + vec3 col = vec3(0.0); + + // Premier segment : glow rose + float dist1 = getSegment(t, pos, offset0, dynamicScale); + float glow1 = getGlow(dist1, dynamicRadius, intensity); + // Ajout d'un noyau blanc (pour le cœur) et du glow rose + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist1)); + col += glow1 * vec3(1.0, 0.05, 0.3); + + // Deuxième segment : glow bleu + float dist2 = getSegment(t, pos, offset1, dynamicScale); + float glow2 = getGlow(dist2, dynamicRadius, intensity); + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist2)); + col += glow2 * vec3(0.1, 0.4, 1.0); + + // Tone mapping et correction gamma pour un rendu lumineux + col = 1.0 - exp(-col); + col = pow(col, vec3(0.4545)); + + int a = 255; + int rInt = int(clamp(col.r, 0.0, 1.0) * 255.0); + int gInt = int(clamp(col.g, 0.0, 1.0) * 255.0); + int bInt = int(clamp(col.b, 0.0, 1.0) * 255.0); + data_0[p] = (a << 24) | (rInt << 16) | (gInt << 8) | bInt; } From d013d6a1637f1fab6b73c6e0c4648b122c8f4b93 Mon Sep 17 00:00:00 2001 From: islem jnaieh <99294197+islem-jnaieh@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:27:59 +0100 Subject: [PATCH 15/37] Create heart.cpp --- examples/heart/heart.cpp | 139 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 examples/heart/heart.cpp diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp new file mode 100644 index 0000000..d26332a --- /dev/null +++ b/examples/heart/heart.cpp @@ -0,0 +1,139 @@ +#[compute] +#version 450 + +#define POINT_COUNT 8 +const float speed = -0.5; +const float len = 0.25; +const float scale = 0.012; +float intensity = 1.3; +float radius = 0.015; + +// Signed distance to a quadratic bezier +float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { + vec2 a = B - A; + vec2 b = A - 2.0*B + C; + vec2 c = a * 2.0; + vec2 d = A - pos; + float kk = 1.0 / dot(b,b); + float kx = kk * dot(a,b); + float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0; + float kz = kk * dot(d,a); + float res = 0.0; + float p = ky - kx*kx; + float p3 = p*p*p; + float q = kx*(2.0*kx*kx - 3.0*ky) + kz; + float h = q*q + 4.0*p3; + if(h >= 0.0) { + h = sqrt(h); + vec2 x = (vec2(h, -h) - q) / 2.0; + vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); + float t = uv.x + uv.y - kx; + t = clamp(t, 0.0, 1.0); + // 1 root + vec2 qos = d + (c + b*t)*t; + res = length(qos); + } else { + float z = sqrt(-p); + float v = acos(q/(p*z*2.0)) / 3.0; + float m = cos(v); + float n = sin(v)*1.732050808; + vec3 t = vec3(m + m, -n - m, n - m) * z - kx; + t = clamp(t, 0.0, 1.0); + // 3 roots + vec2 qos = d + (c + b*t.x)*t.x; + float dis = dot(qos,qos); + + res = dis; + qos = d + (c + b*t.y)*t.y; + dis = dot(qos,qos); + res = min(res,dis); + qos = d + (c + b*t.z)*t.z; + dis = dot(qos,qos); + res = min(res,dis); + res = sqrt(res); + } + + return res; +} + +// Heart curve function +vec2 getHeartPosition(float t) { + return vec2(16.0 * sin(t) * sin(t) * sin(t), + -(13.0 * cos(t) - 5.0 * cos(2.0*t) + - 2.0 * cos(3.0*t) - cos(4.0*t))); +} + +// Glow function +float getGlow(float dist, float radius, float intensity) { + return pow(radius/dist, intensity); +} + +// comment +float getSegment(float t, vec2 pos, float offset) { + vec2 points[POINT_COUNT]; + for(int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i)*len + fract(speed * t) * 6.28); + } + + vec2 c = (points[0] + points[1]) / 2.0; + vec2 c_prev; + float dist = 10000.0; + + for(int i = 0; i < POINT_COUNT-1; i++) { + c_prev = c; + c = (points[i] + points[i+1]) / 2.0; + dist = min(dist, sdBezier(pos, scale * c_prev, scale * points[i], scale * c)); + } + return max(0.0, dist); +} + +void main() { + // Get the current pixel coordinates + ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); + + // Make sure we don't try to write outside the texture + if (pixel_coords.x >= int(resolution.x) || pixel_coords.y >= int(resolution.y)) { + return; + } + + // Convert to normalized coordinates (0.0 to 1.0) + vec2 uv = vec2(pixel_coords) / resolution; + float widthHeightRatio = resolution.x / resolution.y; + vec2 centre = vec2(0.5, 0.5); + vec2 pos = centre - uv; + pos.y /= widthHeightRatio; + + // Shift upwards to center heart + pos.y += 0.03; + + float t = time; + + // Get first segment + float dist = getSegment(t, pos, 0.0); + float glow = getGlow(dist, radius, intensity); + + vec3 col = vec3(0.0); + + // White core + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); + // Pink glow + col += glow * vec3(1.0, 0.05, 0.3); + + // Get second segment + dist = getSegment(t, pos, 3.4); + glow = getGlow(dist, radius, intensity); + + // White core + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); + // Blue glow + col += glow * vec3(0.1, 0.4, 1.0); + + // Tone mapping + col = 1.0 - exp(-col); + + // Gamma + col = pow(col, vec3(0.4545)); + + // Write the result to the output texture + imageStore(output_texture, pixel_coords, vec4(col, 1.0)); +} \ No newline at end of file From e22e449c456c7132195a0abfab6961ef17ced9dd Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Wed, 12 Mar 2025 17:31:42 +0100 Subject: [PATCH 16/37] Update heart.cpp --- examples/heart/heart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index d26332a..8759c52 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -68,7 +68,7 @@ float getGlow(float dist, float radius, float intensity) { return pow(radius/dist, intensity); } -// comment +// my comment float getSegment(float t, vec2 pos, float offset) { vec2 points[POINT_COUNT]; for(int i = 0; i < POINT_COUNT; i++) { From 70c61db3215c57e8e9ca939793179217ce6105a0 Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Wed, 12 Mar 2025 17:33:37 +0100 Subject: [PATCH 17/37] coeur fonc --- examples/heart/heart.cpp | 135 ++++++++++---------------------------- examples/heart/heart.tscn | 18 +++++ 2 files changed, 53 insertions(+), 100 deletions(-) create mode 100644 examples/heart/heart.tscn diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 8759c52..cc2b99c 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,139 +1,74 @@ -#[compute] -#version 450 +// Shader Compute 2D - Godot 4.4 - Effet de cœurs lumineux inspiré de Shadertoy #define POINT_COUNT 8 + +vec2 points[POINT_COUNT]; const float speed = -0.5; const float len = 0.25; const float scale = 0.012; float intensity = 1.3; float radius = 0.015; -// Signed distance to a quadratic bezier -float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { - vec2 a = B - A; - vec2 b = A - 2.0*B + C; - vec2 c = a * 2.0; - vec2 d = A - pos; - float kk = 1.0 / dot(b,b); - float kx = kk * dot(a,b); - float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0; - float kz = kk * dot(d,a); - float res = 0.0; - float p = ky - kx*kx; - float p3 = p*p*p; - float q = kx*(2.0*kx*kx - 3.0*ky) + kz; - float h = q*q + 4.0*p3; - if(h >= 0.0) { - h = sqrt(h); - vec2 x = (vec2(h, -h) - q) / 2.0; - vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); - float t = uv.x + uv.y - kx; - t = clamp(t, 0.0, 1.0); - // 1 root - vec2 qos = d + (c + b*t)*t; - res = length(qos); - } else { - float z = sqrt(-p); - float v = acos(q/(p*z*2.0)) / 3.0; - float m = cos(v); - float n = sin(v)*1.732050808; - vec3 t = vec3(m + m, -n - m, n - m) * z - kx; - t = clamp(t, 0.0, 1.0); - // 3 roots - vec2 qos = d + (c + b*t.x)*t.x; - float dis = dot(qos,qos); - - res = dis; - qos = d + (c + b*t.y)*t.y; - dis = dot(qos,qos); - res = min(res,dis); - qos = d + (c + b*t.z)*t.z; - dis = dot(qos,qos); - res = min(res,dis); - res = sqrt(res); - } - - return res; -} - -// Heart curve function +// Fonction mathématique pour tracer un cœur inversé vec2 getHeartPosition(float t) { return vec2(16.0 * sin(t) * sin(t) * sin(t), - -(13.0 * cos(t) - 5.0 * cos(2.0*t) - - 2.0 * cos(3.0*t) - cos(4.0*t))); + (13.0 * cos(t) - 5.0 * cos(2.0*t) + - 2.0 * cos(3.0*t) - cos(4.0*t))); // Inversion du signe pour inverser le cœur } -// Glow function float getGlow(float dist, float radius, float intensity) { - return pow(radius/dist, intensity); + return pow(radius / dist, intensity); } -// my comment float getSegment(float t, vec2 pos, float offset) { - vec2 points[POINT_COUNT]; - for(int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i)*len + fract(speed * t) * 6.28); + for (int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); } - + vec2 c = (points[0] + points[1]) / 2.0; vec2 c_prev; float dist = 10000.0; - - for(int i = 0; i < POINT_COUNT-1; i++) { + + for (int i = 0; i < POINT_COUNT - 1; i++) { c_prev = c; - c = (points[i] + points[i+1]) / 2.0; - dist = min(dist, sdBezier(pos, scale * c_prev, scale * points[i], scale * c)); + c = (points[i] + points[i + 1]) / 2.0; + dist = min(dist, length(pos - scale * c)); } return max(0.0, dist); } void main() { - // Get the current pixel coordinates - ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); - - // Make sure we don't try to write outside the texture - if (pixel_coords.x >= int(resolution.x) || pixel_coords.y >= int(resolution.y)) { - return; - } - - // Convert to normalized coordinates (0.0 to 1.0) - vec2 uv = vec2(pixel_coords) / resolution; - float widthHeightRatio = resolution.x / resolution.y; + 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)); + float widthHeightRatio = float(WSX) / float(WSY); vec2 centre = vec2(0.5, 0.5); vec2 pos = centre - uv; pos.y /= widthHeightRatio; - - // Shift upwards to center heart pos.y += 0.03; - - float t = time; - - // Get first segment + + float t = float(step) / 60.0; float dist = getSegment(t, pos, 0.0); float glow = getGlow(dist, radius, intensity); vec3 col = vec3(0.0); - - // White core - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Pink glow - col += glow * vec3(1.0, 0.05, 0.3); - - // Get second segment + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); // Cœur lumineux blanc + col += glow * vec3(1.0, 0.05, 0.3); // Halo rose + dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); - - // White core col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Blue glow - col += glow * vec3(0.1, 0.4, 1.0); - - // Tone mapping + col += glow * vec3(0.1, 0.4, 1.0); // Effet bleu secondaire + col = 1.0 - exp(-col); - - // Gamma col = pow(col, vec3(0.4545)); - - // Write the result to the output texture - imageStore(output_texture, pixel_coords, vec4(col, 1.0)); -} \ No newline at end of file + + int r = int(255.0 * col.r); + int g = int(255.0 * col.g); + int b = int(255.0 * col.b); + int color = (0xFF << 24) | (r << 16) | (g << 8) | b; + + data_0[p] = color; +} diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn new file mode 100644 index 0000000..0f6e353 --- /dev/null +++ b/examples/heart/heart.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://dswe7om5osvdk"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_7p8dj"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] + +[node name="heart_2D" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(448, 220) +scale = Vector2(3.44531, 2.52734) +texture = ExtResource("1_7p8dj") + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("2_pembh") +glsl_file = "res://examples/heart/heart.cpp" +GLSL_code = "" +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" From 8058646b60fbef7b006c4e8a135e52f1bf19a90f Mon Sep 17 00:00:00 2001 From: radia0203 Date: Wed, 12 Mar 2025 17:35:33 +0100 Subject: [PATCH 18/37] test --- examples/heart/heart.cpp | 166 ++++++++++++++++++++------------------- heart.tscn | 3 +- 2 files changed, 86 insertions(+), 83 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 1b4b992..1aff6e4 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,140 +1,142 @@ -<<<<<<< Updated upstream +// Compute shader 2D pour Godot 4.4, inspiré de Gelami -======= ->>>>>>> Stashed changes #define POINT_COUNT 8 + +vec2 points[POINT_COUNT]; const float speed = -0.5; -const float len = 0.25; -const float scale = 0.012; +const float len = 0.25; +const float baseScale = 0.012; float intensity = 1.3; -float radius = 0.015; +float radius = 0.015; -// Signed distance to a quadratic bezier +// Distance signée à une courbe de Bézier quadratique float sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) { vec2 a = B - A; - vec2 b = A - 2.0*B + C; + vec2 b = A - 2.0 * B + C; vec2 c = a * 2.0; vec2 d = A - pos; - float kk = 1.0 / dot(b,b); - float kx = kk * dot(a,b); - float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0; - float kz = kk * dot(d,a); + + float kk = 1.0 / dot(b, b); + float kx = kk * dot(a, b); + float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0; + float kz = kk * dot(d, a); + float res = 0.0; - float p = ky - kx*kx; - float p3 = p*p*p; - float q = kx*(2.0*kx*kx - 3.0*ky) + kz; - float h = q*q + 4.0*p3; - if(h >= 0.0){ + float p = ky - kx * kx; + float p3 = p * p * p; + float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz; + float h = q * q + 4.0 * p3; + + if (h >= 0.0) { h = sqrt(h); vec2 x = (vec2(h, -h) - q) / 2.0; - vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); + vec2 uv = sign(x) * pow(abs(x), vec2(1.0/3.0)); float t = uv.x + uv.y - kx; - t = clamp( t, 0.0, 1.0 ); - // 1 root - vec2 qos = d + (c + b*t)*t; + t = clamp(t, 0.0, 1.0); + vec2 qos = d + (c + b * t) * t; res = length(qos); } else { float z = sqrt(-p); - float v = acos( q/(p*z*2.0) ) / 3.0; + float v = acos(q / (p * z * 2.0)) / 3.0; float m = cos(v); - float n = sin(v)*1.732050808; + float n = sin(v) * 1.732050808; vec3 t = vec3(m + m, -n - m, n - m) * z - kx; - t = clamp( t, 0.0, 1.0 ); - // 3 roots - vec2 qos = d + (c + b*t.x)*t.x; - float dis = dot(qos,qos); - + t = clamp(t, 0.0, 1.0); + vec2 qos = d + (c + b * t.x) * t.x; + float dis = dot(qos, qos); res = dis; - qos = d + (c + b*t.y)*t.y; - dis = dot(qos,qos); - res = min(res,dis); - qos = d + (c + b*t.z)*t.z; - dis = dot(qos,qos); - res = min(res,dis); - res = sqrt( res ); + qos = d + (c + b * t.y) * t.y; + dis = dot(qos, qos); + res = min(res, dis); + qos = d + (c + b * t.z) * t.z; + dis = dot(qos, qos); + res = min(res, dis); + res = sqrt(res); } return res; } -// Function to get the heart position +// Position sur la courbe du cœur (paramétrisation classique) vec2 getHeartPosition(float t) { return vec2(16.0 * sin(t) * sin(t) * sin(t), - -(13.0 * cos(t) - 5.0 * cos(2.0*t) - - 2.0 * cos(3.0*t) - cos(4.0*t))); + -(13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t))); } -// Function to get the glow +// Calcul du glow en fonction de la distance à la courbe float getGlow(float dist, float radius, float intensity) { - return pow(radius/dist, intensity); + return pow(radius / max(dist, 0.0001), intensity); } -float getSegment(float t, vec2 pos, float offset) { - vec2 points[POINT_COUNT]; - for(int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i)*len + fract(speed * t) * 6.28); +// Calcule la distance minimale d'un segment de la courbe, en utilisant des courbes de Bézier pour adoucir le contour. +// Le paramètre scaleFactor permet de faire varier la taille du segment. +float getSegment(float t, vec2 pos, float offset, float scaleFactor) { + for (int i = 0; i < POINT_COUNT; i++) { + points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); } vec2 c = (points[0] + points[1]) / 2.0; vec2 c_prev; float dist = 10000.0; - for(int i = 0; i < POINT_COUNT-1; i++) { + for (int i = 0; i < POINT_COUNT - 1; i++) { c_prev = c; c = (points[i] + points[i+1]) / 2.0; - dist = min(dist, sdBezier(pos, scale * c_prev, scale * points[i], scale * c)); + dist = min(dist, sdBezier(pos, scaleFactor * c_prev, scaleFactor * points[i], scaleFactor * c)); } return max(0.0, dist); } void main() { - // Get pixel coordinates - ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); - vec2 fragCoord = vec2(pixelCoords); - - // Check if we're within the image bounds - if (pixelCoords.x >= int(iResolution.x) || pixelCoords.y >= int(iResolution.y)) { - return; - } + uint ix = gl_GlobalInvocationID.x; + uint iy = gl_GlobalInvocationID.y; + int p = int(ix + iy * WSX); - // Execute the shader - vec2 uv = fragCoord / iResolution.xy; - float widthHeightRatio = iResolution.x / iResolution.y; + // Coordonnées normalisées et centrage + vec2 fragCoord = vec2(float(ix), float(iy)); + vec2 uv = fragCoord / vec2(float(WSX), float(WSY)); + float aspect = float(WSX) / float(WSY); vec2 centre = vec2(0.5, 0.5); vec2 pos = centre - uv; - pos.y /= widthHeightRatio; - - // Shift upwards to center the heart + pos.y /= aspect; pos.y += 0.03; - float t = iTime; - - // Get first segment - float dist = getSegment(t, pos, 0.0); - float glow = getGlow(dist, radius, intensity); + // Temps (utilisé pour l'animation) + float t = float(step); - vec3 col = vec3(0.0); + // Effet de pulsation : variation de la taille du cœur + float pulse = 1.0 + 0.15 * sin(t * 2.0); + float dynamicScale = baseScale * pulse; + // On fait aussi varier le rayon du glow pour renforcer l'animation + float dynamicRadius = radius * (1.0 + 0.2 * sin(t * 3.0)); - // White core - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Pink glow - col += glow * vec3(1.0, 0.05, 0.3); + // Offsets animés pour les deux segments + float offset0 = 0.0 + 0.1 * sin(t * 1.5); + float offset1 = 3.4 + 0.1 * cos(t * 1.3); - // Get second segment - dist = getSegment(t, pos, 3.4); - glow = getGlow(dist, radius, intensity); + vec3 col = vec3(0.0); - // White core - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Blue glow - col += glow * vec3(0.1, 0.4, 1.0); + // Premier segment : glow rose + float dist1 = getSegment(t, pos, offset0, dynamicScale); + float glow1 = getGlow(dist1, dynamicRadius, intensity); + // Ajout d'un noyau blanc (pour le cœur) et du glow rose + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist1)); + col += glow1 * vec3(1.0, 0.05, 0.3); - // Tone mapping + // Deuxième segment : glow bleu + float dist2 = getSegment(t, pos, offset1, dynamicScale); + float glow2 = getGlow(dist2, dynamicRadius, intensity); + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist2)); + col += glow2 * vec3(0.1, 0.4, 1.0); + + // Tone mapping et correction gamma pour un rendu lumineux col = 1.0 - exp(-col); - - // Gamma col = pow(col, vec3(0.4545)); - // Write to output image - imageStore(outputTexture, pixelCoords, vec4(col, 1.0)); + int a = 255; + int rInt = int(clamp(col.r, 0.0, 1.0) * 255.0); + int gInt = int(clamp(col.g, 0.0, 1.0) * 255.0); + int bInt = int(clamp(col.b, 0.0, 1.0) * 255.0); + data_0[p] = (a << 24) | (rInt << 16) | (gInt << 8) | bInt; } \ No newline at end of file diff --git a/heart.tscn b/heart.tscn index e99e7bd..13e4df3 100644 --- a/heart.tscn +++ b/heart.tscn @@ -6,7 +6,8 @@ [node name="heart_2D" type="Node2D"] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(423, 168) +position = Vector2(442, 182.5) +scale = Vector2(2.65625, 2.38281) texture = ExtResource("1_7p8dj") [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] From 6a63ebb09fff7e9f14b584510b0f50879e4ad069 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Thu, 13 Mar 2025 15:54:01 +0100 Subject: [PATCH 19/37] effet-plusieurs-coeurs --- examples/heart/heart.cpp | 42 +++++++++++++++++++++++++-------------- examples/heart/heart.tscn | 5 ++--- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index cc2b99c..ddbfca5 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,19 +1,19 @@ -// Shader Compute 2D - Godot 4.4 - Effet de cœurs lumineux inspiré de Shadertoy - #define POINT_COUNT 8 vec2 points[POINT_COUNT]; const float speed = -0.5; -const float len = 0.25; +const float len = 0.25; const float scale = 0.012; -float intensity = 1.3; -float radius = 0.015; +float intensity = 1.3; +float radius = 0.015; // Fonction mathématique pour tracer un cœur inversé vec2 getHeartPosition(float t) { - return vec2(16.0 * sin(t) * sin(t) * sin(t), - (13.0 * cos(t) - 5.0 * cos(2.0*t) - - 2.0 * cos(3.0*t) - cos(4.0*t))); // Inversion du signe pour inverser le cœur + return vec2( + 16.0 * sin(t) * sin(t) * sin(t), + (13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t)) + ); // Inversion du signe pour inverser le cœur } float getGlow(float dist, float radius, float intensity) { @@ -22,7 +22,9 @@ float getGlow(float dist, float radius, float intensity) { float getSegment(float t, vec2 pos, float offset) { for (int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); + points[i] = getHeartPosition( + offset + float(i) * len + fract(speed * t) * 6.28 + ); } vec2 c = (points[0] + points[1]) / 2.0; @@ -50,18 +52,28 @@ void main() { pos.y += 0.03; float t = float(step) / 60.0; + + // Premier segment float dist = getSegment(t, pos, 0.0); float glow = getGlow(dist, radius, intensity); - + + // Couleur accumulée vec3 col = vec3(0.0); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); // Cœur lumineux blanc - col += glow * vec3(1.0, 0.05, 0.3); // Halo rose + // Cœur lumineux (noyau blanc un peu plus fort) + col += 12.0 * vec3(smoothstep(0.006, 0.003, dist)); + // Halo rose plus vif + col += glow * vec3(1.0, 0.3, 0.7); + + // Second segment (décalé de 3.4) dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.1, 0.4, 1.0); // Effet bleu secondaire + col += 12.0 * vec3(smoothstep(0.006, 0.003, dist)); + // Teinte bleue plus pastel et éclatante + col += glow * vec3(0.2, 0.8, 1.0); + + // Tone mapping et correction gamma col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); @@ -71,4 +83,4 @@ void main() { int color = (0xFF << 24) | (r << 16) | (g << 8) | b; data_0[p] = color; -} +} \ No newline at end of file diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index 0f6e353..37af79a 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -1,7 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://dswe7om5osvdk"] +[gd_scene load_steps=3 format=3 uid="uid://2uk2l8hsinhg"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_7p8dj"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] +[ext_resource type="Script" uid="uid://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] [node name="heart_2D" type="Node2D"] @@ -15,4 +15,3 @@ script = ExtResource("2_pembh") glsl_file = "res://examples/heart/heart.cpp" GLSL_code = "" data = [NodePath("../Icon")] -metadata/_custom_type_script = "uid://c8esqdv0y26yp" From d4196d40ebf873f85b1931625bc4d5d24ffb8b30 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 16:05:04 +0100 Subject: [PATCH 20/37] modification de couleurs --- examples/heart/heart.cpp | 6 +++--- heart.tscn | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index cc2b99c..b0cf0c4 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -54,13 +54,13 @@ void main() { float glow = getGlow(dist, radius, intensity); vec3 col = vec3(0.0); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); // Cœur lumineux blanc - col += glow * vec3(1.0, 0.05, 0.3); // Halo rose + col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); + col += glow * vec3(1.0, 0.05, 0.3); dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.1, 0.4, 1.0); // Effet bleu secondaire + col += glow * vec3(0.6, 0.4, 2.0); col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); diff --git a/heart.tscn b/heart.tscn index 13e4df3..5a052ee 100644 --- a/heart.tscn +++ b/heart.tscn @@ -6,8 +6,8 @@ [node name="heart_2D" type="Node2D"] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(442, 182.5) -scale = Vector2(2.65625, 2.38281) +position = Vector2(429.5, 207.5) +scale = Vector2(3.10156, 2.75781) texture = ExtResource("1_7p8dj") [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] From 99703c8632f62dc84853c5d8ebbef19385e32562 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Thu, 13 Mar 2025 16:06:34 +0100 Subject: [PATCH 21/37] test --- examples/heart/heart.cpp | 66 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index ddbfca5..75f765f 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,25 +1,28 @@ #define POINT_COUNT 8 +#define HEART_COUNT 6 // Nombre de cœurs affichés vec2 points[POINT_COUNT]; -const float speed = -0.5; +const float speed = -0.4; const float len = 0.25; -const float scale = 0.012; -float intensity = 1.3; -float radius = 0.015; +const float scale = 0.015; +float intensity = 1.8; +float radius = 0.02; -// Fonction mathématique pour tracer un cœur inversé +// Fonction pour dessiner un cœur stylisé vec2 getHeartPosition(float t) { return vec2( 16.0 * sin(t) * sin(t) * sin(t), - (13.0 * cos(t) - 5.0 * cos(2.0 * t) - - 2.0 * cos(3.0 * t) - cos(4.0 * t)) - ); // Inversion du signe pour inverser le cœur + 13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t) + ); } +// Glow plus fluide et magique float getGlow(float dist, float radius, float intensity) { - return pow(radius / dist, intensity); + return pow(smoothstep(radius * 2.2, radius, dist), intensity); } +// Calcule la distance au segment du cœur float getSegment(float t, vec2 pos, float offset) { for (int i = 0; i < POINT_COUNT; i++) { points[i] = getHeartPosition( @@ -39,6 +42,11 @@ float getSegment(float t, vec2 pos, float offset) { return max(0.0, dist); } +// Fonction de bruit pour un effet scintillant +float getNoise(vec2 uv) { + return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453); +} + void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; @@ -53,29 +61,39 @@ void main() { float t = float(step) / 60.0; - // Premier segment - float dist = getSegment(t, pos, 0.0); - float glow = getGlow(dist, radius, intensity); + // Effet de pulsation pour un rendu vivant + float pulse = 0.5 + 0.5 * sin(3.0 * t); + float dynamicRadius = mix(0.015, 0.025, pulse); // Couleur accumulée vec3 col = vec3(0.0); - // Cœur lumineux (noyau blanc un peu plus fort) - col += 12.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Halo rose plus vif - col += glow * vec3(1.0, 0.3, 0.7); + // **Ajout de plusieurs cœurs avec des positions différentes** + for (int i = 0; i < HEART_COUNT; i++) { + float offset = float(i) * 2.3; // Décalage des cœurs + vec2 heartPos = pos + vec2(sin(t + float(i) * 1.5) * 0.3, cos(t + float(i) * 1.8) * 0.2); + float dist = getSegment(t, heartPos, offset); + float glow = getGlow(dist, dynamicRadius, intensity); + + // **Dégradé magique entre bleu néon et rose pastel** + vec3 heartColor = mix(vec3(0.4, 0.8, 1.0), vec3(1.0, 0.5, 0.8), smoothstep(0.0, 0.6, dist)); + + // Ajout du glow et du cœur lumineux + col += 15.0 * vec3(smoothstep(0.008, 0.004, dist)); + col += glow * heartColor; + } - // Second segment (décalé de 3.4) - dist = getSegment(t, pos, 3.4); - glow = getGlow(dist, radius, intensity); + // **Ajout d’un fond ultra doux et onirique** + vec3 backgroundColor = mix(vec3(0.1, 0.0, 0.3), vec3(0.3, 0.0, 0.5), uv.y * 1.2); + col = mix(backgroundColor, col, smoothstep(0.2, 0.6, length(pos))); - col += 12.0 * vec3(smoothstep(0.006, 0.003, dist)); - // Teinte bleue plus pastel et éclatante - col += glow * vec3(0.2, 0.8, 1.0); + // **Léger scintillement pour un effet féerique** + float noise = getNoise(uv + t * 0.1); + col += 0.03 * noise; // Tone mapping et correction gamma col = 1.0 - exp(-col); - col = pow(col, vec3(0.4545)); + col = pow(col, vec3(0.45)); int r = int(255.0 * col.r); int g = int(255.0 * col.g); @@ -83,4 +101,4 @@ void main() { int color = (0xFF << 24) | (r << 16) | (g << 8) | b; data_0[p] = color; -} \ No newline at end of file +} From 12f706dcfeda2de902e404a33e4a8ef477983e7a Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Thu, 13 Mar 2025 16:07:41 +0100 Subject: [PATCH 22/37] test --- examples/heart/heart.cpp | 29 +++++++++++++++++++++++++---- project.godot | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index cc2b99c..787c822 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,4 +1,4 @@ -// Shader Compute 2D - Godot 4.4 - Effet de cœurs lumineux inspiré de Shadertoy +// Shader Compute 2D - Godot 4.4 - Effet de cœurs lumineux avec étoiles et fond spatial dynamique #define POINT_COUNT 8 @@ -37,6 +37,21 @@ float getSegment(float t, vec2 pos, float offset) { return max(0.0, dist); } +// Fonction pour générer des étoiles scintillantes et fond spatial +float starField(vec2 uv, float time) { + vec2 seed = floor(uv * 100.0); + float star = fract(sin(dot(seed, vec2(12.9898, 78.233))) * 43758.5453); + float twinkle = 0.5 + 0.5 * sin(time + star * 10.0); + return step(0.98, star) * twinkle; +} + +// Fond spatial dynamique inspiré du code de champ d'étoiles +float nebulaField(vec2 uv, float time) { + float noise = fract(sin(dot(uv * 5.0, vec2(12.9898, 78.233))) * 43758.5453); + float colorVariation = 0.5 + 0.5 * sin(time * 0.5 + noise * 10.0); + return smoothstep(0.3, 1.0, colorVariation * noise); +} + void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; @@ -55,12 +70,18 @@ void main() { vec3 col = vec3(0.0); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); // Cœur lumineux blanc - col += glow * vec3(1.0, 0.05, 0.3); // Halo rose + col += glow * vec3(0.1, 0.4, 1.0); // Halo bleu dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.1, 0.4, 1.0); // Effet bleu secondaire + col += glow * vec3(1.0, 0.05, 0.3); // Effet rose + + // Ajout d'un ciel étoilé scintillant et d'un fond spatial + float stars = starField(uv, float(step) / 20.0); + float nebula = nebulaField(uv, float(step) / 15.0); + col += stars * vec3(1.0, 1.0, 1.0); // Étoiles blanches scintillantes + col += nebula * vec3(0.2, 0.1, 0.5); // Effet spatial violet-bleu col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); @@ -71,4 +92,4 @@ void main() { int color = (0xFF << 24) | (r << 16) | (g << 8) | b; data_0[p] = color; -} +} \ No newline at end of file diff --git a/project.godot b/project.godot index 1617345..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.4", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From 0f7f6c3aa83caece5e808e16f0c3f4877c742af3 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 16:44:28 +0100 Subject: [PATCH 23/37] coeur rose et bleu --- examples/heart/heart.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index b0cf0c4..5b27a6e 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,5 +1,3 @@ -// Shader Compute 2D - Godot 4.4 - Effet de cœurs lumineux inspiré de Shadertoy - #define POINT_COUNT 8 vec2 points[POINT_COUNT]; @@ -55,12 +53,15 @@ void main() { vec3 col = vec3(0.0); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(1.0, 0.05, 0.3); + col += glow * vec3(1.0, 0.5, 0.0); // bleu clair + + + dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.6, 0.4, 2.0); + col += glow * vec3(0.6, 0.4, 2.0); // rose col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); From 5302c3998046a9dbb0c96effdf79fe7df940b072 Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Thu, 13 Mar 2025 16:45:42 +0100 Subject: [PATCH 24/37] update --- examples/heart/heart.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index b0cf0c4..2090e19 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -49,18 +49,21 @@ void main() { pos.y /= widthHeightRatio; pos.y += 0.03; + // Définition du fond avec un dégradé de bleu ciel + vec3 background = mix(vec3(0.1, 0.2, 0.4), vec3(0.6, 0.8, 1.0), uv.y); + float t = float(step) / 60.0; float dist = getSegment(t, pos, 0.0); float glow = getGlow(dist, radius, intensity); - vec3 col = vec3(0.0); + vec3 col = background; col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(1.0, 0.05, 0.3); + col += glow * vec3(1.0, 0.4, 0.7); // Rose dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.6, 0.4, 2.0); + col += glow * vec3(0.5, 0.8, 1.0); // Bleu ciel col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); @@ -71,4 +74,4 @@ void main() { int color = (0xFF << 24) | (r << 16) | (g << 8) | b; data_0[p] = color; -} +} \ No newline at end of file From 3b7b62cac743ea0a51d87d3d1b5e838c925280d5 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Thu, 13 Mar 2025 16:54:17 +0100 Subject: [PATCH 25/37] points-en-trait les points i didnt like , donc j'ai mit un effet trait --- examples/heart/heart.cpp | 109 +++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 34 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index b0cf0c4..6f1c81d 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,74 +1,115 @@ -// Shader Compute 2D - Godot 4.4 - Effet de cœurs lumineux inspiré de Shadertoy - -#define POINT_COUNT 8 +#define POINT_COUNT 12 // Plus de points pour un tracé lisse +#define HEART_COUNT 4 // Nombre total de cœurs vec2 points[POINT_COUNT]; -const float speed = -0.5; -const float len = 0.25; +const float speed = -0.2; +const float len = 0.2; const float scale = 0.012; -float intensity = 1.3; -float radius = 0.015; -// Fonction mathématique pour tracer un cœur inversé +// Ajustements pour éviter la saturation +float intensity = 1.0; // Intensité moins élevée +float radius = 0.015; // Rayon légèrement réduit +float lineWidth = 0.004; // Largeur du trait inchangée + +// Fonction mathématique pour tracer un cœur vec2 getHeartPosition(float t) { - return vec2(16.0 * sin(t) * sin(t) * sin(t), - (13.0 * cos(t) - 5.0 * cos(2.0*t) - - 2.0 * cos(3.0*t) - cos(4.0*t))); // Inversion du signe pour inverser le cœur + return vec2( + 16.0 * sin(t) * sin(t) * sin(t), + 13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t) + ); } +// Fonction de glow (inchangée) – on fera surtout attention aux multiplicateurs float getGlow(float dist, float radius, float intensity) { - return pow(radius / dist, intensity); + // max(dist, 0.001) pour éviter division par zéro + return pow(radius / max(dist, 0.001), intensity); +} + +// Calcul de la distance à un segment (pour tracer le “trait” du cœur) +float distToLine(vec2 p, vec2 a, vec2 b) { + vec2 pa = p - a; + vec2 ba = b - a; + float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); + return length(pa - ba * h); } +// Calcul de la distance au “trait” du cœur float getSegment(float t, vec2 pos, float offset) { for (int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); + points[i] = getHeartPosition( + offset + float(i) * len + fract(speed * t) * 6.28 + ); } - - vec2 c = (points[0] + points[1]) / 2.0; - vec2 c_prev; + float dist = 10000.0; - for (int i = 0; i < POINT_COUNT - 1; i++) { - c_prev = c; - c = (points[i] + points[i + 1]) / 2.0; - dist = min(dist, length(pos - scale * c)); + float segDist = distToLine(pos, scale * points[i], scale * points[i + 1]); + dist = min(dist, segDist); } - return max(0.0, dist); + return dist; } void main() { + // Position du pixel en X/Y uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; - + + // Coordonnées [0..1] vec2 uv = vec2(float(x) / float(WSX), float(y) / float(WSY)); float widthHeightRatio = float(WSX) / float(WSY); + + // On centre la scène vec2 centre = vec2(0.5, 0.5); vec2 pos = centre - uv; pos.y /= widthHeightRatio; pos.y += 0.03; - + float t = float(step) / 60.0; - float dist = getSegment(t, pos, 0.0); - float glow = getGlow(dist, radius, intensity); + // Accumulateur de couleur vec3 col = vec3(0.0); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(1.0, 0.05, 0.3); - - dist = getSegment(t, pos, 3.4); - glow = getGlow(dist, radius, intensity); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.6, 0.4, 2.0); + + // Couleurs ajustées pour être clairement roses et bleues + vec3 pinkColor = vec3(1.0, 0.0, 0.6); // Rose plus “pur” (sans jaune) + vec3 blueColor = vec3(0.0, 0.5, 1.0); // Bleu clair bien franc + + // On dessine HEART_COUNT cœurs + for (int i = 0; i < HEART_COUNT; i++) { + float offset = float(i) * 3.4; + + // Distance au tracé du cœur + float dist = getSegment(t, pos, offset); + + // Trait lumineux + float line = smoothstep(lineWidth + 0.001, lineWidth - 0.001, dist); + + // Halo + float glow = getGlow(dist, radius, intensity); + + // Alterne rose / bleu + vec3 heartColor = (i % 2 == 0) ? pinkColor : blueColor; + + // Ajout du trait (pas de multiplicateur énorme) + col += line * heartColor; + + // Ajout du halo (pas de *1.5 ici, pour éviter la saturation) + col += glow * heartColor; + } + + // On limite la valeur maximale (pour éviter la sur-saturation) + col = clamp(col, 0.0, 3.0); + // Tone mapping et correction gamma col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); - + + // Conversion vers int int r = int(255.0 * col.r); int g = int(255.0 * col.g); int b = int(255.0 * col.b); int color = (0xFF << 24) | (r << 16) | (g << 8) | b; - + data_0[p] = color; } From 5de27a7bf5540b1355d031a89d687651ee120687 Mon Sep 17 00:00:00 2001 From: dihiaAmz Date: Thu, 13 Mar 2025 17:05:01 +0100 Subject: [PATCH 26/37] coeur-v2 j'ai modifie les traits il manque juste les couleurs --- examples/heart/heart.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 6f1c81d..fc8b489 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -7,9 +7,9 @@ const float len = 0.2; const float scale = 0.012; // Ajustements pour éviter la saturation -float intensity = 1.0; // Intensité moins élevée -float radius = 0.015; // Rayon légèrement réduit -float lineWidth = 0.004; // Largeur du trait inchangée +float intensity = 1.0; // Intensité du glow +float radius = 0.015; // Rayon du halo +float lineWidth = 0.004; // Largeur du trait // Fonction mathématique pour tracer un cœur vec2 getHeartPosition(float t) { @@ -20,13 +20,12 @@ vec2 getHeartPosition(float t) { ); } -// Fonction de glow (inchangée) – on fera surtout attention aux multiplicateurs +// Fonction de glow float getGlow(float dist, float radius, float intensity) { - // max(dist, 0.001) pour éviter division par zéro return pow(radius / max(dist, 0.001), intensity); } -// Calcul de la distance à un segment (pour tracer le “trait” du cœur) +// Calcul de la distance à un segment float distToLine(vec2 p, vec2 a, vec2 b) { vec2 pa = p - a; vec2 ba = b - a; @@ -68,13 +67,13 @@ void main() { float t = float(step) / 60.0; - // Accumulateur de couleur + // Fond noir vec3 col = vec3(0.0); - // Couleurs ajustées pour être clairement roses et bleues - vec3 pinkColor = vec3(1.0, 0.0, 0.6); // Rose plus “pur” (sans jaune) - vec3 blueColor = vec3(0.0, 0.5, 1.0); // Bleu clair bien franc - + // Couleurs : rose et bleu + vec3 pinkColor = vec3(1.0, 0.0, 0.6); + vec3 blueColor = vec3(0.0, 0.5, 1.0); + // On dessine HEART_COUNT cœurs for (int i = 0; i < HEART_COUNT; i++) { float offset = float(i) * 3.4; @@ -91,10 +90,10 @@ void main() { // Alterne rose / bleu vec3 heartColor = (i % 2 == 0) ? pinkColor : blueColor; - // Ajout du trait (pas de multiplicateur énorme) + // Ajout du trait col += line * heartColor; - // Ajout du halo (pas de *1.5 ici, pour éviter la saturation) + // Ajout du halo col += glow * heartColor; } @@ -111,5 +110,6 @@ void main() { int b = int(255.0 * col.b); int color = (0xFF << 24) | (r << 16) | (g << 8) | b; + // On écrit la couleur finale data_0[p] = color; } From 9346366fbb681b505a4b3ef10ad385044e1c71ff Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 17:06:42 +0100 Subject: [PATCH 27/37] Update heart.tscn --- heart.tscn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/heart.tscn b/heart.tscn index 5a052ee..30047b8 100644 --- a/heart.tscn +++ b/heart.tscn @@ -6,8 +6,8 @@ [node name="heart_2D" type="Node2D"] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(429.5, 207.5) -scale = Vector2(3.10156, 2.75781) +position = Vector2(606, 338.5) +scale = Vector2(5.07813, 4.25781) texture = ExtResource("1_7p8dj") [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] From 27f34301561b8bc5f38c458ac5342920a5e1c39a Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Thu, 13 Mar 2025 17:06:53 +0100 Subject: [PATCH 28/37] update --- examples/heart/heart.cpp | 15 ++++++++------- examples/heart/heart.tscn | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 5b27a6e..60f9d26 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -48,24 +48,25 @@ void main() { pos.y += 0.03; float t = float(step) / 60.0; + + vec3 col = vec3(0.0); // Fond noir propre + float dist = getSegment(t, pos, 0.0); float glow = getGlow(dist, radius, intensity); - - vec3 col = vec3(0.0); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(1.0, 0.5, 0.0); // bleu clair - - - + col += glow * vec3(1.0, 0.5, 0.0); // Bleu clair dist = getSegment(t, pos, 3.4); glow = getGlow(dist, radius, intensity); col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.6, 0.4, 2.0); // rose + col += glow * vec3(0.6, 0.4, 2.0); // Rose col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); + // Ajout d'un fond noir plus contrasté + col = mix(vec3(0.0), col, smoothstep(0.02, 0.04, length(col))); + int r = int(255.0 * col.r); int g = int(255.0 * col.g); int b = int(255.0 * col.b); diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index 0f6e353..3342048 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -6,8 +6,8 @@ [node name="heart_2D" type="Node2D"] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(448, 220) -scale = Vector2(3.44531, 2.52734) +position = Vector2(465, 261) +scale = Vector2(4.36719, 3.64844) texture = ExtResource("1_7p8dj") [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] From fd366bf208ab63c9f25b4d70d8879dc53bbe4852 Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Thu, 13 Mar 2025 17:10:07 +0100 Subject: [PATCH 29/37] coeur2 --- examples/heart/heart.cpp | 9 ++++++--- examples/heart/heart.tscn | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index fc8b489..612e06d 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -70,9 +70,12 @@ void main() { // Fond noir vec3 col = vec3(0.0); - // Couleurs : rose et bleu - vec3 pinkColor = vec3(1.0, 0.0, 0.6); - vec3 blueColor = vec3(0.0, 0.5, 1.0); + + + // Couleurs : rose vif et bleu cyan +vec3 pinkColor = vec3(1.0, 0.2, 0.8); +vec3 blueColor = vec3(0.0, 0.8, 1.0); + // On dessine HEART_COUNT cœurs for (int i = 0; i < HEART_COUNT; i++) { diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn index 7427ae4..a7b1242 100644 --- a/examples/heart/heart.tscn +++ b/examples/heart/heart.tscn @@ -1,7 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://2uk2l8hsinhg"] +[gd_scene load_steps=3 format=3 uid="uid://dswe7om5osvdk"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_7p8dj"] -[ext_resource type="Script" uid="uid://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_pembh"] [node name="heart_2D" type="Node2D"] From a423d7710ca2c8d42b7eb82698c4f2dbdace1338 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 17:11:22 +0100 Subject: [PATCH 30/37] coeur ligne continue --- examples/heart/heart.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 5b27a6e..d189519 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -52,8 +52,15 @@ void main() { float glow = getGlow(dist, radius, intensity); vec3 col = vec3(0.0); +<<<<<<< Updated upstream col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); col += glow * vec3(1.0, 0.5, 0.0); // bleu clair +======= + + // Couleurs : rose et bleu + vec3 pinkColor = vec3(0.6, 0.4, 2.0); + vec3 blueColor = vec3(1.0, 0.5, 0.0); +>>>>>>> Stashed changes From 6570057df15f1a3f86b511dcd60fb5c394ebfe4f Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 17:13:55 +0100 Subject: [PATCH 31/37] coeur ligne continue 1 --- examples/heart/heart.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index d189519..4d17736 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -80,3 +80,6 @@ void main() { data_0[p] = color; } + + +// comment \ No newline at end of file From 0bf3bc4d022c6a3bf2c34ae17cd43f23748aa1ef Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Thu, 13 Mar 2025 17:14:26 +0100 Subject: [PATCH 32/37] modif5 --- examples/heart/heart.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index d189519..5b27a6e 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -52,15 +52,8 @@ void main() { float glow = getGlow(dist, radius, intensity); vec3 col = vec3(0.0); -<<<<<<< Updated upstream col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); col += glow * vec3(1.0, 0.5, 0.0); // bleu clair -======= - - // Couleurs : rose et bleu - vec3 pinkColor = vec3(0.6, 0.4, 2.0); - vec3 blueColor = vec3(1.0, 0.5, 0.0); ->>>>>>> Stashed changes From e2c09beb7de222b8a8af18e16b5fa561a95fb466 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 17:16:21 +0100 Subject: [PATCH 33/37] coeur continue --- examples/heart/heart.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index 4d17736..f843c87 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -82,4 +82,5 @@ void main() { } -// comment \ No newline at end of file +// comment +// comme \ No newline at end of file From bf3baf000cc77a14d4dad6c495e267dfa6011516 Mon Sep 17 00:00:00 2001 From: islem jnaieh Date: Thu, 13 Mar 2025 17:22:11 +0100 Subject: [PATCH 34/37] coeur final --- examples/heart/heart.cpp | 113 ++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index fdbe65c..c49c512 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -1,79 +1,116 @@ -#define POINT_COUNT 8 +#define POINT_COUNT 12 // Plus de points pour un tracé lisse +#define HEART_COUNT 4 // Nombre total de cœurs vec2 points[POINT_COUNT]; -const float speed = -0.5; -const float len = 0.25; +const float speed = -0.2; +const float len = 0.2; const float scale = 0.012; -float intensity = 1.3; -float radius = 0.015; -// Fonction mathématique pour tracer un cœur inversé +// Ajustements pour éviter la saturation +float intensity = 1.0; // Intensité du glow +float radius = 0.015; // Rayon du halo +float lineWidth = 0.004; // Largeur du trait + +// Fonction mathématique pour tracer un cœur vec2 getHeartPosition(float t) { - return vec2(16.0 * sin(t) * sin(t) * sin(t), - (13.0 * cos(t) - 5.0 * cos(2.0*t) - - 2.0 * cos(3.0*t) - cos(4.0*t))); // Inversion du signe pour inverser le cœur + return vec2( + 16.0 * sin(t) * sin(t) * sin(t), + 13.0 * cos(t) - 5.0 * cos(2.0 * t) + - 2.0 * cos(3.0 * t) - cos(4.0 * t) + ); } +// Fonction de glow float getGlow(float dist, float radius, float intensity) { - return pow(radius / dist, intensity); + return pow(radius / max(dist, 0.001), intensity); +} + +// Calcul de la distance à un segment +float distToLine(vec2 p, vec2 a, vec2 b) { + vec2 pa = p - a; + vec2 ba = b - a; + float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); + return length(pa - ba * h); } +// Calcul de la distance au “trait” du cœur float getSegment(float t, vec2 pos, float offset) { for (int i = 0; i < POINT_COUNT; i++) { - points[i] = getHeartPosition(offset + float(i) * len + fract(speed * t) * 6.28); + points[i] = getHeartPosition( + offset + float(i) * len + fract(speed * t) * 6.28 + ); } - - vec2 c = (points[0] + points[1]) / 2.0; - vec2 c_prev; + float dist = 10000.0; - for (int i = 0; i < POINT_COUNT - 1; i++) { - c_prev = c; - c = (points[i] + points[i + 1]) / 2.0; - dist = min(dist, length(pos - scale * c)); + float segDist = distToLine(pos, scale * points[i], scale * points[i + 1]); + dist = min(dist, segDist); } - return max(0.0, dist); + return dist; } void main() { + // Position du pixel en X/Y uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; - + + // Coordonnées [0..1] vec2 uv = vec2(float(x) / float(WSX), float(y) / float(WSY)); float widthHeightRatio = float(WSX) / float(WSY); + + // On centre la scène vec2 centre = vec2(0.5, 0.5); vec2 pos = centre - uv; pos.y /= widthHeightRatio; pos.y += 0.03; - + float t = float(step) / 60.0; - float dist = getSegment(t, pos, 0.0); - float glow = getGlow(dist, radius, intensity); + // Fond noir vec3 col = vec3(0.0); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(1.0, 0.5, 0.0); // bleu clair - - - - - dist = getSegment(t, pos, 3.4); - glow = getGlow(dist, radius, intensity); - col += 10.0 * vec3(smoothstep(0.006, 0.003, dist)); - col += glow * vec3(0.6, 0.4, 2.0); // rose + + // Couleurs : rose et bleu + vec3 pinkColor = vec3(0.6, 0.4, 2.0); + vec3 blueColor = vec3(1.0, 0.5, 0.0); + + // On dessine HEART_COUNT cœurs + for (int i = 0; i < HEART_COUNT; i++) { + float offset = float(i) * 3.4; + + // Distance au tracé du cœur + float dist = getSegment(t, pos, offset); + + // Trait lumineux + float line = smoothstep(lineWidth + 0.001, lineWidth - 0.001, dist); + + // Halo + float glow = getGlow(dist, radius, intensity); + + // Alterne rose / bleu + vec3 heartColor = (i % 2 == 0) ? pinkColor : blueColor; + + // Ajout du trait + col += line * heartColor; + + // Ajout du halo + col += glow * heartColor; + } + + // On limite la valeur maximale (pour éviter la sur-saturation) + col = clamp(col, 0.0, 3.0); + // Tone mapping et correction gamma col = 1.0 - exp(-col); col = pow(col, vec3(0.4545)); - + + // Conversion vers int int r = int(255.0 * col.r); int g = int(255.0 * col.g); int b = int(255.0 * col.b); int color = (0xFF << 24) | (r << 16) | (g << 8) | b; - + + // On écrit la couleur finale data_0[p] = color; } - -// comment -// comme \ No newline at end of file From df2f060e0cfbceb5fff9f59068fca3e796caa675 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Thu, 13 Mar 2025 17:23:12 +0100 Subject: [PATCH 35/37] up --- examples/heart/heart.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index f843c87..d189519 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -80,7 +80,3 @@ void main() { data_0[p] = color; } - - -// comment -// comme \ No newline at end of file From 28e50c0b4bb4dac470e6ee4a3a8afed6a81bc0ae Mon Sep 17 00:00:00 2001 From: radia0203 Date: Tue, 18 Mar 2025 08:17:31 +0100 Subject: [PATCH 36/37] modif --- examples/example_5.tscn | 2 +- project.godot | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_5.tscn b/examples/example_5.tscn index 83c022e..b1d6e72 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" uid="uid://bxee45ox6kfs2" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_cogap"] +[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_cogap"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_pm7bb"] diff --git a/project.godot b/project.godot index 0436dd7..1617345 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.2", "Forward Plus") +config/features=PackedStringArray("4.4", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From 5c948d298ac92011ede2d65a5764441475492c53 Mon Sep 17 00:00:00 2001 From: radia0203 Date: Tue, 18 Mar 2025 09:36:14 +0100 Subject: [PATCH 37/37] version finale --- examples/heart/heart.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/heart/heart.cpp b/examples/heart/heart.cpp index c49c512..1a7301a 100644 --- a/examples/heart/heart.cpp +++ b/examples/heart/heart.cpp @@ -114,3 +114,4 @@ void main() { data_0[p] = color; } +// \ No newline at end of file