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..fd17536 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false, + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/examples/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_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/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_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_lenia_test.tscn b/examples/example_lenia_test.tscn index 118ec4d..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" 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" 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_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..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" uid="uid://c8esqdv0y26yp" 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/.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 new file mode 100644 index 0000000..1a7301a --- /dev/null +++ b/examples/heart/heart.cpp @@ -0,0 +1,117 @@ +#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.2; +const float len = 0.2; +const float scale = 0.012; + +// 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) + ); +} + +// Fonction de glow +float getGlow(float dist, float radius, float 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 + ); + } + + float dist = 10000.0; + for (int i = 0; i < POINT_COUNT - 1; i++) { + float segDist = distToLine(pos, scale * points[i], scale * points[i + 1]); + dist = min(dist, segDist); + } + 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; + + // Fond noir + vec3 col = vec3(0.0); + + // 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; +} + +// \ No newline at end of file diff --git a/examples/heart/heart.tscn b/examples/heart/heart.tscn new file mode 100644 index 0000000..a7b1242 --- /dev/null +++ b/examples/heart/heart.tscn @@ -0,0 +1,17 @@ +[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(465, 261) +scale = Vector2(4.36719, 3.64844) +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")] diff --git a/heart.tscn b/heart.tscn new file mode 100644 index 0000000..30047b8 --- /dev/null +++ b/heart.tscn @@ -0,0 +1,18 @@ +[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(606, 338.5) +scale = Vector2(5.07813, 4.25781) +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 new file mode 100644 index 0000000..1dc95b1 --- /dev/null +++ b/node_2d.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://cudof00lg11dw"] + +[node name="Node2D" type="Node2D"]