diff --git a/.gitattributes b/.gitattributes old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index d0650cc..81f0be2 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ mono_crash.*.json .DS_Store screenshots/.DS_Store *.tmp + +# Editor-specific ignores +.vscode/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "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..c7bd280 --- /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": false, + "cwd": "/media/clem/SSD-Clem/master/m1/s8/AAP/godot/ComputeShaderStudio/examples/backgroundClement", + "program": "/media/clem/SSD-Clem/master/m1/s8/AAP/godot/ComputeShaderStudio/examples/backgroundClement/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..3e5eb95 --- /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_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 diff --git a/ComputeShaderStudio-eb203f3312bfe10069dc51702b02feeb7168a6c1/examples/g.tscn b/ComputeShaderStudio-eb203f3312bfe10069dc51702b02feeb7168a6c1/examples/g.tscn new file mode 100644 index 0000000..a5444f2 --- /dev/null +++ b/ComputeShaderStudio-eb203f3312bfe10069dc51702b02feeb7168a6c1/examples/g.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://c602ywnkwddt3"] + +[node name="G" type="Node2D"] diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/addons/compute_shader_studio/compute_shader_studio_2d.gd b/addons/compute_shader_studio/compute_shader_studio_2d.gd index 1e71089..fcc6481 100644 --- a/addons/compute_shader_studio/compute_shader_studio_2d.gd +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd @@ -352,3 +352,7 @@ func screen_to_data0(pos : Vector2): return pos; else: return Vector2(0,0) + + +func _on_check_button_button_up() -> void: + pass # Replace with function body. diff --git a/addons/compute_shader_studio/compute_shader_studio_plugin.gd b/addons/compute_shader_studio/compute_shader_studio_plugin.gd old mode 100644 new mode 100755 diff --git a/addons/compute_shader_studio/icon.png b/addons/compute_shader_studio/icon.png old mode 100644 new mode 100755 diff --git a/addons/compute_shader_studio/plugin.cfg b/addons/compute_shader_studio/plugin.cfg old mode 100644 new mode 100755 diff --git a/doc/ComputeShaderStudio.pdf b/doc/ComputeShaderStudio.pdf old mode 100644 new mode 100755 diff --git a/examples/LabelStepPass.gd b/examples/LabelStepPass.gd old mode 100644 new mode 100755 diff --git a/examples/basic_examples/example_2.tscn b/examples/basic_examples/example_2.tscn index a843389..a7744a9 100644 --- a/examples/basic_examples/example_2.tscn +++ b/examples/basic_examples/example_2.tscn @@ -37,10 +37,10 @@ horizontal_alignment = 1 vertical_alignment = 1 [node name="Label2" type="Label" parent="."] -offset_left = 29.0 -offset_top = 76.0 -offset_right = 336.0 -offset_bottom = 405.0 +offset_left = -80.0 +offset_top = 41.0 +offset_right = 227.0 +offset_bottom = 370.0 scale = Vector2(1.72, 1.72) text = "// Select the node ComputeShader // to write your GLSL code diff --git a/examples/basic_examples/example_3.tscn b/examples/basic_examples/example_3.tscn index 8d0b838..22b65db 100644 --- a/examples/basic_examples/example_3.tscn +++ b/examples/basic_examples/example_3.tscn @@ -4,7 +4,7 @@ [ext_resource type="Script" uid="uid://jw3o2qu3a0pl" 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"] +[node name="CompShadStudioEx4" type="Node2D"] [node name="ComputeShaderStudio2D2" type="Node" parent="." node_paths=PackedStringArray("data")] script = ExtResource("1_eimw3") diff --git a/examples/basic_examples/example_5.cpp b/examples/basic_examples/example_5.cpp old mode 100644 new mode 100755 index 5c9ebc2..b3a2bac --- a/examples/basic_examples/example_5.cpp +++ b/examples/basic_examples/example_5.cpp @@ -1,11 +1,39 @@ -// Write your code HERE void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - int dx = int(WSX)/2 - int(x); - int dy = int(WSY)/2 - int(y); - int r = int(64.0*sin(step/100.0)); - int d = int(dx*dx+dy*dy) ; - data_0[p] = 0xFF000000 - 600* (d + step) ; + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + int dx = int(WSX) / 2 - int(x); + int dy = int(WSY) / 2 - int(y); + + int d = dx * dx + dy * dy; + + // Condition : après 5 secondes (ajuste la valeur selon ton framerate) + if (step > 300) { // Après 5 secondes -> Afficher les cercles + + float d = sqrt(float(dx * dx + dy * dy)); // Distance au centre + + // Animation des cercles (pulsation) + float amplitude = 10.0; // Amplitude de la pulsation + float vitesse = 0.08; // Vitesse de l'effet + float animatedD = d + amplitude * sin(float(step) * vitesse); + + // Espacement animé des cercles + float spacing = 30.0 + 10.0 * sin(float(step) * 0.1); + + // Calcul des cercles noirs avec un motif en anneaux + float rings = mod(animatedD, spacing); + bool isBlack = rings < 6.0; // Épaisseur des anneaux noirs + + if (isBlack) { + data_0[p] = 0xFF000000; // Noir + } else { + data_0[p] = 0xFF800080; // Fond violet + } + + } else { + int value = clamp(600 * (d + int(step)), 0, 0xFFFFFF); + data_0[p] = 0xFF000000 | (0xFFFFFF - value); // Rendu normal + } } + diff --git a/examples/basic_examples/example_5.tscn b/examples/basic_examples/example_5.tscn index b54d2e0..2d7ca12 100644 --- a/examples/basic_examples/example_5.tscn +++ b/examples/basic_examples/example_5.tscn @@ -2,12 +2,12 @@ [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"] +[sub_resource type="FastNoiseLite" id="FastNoiseLite_ynclj"] [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_nxi5j"] width = 256 height = 128 -noise = SubResource("FastNoiseLite_pm7bb") +noise = SubResource("FastNoiseLite_ynclj") [node name="CompShadStudioEx5" type="Node2D"] @@ -31,8 +31,8 @@ horizontal_alignment = 1 vertical_alignment = 1 [node name="TextureRect" type="TextureRect" parent="."] -offset_left = 278.0 -offset_top = 192.0 -offset_right = 975.0 -offset_bottom = 629.0 +offset_left = -10.0 +offset_top = -26.0 +offset_right = 1171.0 +offset_bottom = 667.0 texture = SubResource("NoiseTexture2D_nxi5j") diff --git a/examples/cells/cells.gd b/examples/cells/cells.gd old mode 100644 new mode 100755 diff --git a/examples/cells/example_cells.c b/examples/cells/example_cells.c old mode 100644 new mode 100755 diff --git a/examples/cells/example_cells.tscn b/examples/cells/example_cells.tscn index 6d35843..bd0b459 100644 --- a/examples/cells/example_cells.tscn +++ b/examples/cells/example_cells.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=3 format=3 uid="uid://cutxgtalwsp6q"] +[gd_scene load_steps=5 format=3 uid="uid://cutxgtalwsp6q"] [ext_resource type="Script" uid="uid://bs2f5sxok3d3i" path="res://examples/cells/cells.gd" id="1_dw4h8"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_oji6h"] @@ -17,83 +17,19 @@ WSY = 256 nb_passes_cyto = 20 nb_passes_memb = 14 glsl_file = "res://examples/cells/example_cells.c" -data = [NodePath("CenterAnchor/Display"), null, null, null, null, null, null, null, null, null, null, null, null] +data = [null, null, null, null, null, null, null, null, null, null, null, null, null] -[node name="CenterAnchor" type="Control" parent="."] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="Display" type="Sprite2D" parent="CenterAnchor"] -texture_filter = 1 -scale = Vector2(4, 4) -texture = ExtResource("2_oji6h") - -[node name="DisplayNormalButton" type="Button" parent="."] -layout_mode = 0 -offset_left = 8.0 -offset_top = 8.0 -offset_right = 248.0 -offset_bottom = 56.0 -text = "Display Regular" - -[node name="DisplayCytoplasmButton" type="Button" parent="."] -layout_mode = 0 -offset_left = 8.0 -offset_top = 72.0 -offset_right = 248.0 -offset_bottom = 120.0 -text = "Display Cytoplasm Field" - -[node name="DisplayCytoplasmButton2" type="Button" parent="."] -layout_mode = 0 -offset_left = 8.0 -offset_top = 136.0 -offset_right = 248.0 -offset_bottom = 184.0 -text = "Display Cytoplasm Field (Flat)" - -[node name="DisplayMembranes" type="Button" parent="."] -layout_mode = 0 -offset_left = 8.0 -offset_top = 200.0 -offset_right = 248.0 -offset_bottom = 248.0 -text = "Display Membranes" +[node name="ComputeShaderStudio2D2" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("2_6o5l7") +WSX = 256 +glsl_file = "res://examples/project/base.cpp" +GLSL_code = "" +data = [null] -[node name="DisplayMembraneField" type="Button" parent="."] +[node name="TextureRect" type="TextureRect" parent="."] layout_mode = 0 -offset_left = 8.0 -offset_top = 264.0 -offset_right = 248.0 -offset_bottom = 312.0 -text = "Display Membrane Field" - -[node name="RichTextLabel" type="RichTextLabel" parent="."] -layout_mode = 1 -anchors_preset = 11 -anchor_left = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -320.0 -grow_horizontal = 0 -grow_vertical = 2 -theme_override_font_sizes/normal_font_size = 20 -text = "- Step 1: Plop cytoplasm fields at center positions -- Step 2: Diffuse cytoplasm field -- Step 3: At cytoplasm edges, plop membranes -- Step 4: Diffuse membrane field -- Step 5: At centers, push in direction where membrane field is weakest -- Step 6: move centers -- Display & Repeat" - -[connection signal="pressed" from="DisplayNormalButton" to="." method="set_display_normal"] -[connection signal="pressed" from="DisplayCytoplasmButton" to="." method="set_display_cytoplasm"] -[connection signal="pressed" from="DisplayCytoplasmButton2" to="." method="set_display_cytoplasm_flat"] -[connection signal="pressed" from="DisplayMembranes" to="." method="set_display_membranes"] -[connection signal="pressed" from="DisplayMembraneField" to="." method="set_display_membrane_field"] +offset_left = 127.0 +offset_top = 5.0 +offset_right = 824.0 +offset_bottom = 442.0 +texture = SubResource("NoiseTexture2D_0uqft") diff --git a/examples/circles/circles.cpp b/examples/circles/circles.cpp old mode 100644 new mode 100755 diff --git a/examples/circles/circles.tscn b/examples/circles/circles.tscn old mode 100644 new mode 100755 diff --git a/examples/example_1.cpp b/examples/example_1.cpp old mode 100644 new mode 100755 index d9cb0f8..d7cecc3 --- a/examples/example_1.cpp +++ b/examples/example_1.cpp @@ -4,4 +4,5 @@ void main() { uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; data_0[p] = 0xFFFF0000 - int(x+y*1024)*(step); + } diff --git a/examples/example_1.glsl.import b/examples/example_1.glsl.import old mode 100644 new mode 100755 diff --git a/examples/example_mandelbrot.gd b/examples/example_mandelbrot.gd new file mode 100755 index 0000000..d869fa7 --- /dev/null +++ b/examples/example_mandelbrot.gd @@ -0,0 +1,40 @@ +extends Node + +var css : Node + +var zoom : float = 1.0 +var pos : Vector2 = Vector2(-0.75, 0) + +var grab : Vector2 +var grabbing : bool = false + +func screen_to_world(screen : Vector2): + var pos_data0 : Vector2 = css.screen_to_data0(screen) + var wsize : Vector2 = Vector2(css.WSX, css.WSY); + return pos + (pos_data0 / wsize - Vector2(0.5, 0.5)) * 4.0 / zoom; + +func _ready(): + css = get_node("ComputeShaderStudio2D") + css.uniform_user_data.resize(4*3) + +func _process(_delta): + css.uniform_user_data.encode_float(0, zoom) + css.uniform_user_data.encode_float(4, pos.x) + css.uniform_user_data.encode_float(8, pos.y) + +func _input(event): + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_WHEEL_UP : + zoom *= 1.1 + elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN : + zoom /= 1.1 + elif event.button_index == MOUSE_BUTTON_LEFT : + if event.pressed : # Start panning + grab = screen_to_world(event.position) + grabbing = true + else : # Stop panning + grabbing = false + + elif event is InputEventMouse and grabbing : # Panning + var delta : Vector2 = screen_to_world(event.position) - grab + pos -= delta diff --git a/examples/example_mandelbrot.gd.uid b/examples/example_mandelbrot.gd.uid new file mode 100644 index 0000000..3e93ef9 --- /dev/null +++ b/examples/example_mandelbrot.gd.uid @@ -0,0 +1 @@ +uid://n4ra8rjo3hu diff --git a/examples/grid_512x512.png b/examples/grid_512x512.png old mode 100644 new mode 100755 diff --git a/examples/grid_image_licence.txt b/examples/grid_image_licence.txt old mode 100644 new mode 100755 diff --git a/examples/icon.svg b/examples/icon.svg old mode 100644 new mode 100755 diff --git a/examples/lenia.cpp b/examples/lenia.cpp old mode 100644 new mode 100755 diff --git a/examples/mandelbrot/example_mandelbrot.tscn b/examples/mandelbrot/example_mandelbrot.tscn old mode 100644 new mode 100755 diff --git a/examples/misc/example_laser.tscn b/examples/misc/example_laser.tscn old mode 100644 new mode 100755 diff --git a/examples/naruto/backgroundClement/TestExample.tscn b/examples/naruto/backgroundClement/TestExample.tscn new file mode 100644 index 0000000..63e7330 --- /dev/null +++ b/examples/naruto/backgroundClement/TestExample.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://ddfhk06k1ymy"] + +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_bowy1"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_n443p"] + +[node name="background" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_bowy1") +glsl_file = "res://examples/backgroundClement/background.cpp" +GLSL_code = " +" +data = [NodePath("../Sprite2D")] + +[node name="Sprite2D" type="Sprite2D" parent="."] +position = Vector2(369, 246) +scale = Vector2(3.60063, 3.6475) +texture = ExtResource("2_n443p") diff --git a/examples/naruto/backgroundClement/background.cpp b/examples/naruto/backgroundClement/background.cpp new file mode 100644 index 0000000..43f58f7 --- /dev/null +++ b/examples/naruto/backgroundClement/background.cpp @@ -0,0 +1,70 @@ +float random(vec2 st) { + return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); +} + +// inspiré par le background shadertoy suivant : https://www.shadertoy.com/view/Wf2GDt +float noise(vec2 st) { + vec2 i = floor(st); + vec2 f = fract(st); + + // Quatre coins du carré + float a = random(i); + float b = random(i + vec2(1.0, 0.0)); + float c = random(i + vec2(0.0, 1.0)); + float d = random(i + vec2(1.0, 1.0)); + + // Interpolation lisse + vec2 u = f * f * (3.0 - 2.0 * f); + + return mix(a, b, u.x) + + (c - a) * u.y * (1.0 - u.x) + + (d - b) * u.x * u.y; +} + +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + //variable time basé sur la variable step de computeShaderStudio + float iTime = step / 10.0; + vec2 fragCoord = vec2(float(x), float(y)); + vec2 iResolution = vec2(float(WSX), float(WSY)); + vec4 fragColor = vec4(0.0); + + // Conversion du code shadertoy + float t = iTime / 10.0; + + vec2 pos = 100.0 * fragCoord/(iResolution.xy); + float yPos = pos.y/100.0; + pos.y += sin(2.0*t); + pos.x += cos(5.0*t); + pos *= mat2(sin(t/2.0),-cos(t/2.0),cos(t/2.0),sin(t/2.0))/8.0; + + // Boucle de l'effet de fractale + for (float i = 0.0; i < 8.0; i++) { + fragColor = cos(pos.xxxx*0.3)*0.5+0.5; + float n = noise(pos/5.0); + fragColor *= n; + pos.x += sin(pos.y + iTime*0.3 + i); + pos *= mat2(6.0,-8.0,8.0,6.0)/8.0; + } + + // Fade vertical + fragColor *= 1.0 - smoothstep(0.0, 0.91, yPos); + + // Teinte rouge + fragColor *= vec4(0.2, 0.23, 0.54, 1.0); + + // Conversion de la couleur au format requis par le buffer + uint r = uint(min(255.0, fragColor.r * 255.0)); + uint g = uint(min(255.0, fragColor.g * 255.0)); + uint b = uint(min(255.0, fragColor.b * 255.0)); + uint alpha = 0xFF; + + // Construction de la couleur finale + uvec4 color = uvec4((alpha << 24) | (r << 16) | (g << 8) | b); + + // Écriture dans le buffer + data_0[p] = int(color.x); +} \ No newline at end of file diff --git a/examples/naruto/backgroundClement/read.me b/examples/naruto/backgroundClement/read.me new file mode 100644 index 0000000..7b3fb1d --- /dev/null +++ b/examples/naruto/backgroundClement/read.me @@ -0,0 +1 @@ +objectif : fond anime akatsuki \ No newline at end of file diff --git a/examples/naruto/project/naruto.cpp b/examples/naruto/project/naruto.cpp new file mode 100644 index 0000000..8f932d6 --- /dev/null +++ b/examples/naruto/project/naruto.cpp @@ -0,0 +1,281 @@ +#define RADIUS 40 +#define PUPIL_RADIUS 10 +#define IRIS_RADIUS 25 +#define DOT_RADIUS 3 +#define CRESCENT_OFFSET 2.0 // Décalage pour créer l'effet de croissant +#define PI 3.14159265359 // Ajout de la définition de PI +#define SMALL_DOT_RADIUS 2.0 // Rayon du petit point +#define SMALL_DOT_OFFSET 1.0 // Distance du point par rapport au croissant +#define IRIS_BORDER 0.5 // Épaisseur de la bordure de l'iris +#define LIGHT_INTENSITY 0.4 // Intensité de la lumière directionnelle +#define BLINK_INTERVAL 200 // Intervalle de clignotement (10 secondes à 20fps) +#define BLINK_DURATION 20 // Durée du clignotement (1 seconde) +#define BLINK_SPEED 0.15 // Vitesse de propagation du noir +#define TRANSITION_WIDTH 5.0 // Largeur de la transition du noir +#define ANIMATION_INTERVAL 300 // 5 secondes à 60fps +#define PULSE_AMPLITUDE 10.0 +#define PULSE_SPEED 0.08 +#define RING_SPACING 20.0 // Espacement entre les cercles +#define RING_THICKNESS 4.0 // Épaisseur des cercles +#define SPACING_VARIATION 10.0 +#define WAVE_SPEED 0.15 // Augmentation de la vitesse de propagation (anciennement 0.05) +#define TRANSITION_DURATION 60.0 // Durée de la transition en frames +#define MAX_TRANSITION_RADIUS 60.0 // Rayon maximum du cercle de transition +#define TRANSITION_OUT_START (ANIMATION_INTERVAL - TRANSITION_DURATION) + +// Ajouter les fonctions de bruit en haut du fichier +float random(vec2 st) { + return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); +} + +float noise(vec2 st) { + vec2 i = floor(st); + vec2 f = fract(st); + float a = random(i); + float b = random(i + vec2(1.0, 0.0)); + float c = random(i + vec2(0.0, 1.0)); + float d = random(i + vec2(1.0, 1.0)); + vec2 u = f * f * (3.0 - 2.0 * f); + return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; +} + +void main() +{ + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + int p = x + y * int(WSX); + + // initial background is black & opac + if (step == 0) { + data_0[p] = 0xFF000000; + } else { + float dx = float(mousex - x); + float dy = float(mousey - y); + float dist = sqrt(dx*dx + dy*dy); + + // Calcul de la lumière directionnelle + float lightDirX = 1.0; // Direction X de la lumière (vers la gauche) + float lightDirY = 1.0; // Direction Y de la lumière (vers le haut) + float normalX = dx/dist; + float normalY = dy/dist; + float lightAngle = (lightDirX * normalX + lightDirY * normalY) * 0.5 + 0.5; + + // Position des points tournants + float angle = float(step) * 0.05f; // Vitesse de rotation + float orbit_radius = (IRIS_RADIUS + PUPIL_RADIUS) * 0.5f; // Rayon de l'orbite + + // Premier point + float dot_x = mousex + orbit_radius * cos(angle); + float dot_y = mousey + orbit_radius * sin(angle); + float dot_dist = sqrt(pow(x - dot_x, 2) + pow(y - dot_y, 2)); + + // Deuxième point (décalé de 120°) + float dot2_x = mousex + orbit_radius * cos(angle + 2.0944); // 2π/3 + float dot2_y = mousey + orbit_radius * sin(angle + 2.0944); + float dot2_dist = sqrt(pow(x - dot2_x, 2) + pow(y - dot2_y, 2)); + + // Troisième point (décalé de 240°) + float dot3_x = mousex + orbit_radius * cos(angle + 4.1888); // 4π/3 + float dot3_y = mousey + orbit_radius * sin(angle + 4.1888); + float dot3_dist = sqrt(pow(x - dot3_x, 2) + pow(y - dot3_y, 2)); + + // Premier croissant - décalage orienté vers l'extérieur + float crescent1MainDist = sqrt(pow(x - dot_x, 2) + pow(y - dot_y, 2)); + float crescent1SecDist = sqrt(pow(x - (dot_x + CRESCENT_OFFSET * cos(angle + PI/2)), 2) + + pow(y - (dot_y + CRESCENT_OFFSET * sin(angle + PI/2)), 2)); + + // Deuxième croissant - décalage orienté vers l'extérieur + float crescent2MainDist = sqrt(pow(x - dot2_x, 2) + pow(y - dot2_y, 2)); + float crescent2SecDist = sqrt(pow(x - (dot2_x + CRESCENT_OFFSET * cos(angle + 2.0944 + + PI/2)), 2) + + pow(y - (dot2_y + CRESCENT_OFFSET * sin(angle + 2.0944 + + PI/2)), 2)); + + // Troisième croissant - décalage orienté vers l'extérieur + float crescent3MainDist = sqrt(pow(x - dot3_x, 2) + pow(y - dot3_y, 2)); + float crescent3SecDist = sqrt(pow(x - (dot3_x + CRESCENT_OFFSET * cos(angle + 4.1888 + + PI/2)), 2) + + pow(y - (dot3_y + CRESCENT_OFFSET * sin(angle + 4.1888 + + PI/2)), 2)); + + // Points superposés aux croissants + float dot1_center_x = dot_x - SMALL_DOT_OFFSET * cos(angle); + float dot1_center_y = dot_y - SMALL_DOT_OFFSET * sin(angle); + float small_dot1_dist = sqrt(pow(x - dot1_center_x, 2) + pow(y - dot1_center_y, 2)); + + float dot2_center_x = dot2_x - SMALL_DOT_OFFSET * cos(angle + 2.0944); + float dot2_center_y = dot2_y - SMALL_DOT_OFFSET * sin(angle + 2.0944); + float small_dot2_dist = sqrt(pow(x - dot2_center_x, 2) + pow(y - dot2_center_y, 2)); + + float dot3_center_x = dot3_x - SMALL_DOT_OFFSET * cos(angle + 4.1888); + float dot3_center_y = dot3_y - SMALL_DOT_OFFSET * sin(angle + 4.1888); + float small_dot3_dist = sqrt(pow(x - dot3_center_x, 2) + pow(y - dot3_center_y, 2)); + + // Variables nécessaires pour le background animé + float iTime = step / 10.0; // division par 10 pour ralentir l'animation + vec2 fragCoord = vec2(float(x), float(y));// Position du pixel + vec2 iResolution = vec2(float(WSX), float(WSY)); + vec4 fragColor = vec4(0.0); //couleur initiale = noir transparent + + float t = iTime / 10.0; + vec2 pos = 100.0 * fragCoord/(iResolution.xy); + float yPos = pos.y/100.0; + // mouvement oscillaoire vertical et horizontal + pos.y += sin(2.0*t); + pos.x += cos(5.0*t); + // rotation progressive de l'effet + pos *= mat2(sin(t/2.0),-cos(t/2.0),cos(t/2.0),sin(t/2.0))/8.0; + + // Boucle gérant l'effet de fractale + for (float i = 0.0; i < 8.0; i++) { + //motif de base répétés avec transitions douces + fragColor = cos(pos.xxxx*0.3)*0.5+0.5; + //ajout de bruit de Perlin pour un effet de texture organique + float n = noise(pos/5.0); + //multiplie la couleur par le bruit de Perlin + fragColor *= n; + //deformation ondulatoire horizontale + pos.x += sin(pos.y + iTime*0.3 + i); + //deformation ondulatoire verticale + pos *= mat2(6.0,-8.0,8.0,6.0)/8.0; + } + + //fade vertical + fragColor *= 1.0 - smoothstep(0.0, 0.91, yPos); + + //teinte rouge + fragColor *= vec4(0.2, 0.23, 0.54, 1.0); + + // Conversion de la couleur du fond float -> int + uint r = uint(min(255.0, fragColor.r * 255.0)); + uint g = uint(min(255.0, fragColor.g * 255.0)); + uint b = uint(min(255.0, fragColor.b * 255.0)); + uint background_color = 0xFF000000 | (r << 16) | (g << 8) | b; + + if (dist < RADIUS) { + float z = sqrt(RADIUS*RADIUS - dist*dist); + float normal_z = z/RADIUS; + float light = normal_z; + light = clamp(light * (0.7 + lightAngle * LIGHT_INTENSITY), 0.2f, 1.0f); + + // Alternance entre les animations + bool usePulsingAnimation = ((step / ANIMATION_INTERVAL) % 2) == 1; + + if (usePulsingAnimation) { + float d = sqrt(dx * dx + dy * dy); + float cycleStart = float(step % ANIMATION_INTERVAL); + + // Gestion des transitions + if (cycleStart < TRANSITION_DURATION) { + // Transition d'entrée (comme avant) + float transitionRadius = (cycleStart / TRANSITION_DURATION) * MAX_TRANSITION_RADIUS; + + if (d < transitionRadius) { + // Nouvelle animation + float animatedD = d - float(step) * WAVE_SPEED; + float rings = mod(animatedD, RING_SPACING); + + if (rings < RING_THICKNESS) { + data_0[p] = 0xFF000000; + } else { + int value = int(255.0f * light); + int red = int(180.0f * light); // Augmenté de 128 à 180 + int green = 0; + int blue = int(180.0f * light); // Augmenté de 128 à 180 + data_0[p] = 0xFF000000 | (red << 16) | (green << 8) | blue; + } + } else { + // Animation normale + if (dist < PUPIL_RADIUS) { + data_0[p] = 0xFF000000; + } + // ...reste du code de l'animation normale... + } + } else if (cycleStart > TRANSITION_OUT_START) { + // Transition de sortie + float transitionOutProgress = (cycleStart - TRANSITION_OUT_START) / TRANSITION_DURATION; + float fadeRadius = (1.0 - transitionOutProgress) * MAX_TRANSITION_RADIUS; + + if (d < fadeRadius) { + // Zone encore visible de l'animation des cercles + float animatedD = d - float(step) * WAVE_SPEED; + float rings = mod(animatedD, RING_SPACING); + + if (rings < RING_THICKNESS) { + data_0[p] = 0xFF000000; + } else { + int value = int(255.0f * light); + int red = int(180.0f * light); // Augmenté de 128 à 180 + int green = 0; + int blue = int(180.0f * light); // Augmenté de 128 à 180 + data_0[p] = 0xFF000000 | (red << 16) | (green << 8) | blue; + } + } else { + // Zone qui revient à l'animation normale + if (dist < PUPIL_RADIUS) { + data_0[p] = 0xFF000000; + } else if (dist < IRIS_RADIUS) { + if ((crescent1MainDist < DOT_RADIUS && crescent1SecDist > DOT_RADIUS - 1.0) || + (crescent2MainDist < DOT_RADIUS && crescent2SecDist > DOT_RADIUS - 1.0) || + (crescent3MainDist < DOT_RADIUS && crescent3SecDist > DOT_RADIUS - 1.0) || + small_dot1_dist < SMALL_DOT_RADIUS || + small_dot2_dist < SMALL_DOT_RADIUS || + small_dot3_dist < SMALL_DOT_RADIUS) { + data_0[p] = 0xFF000000; + } else if (dist > IRIS_RADIUS - IRIS_BORDER) { + data_0[p] = 0xFF404040; + } else { + int red = int(200.0f * light); + data_0[p] = 0xFF000000 | red; + } + } else { + int value = int(255.0f * light); + int red = value; + int green = int(value * 0.95); + int blue = int(value * 0.9); + data_0[p] = 0xFF000000 | (red << 16) | (green << 8) | blue; + } + } + } else { + // Animation complète des cercles (entre les deux transitions) + float animatedD = d - float(step) * WAVE_SPEED; + float rings = mod(animatedD, RING_SPACING); + + if (rings < RING_THICKNESS) { + data_0[p] = 0xFF000000; + } else { + int value = int(255.0f * light); + int red = int(180.0f * light); // Augmenté de 128 à 180 + int green = 0; + int blue = int(180.0f * light); // Augmenté de 128 à 180 + data_0[p] = 0xFF000000 | (red << 16) | (green << 8) | blue; + } + } + } else { + // Animation normale + if (dist < PUPIL_RADIUS) { + data_0[p] = 0xFF000000; + } else if (dist < IRIS_RADIUS) { + if ((crescent1MainDist < DOT_RADIUS && crescent1SecDist > DOT_RADIUS - 1.0) || + (crescent2MainDist < DOT_RADIUS && crescent2SecDist > DOT_RADIUS - 1.0) || + (crescent3MainDist < DOT_RADIUS && crescent3SecDist > DOT_RADIUS - 1.0) || + small_dot1_dist < SMALL_DOT_RADIUS || + small_dot2_dist < SMALL_DOT_RADIUS || + small_dot3_dist < SMALL_DOT_RADIUS) { + data_0[p] = 0xFF000000; + } else if (dist > IRIS_RADIUS - IRIS_BORDER) { + data_0[p] = 0xFF404040; + } else { + int red = int(200.0f * light); + data_0[p] = 0xFF000000 | red; + } + } else { + int value = int(255.0f * light); + int red = value; + int green = int(value * 0.95); + int blue = int(value * 0.9); + data_0[p] = 0xFF000000 | (red << 16) | (green << 8) | blue; + } + } + } else { + data_0[p] = int(background_color); // Fond animé au lieu de gris moyen + } + } +} + diff --git a/examples/naruto/project/scene-finale.tscn b/examples/naruto/project/scene-finale.tscn new file mode 100644 index 0000000..799cfb1 --- /dev/null +++ b/examples/naruto/project/scene-finale.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://duh7anebdiq5r"] + +[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_o3uyj"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_gpcd8"] + +[node name="finale" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_o3uyj") +glsl_file = "res://examples/naruto/project/naruto.cpp" +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(685, 320) +scale = Vector2(5.3125, 5.03125) +texture = ExtResource("2_gpcd8") diff --git a/examples/naruto/read.me b/examples/naruto/read.me new file mode 100644 index 0000000..ac6bf62 --- /dev/null +++ b/examples/naruto/read.me @@ -0,0 +1,15 @@ +Projet godot Naruto : + +Membres du groupe : +Réda Lahdoudi +Saad Madi-Soilihi +Clément Nassih + +Sur git nous avons chacun travaillé dans notre propre branche avant de merge pour fusionner nos différents résultats et obtenir le résultat final que nous vous avons présenté en cours + +Pour la réalisation de notre projet nous nous sommes aidés de l'ia claude via github copilot. +Le background a été inspiré par le shadertoy suivant : https://www.shadertoy.com/view/Wf2GDt + +Dans le sous dossier backgroundClement vous pourrez retrouver le code pour le background seul. +Dans le sous dossier rinnegan saad, vous retroverez la seuxième animation violette appliquée sur l'oeil du rendu final. +Le rendu final se trouve dans le sous dossier project et le fichier naruto.cpp \ No newline at end of file diff --git a/examples/naruto/rinnegan saad/example_5.cpp b/examples/naruto/rinnegan saad/example_5.cpp new file mode 100644 index 0000000..b3a2bac --- /dev/null +++ b/examples/naruto/rinnegan saad/example_5.cpp @@ -0,0 +1,39 @@ +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + int dx = int(WSX) / 2 - int(x); + int dy = int(WSY) / 2 - int(y); + + int d = dx * dx + dy * dy; + + // Condition : après 5 secondes (ajuste la valeur selon ton framerate) + if (step > 300) { // Après 5 secondes -> Afficher les cercles + + float d = sqrt(float(dx * dx + dy * dy)); // Distance au centre + + // Animation des cercles (pulsation) + float amplitude = 10.0; // Amplitude de la pulsation + float vitesse = 0.08; // Vitesse de l'effet + float animatedD = d + amplitude * sin(float(step) * vitesse); + + // Espacement animé des cercles + float spacing = 30.0 + 10.0 * sin(float(step) * 0.1); + + // Calcul des cercles noirs avec un motif en anneaux + float rings = mod(animatedD, spacing); + bool isBlack = rings < 6.0; // Épaisseur des anneaux noirs + + if (isBlack) { + data_0[p] = 0xFF000000; // Noir + } else { + data_0[p] = 0xFF800080; // Fond violet + } + + } else { + int value = clamp(600 * (d + int(step)), 0, 0xFFFFFF); + data_0[p] = 0xFF000000 | (0xFFFFFF - value); // Rendu normal + } +} + diff --git a/examples/naruto/rinnegan saad/example_5.tscn b/examples/naruto/rinnegan saad/example_5.tscn new file mode 100644 index 0000000..7b8bed2 --- /dev/null +++ b/examples/naruto/rinnegan saad/example_5.tscn @@ -0,0 +1,38 @@ +[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"] + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_ynclj"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_nxi5j"] +width = 256 +height = 128 +noise = SubResource("FastNoiseLite_ynclj") + +[node name="CompShadStudioEx5" type="Node2D"] + +[node name="ComputeShaderStudio2D2" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_cogap") +WSX = 256 +glsl_file = "res://examples/example_5.cpp" +GLSL_code = "" +data = [NodePath("../TextureRect")] + +[node name="Label" type="Label" parent="."] +offset_left = 278.0 +offset_top = -1.0 +offset_right = 679.0 +offset_bottom = 101.0 +scale = Vector2(1.72, 1.72) +text = "Compute Shader Studio +Example 5: using an external GLSL file +and a TextureRect" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="TextureRect" type="TextureRect" parent="."] +offset_left = -10.0 +offset_top = -26.0 +offset_right = 1171.0 +offset_bottom = 667.0 +texture = SubResource("NoiseTexture2D_nxi5j") diff --git a/examples/simple circle/simple_circle.cpp b/examples/simple circle/simple_circle.cpp new file mode 100755 index 0000000..5526980 --- /dev/null +++ b/examples/simple circle/simple_circle.cpp @@ -0,0 +1,21 @@ +void main() { + + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y*WSX; + + if (step == 0) // init + data_0[p] = int(0xFF0000FF - y) ; // Fond + else { + float dx = float(mousex) - float(x) ; + float dy = float(mousey) - float(y) ; + float dist = sqrt( dx*dx + dy*dy ); + + if (dist < 10) { + data_0[p] = 0xFF00FF00; // Cercle vert + } else { + data_0[p] = int(0xFF0000FF - y) ; // Fond + } + + } +} \ No newline at end of file diff --git a/examples/simple circle/simple_circle.tscn b/examples/simple circle/simple_circle.tscn new file mode 100755 index 0000000..3a07914 --- /dev/null +++ b/examples/simple circle/simple_circle.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://c63rtjh0eurgm"] + +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_rlapi"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_y7slp"] + +[node name="SimpleCircle" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_rlapi") +glsl_file = "res://examples/simple_circle/simple_circle.cpp" +data = [NodePath("../Icon")] +metadata/_custom_type_script = "uid://c8esqdv0y26yp" + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(465.5, 268.5) +scale = Vector2(3.99219, 3.52344) +texture = ExtResource("2_y7slp") diff --git a/node_2d.tscn b/node_2d.tscn new file mode 100755 index 0000000..bf99e3c --- /dev/null +++ b/node_2d.tscn @@ -0,0 +1,3 @@ +[gd_scene load_steps=0 format=3 uid="uid://dyux3ncnsf1xc"] + +[node name="Node2D" type="Node2D"] diff --git a/project.godot b/project.godot index 1617345..2eeea6e 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="compute_shader_studio" -run/main_scene="res://examples/example_1.tscn" +run/main_scene="uid://duh7anebdiq5r" config/features=PackedStringArray("4.4", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" diff --git a/screenshots/.DS_Store b/screenshots/.DS_Store old mode 100644 new mode 100755 diff --git a/screenshots/.gdignore b/screenshots/.gdignore old mode 100644 new mode 100755 diff --git a/screenshots/compute_shader_studio_ex2.png b/screenshots/compute_shader_studio_ex2.png old mode 100644 new mode 100755 diff --git a/screenshots/compute_shader_studio_ext_glsl.png b/screenshots/compute_shader_studio_ext_glsl.png old mode 100644 new mode 100755 diff --git a/screenshots/compute_shader_studio_headline.png b/screenshots/compute_shader_studio_headline.png old mode 100644 new mode 100755 diff --git a/screenshots/compute_shader_studio_mandelbrot.png b/screenshots/compute_shader_studio_mandelbrot.png old mode 100644 new mode 100755