From 8eecae6e943463e23a1705abfe178b2aec073ecd Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Wed, 5 Mar 2025 10:36:46 +0100 Subject: [PATCH 01/13] Create GgProject.c --- GgProject.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 GgProject.c diff --git a/GgProject.c b/GgProject.c new file mode 100644 index 0000000..e69de29 From cdea06b3a88190391f4899792f955efa28714b79 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Wed, 5 Mar 2025 12:09:06 +0100 Subject: [PATCH 02/13] damier de 4 cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Réalisation d'un damier de 4 cases --- GgProject.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ GgProject.tscn | 17 ++++++ project.godot | 2 +- 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 GgProject.tscn diff --git a/GgProject.c b/GgProject.c index e69de29..5c21a34 100644 --- a/GgProject.c +++ b/GgProject.c @@ -0,0 +1,151 @@ + +/* +* Auteur : Gérald CALVARIN +* +* Projet Architecture et Accélérateurs Parallèles, partie Pascal Ballet : Godot, GLSL et compute shader ( tout ça pour programmation GPU) +* projet initié le 05/03/2025 +* +* Description : Ce projet va consister à faire un petit jeu de dames +* +* Étapes : 1- faire un damier (écran noir puis noir et blanc puis cases blanches et noires) +* 2- faire des pions (noirs et blancs ) +* 3- faire des déplacements +* 4- faires des actions (manger et avoir une dame) +*/ +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + + // définition de 4 variables o,r,g,b pour faciliter la gestion des couleurs + int opacite =255; + int r = 0; + int g = 0; + int b = 0; + + //définition de la dimension de chaque case + int dimension = 128/2; // dimension minimale pour 8 cases + + + //on split l'écran en 2 (noir et blanc) sur la verticale + + if((ydimension) && (x>dimension)){ + + r = r+255; + g = g+255; + b = b+255; + + } + else{ + r = 0; + g = 0; + b = 0; + } + + + //on split l'écran en 2 (noir et blanc) sur la verticale + /*if(x<(128/2)){ + r = r+255; + g = g+255; + b = b+255; + } + else{ + r = 0; + g = 0; + b = 0; + }*/ + + + // La scène prend les valeurs orgb définies + data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; + +} + + + + + + + + + + + +#if 0 + +int compter_voisin( uint x, uint y){ + return 3; +} + + +void main() { + + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + int opacite =255; + int r = 0; + int g = 0; + int b = 0; + +// Petite Animation + #if 0 + r = 0+int(x*(y+step)); + g = 0+int(y); + b = 0+int(x); + #endif + +// Division en x ou en y de 2 couleurs fixes + #if 0 + if(y<(128/2)){ + g = g+255; + } + else{ + b = b+255; + } + #endif + +#if 0 +// Initialisation jeu de la vie + if(step==0){ + if(data_0[p]>=0){ + r = 255; + g = 255; + b = 255; + } + data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; //0xFF000000+(int(x)<<16) ; // - int(p)*(step+1); + } + else{ //jeu de la vie + + int nb_v=compter_voisin(x, y); + + if((r==0) && (g==0) && (b==00)){ + if(nb_v==3){ + r = 255; + g = 255; + b = 255; + } + else{ + r = 255; + g = 255; + b = 255; + } + } + + } + + + //data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; //0xFF000000+(int(x)<<16) ; // - int(p)*(step+1); + //data_1[p] = 0xFFF00FFF ; + //data_1[p] = 0xFF0000AA + int( 1.0 + 99999.9*sin(float(x+float(step+y))/1000.0)); +#endif +} + +#endif \ No newline at end of file diff --git a/GgProject.tscn b/GgProject.tscn new file mode 100644 index 0000000..0808c7d --- /dev/null +++ b/GgProject.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://ch5kc8lmik5ef"] + +[ext_resource type="Texture2D" uid="uid://bhxau0hh6k20" path="res://addons/compute_shader_studio/icon.png" id="1_yrdup"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="2_jf41d"] + +[node name="GgProject" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(578, 324) +scale = Vector2(2.29084, 1.32645) +texture = ExtResource("1_yrdup") + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("2_jf41d") +glsl_file = "res://GgProject.c" +GLSL_code = "" +data = [NodePath("../Icon")] diff --git a/project.godot b/project.godot index 725be9c..c90e901 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="res://GgProject.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" From 27a2a5b9c9c2e2e9e3738645dba7fbad7d281f6e Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Tue, 11 Mar 2025 10:44:57 +0100 Subject: [PATCH 03/13] Update GgProject.c --- GgProject.c | 88 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/GgProject.c b/GgProject.c index 5c21a34..54571a0 100644 --- a/GgProject.c +++ b/GgProject.c @@ -23,47 +23,49 @@ void main() { int r = 0; int g = 0; int b = 0; + - //définition de la dimension de chaque case - int dimension = 128/2; // dimension minimale pour 8 cases + #if 0 + { + //définition de la dimension de chaque case + int dimension = 128/4; // dimension minimale pour 4 cases - //on split l'écran en 2 (noir et blanc) sur la verticale - - if((ydimension) && (x>dimension)){ + + //on à un damier de 4 cases - r = r+255; - g = g+255; - b = b+255; - - } - else{ - r = 0; - g = 0; - b = 0; - } + if((ydimension*2) && (x>dimension)){ + + r = r+255; + g = g+255; + b = b+255; + + } + else if((y>dimension) && (x>dimension*2)){ + + r = r+255; + g = g+255; + b = b+255; + + } + else{ + r = 0; + g = 0; + b = 0; + } - //on split l'écran en 2 (noir et blanc) sur la verticale - /*if(x<(128/2)){ - r = r+255; - g = g+255; - b = b+255; - } - else{ - r = 0; - g = 0; - b = 0; - }*/ - // La scène prend les valeurs orgb définies - data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; + // La scène prend les valeurs orgb définies + data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; + + } } @@ -72,8 +74,28 @@ void main() { +/* cercle vert qui suit la sourie sur fond rouge dégradé +//init +if(step==0){ + r=255-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){ + g=255; + } + else{ + g=0; + } +} + + +*/ From e281fe533eea5e6b59f29eff9f503c2311392aa7 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Tue, 11 Mar 2025 12:16:30 +0100 Subject: [PATCH 04/13] le damier prend forme --- GgProject.c | 254 ++++++++++++---------- examples/simple_circle/simple_circle.tscn | 2 +- project.godot | 2 +- 3 files changed, 140 insertions(+), 118 deletions(-) diff --git a/GgProject.c b/GgProject.c index 54571a0..7873b4b 100644 --- a/GgProject.c +++ b/GgProject.c @@ -12,6 +12,8 @@ * 3- faire des déplacements * 4- faires des actions (manger et avoir une dame) */ + + void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; @@ -25,39 +27,57 @@ void main() { int b = 0; - #if 0 + + + //projet principale + #if 1 { //définition de la dimension de chaque case - int dimension = 128/4; // dimension minimale pour 4 cases - + int dimension = (128/10)/2; // dimension minimale pour 4 cases + int debutX = 0; // dimension minimale pour 4 cases + int finX = dimension; // dimension minimale pour 4 cases + int debutY = dimension*2; // dimension minimale pour 4 cases + int finY = debutY+dimension; // dimension minimale pour 4 cases //on à un damier de 4 cases - - if((y=debutX) && (xdimension*2) && (x>dimension)){ - - r = r+255; - g = g+255; - b = b+255; + debutX=dimension; + finX = debutX+dimension; // dimension minimale pour 4 cases + + while(finY<128){ + if((y>=debutY) && (y=debutX) &&(xdimension) && (x>dimension*2)){ - - r = r+255; - g = g+255; - b = b+255; + // else if((y>dimension) && (x>dimension)){ + + // r = r+255; + // g = g+255; + // b = b+255; - } - else{ - r = 0; - g = 0; - b = 0; - } + // } + + // else{ + // r = 0; + // g = 0; + // b = 0; + // } @@ -66,108 +86,110 @@ void main() { data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; } - -} - - - - - - -/* cercle vert qui suit la sourie sur fond rouge dégradé - -//init -if(step==0){ - r=255-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){ - g=255; - } - else{ - g=0; - } -} - - -*/ - - - -#if 0 - -int compter_voisin( uint x, uint y){ - return 3; -} - - -void main() { - - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - - int opacite =255; - int r = 0; - int g = 0; - int b = 0; - -// Petite Animation - #if 0 - r = 0+int(x*(y+step)); - g = 0+int(y); - b = 0+int(x); #endif -// Division en x ou en y de 2 couleurs fixes - #if 0 - if(y<(128/2)){ - g = g+255; - } - else{ - b = b+255; - } - #endif -#if 0 -// Initialisation jeu de la vie - if(step==0){ - if(data_0[p]>=0){ - r = 255; - g = 255; - b = 255; + // base pour les pions + //cercle vert qui suit la sourie sur fond rouge dégradé + #if 0 + { + if(step==0){ + r=255-int(y); } - data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; //0xFF000000+(int(x)<<16) ; // - int(p)*(step+1); - } - else{ //jeu de la vie - - int nb_v=compter_voisin(x, y); - if((r==0) && (g==0) && (b==00)){ - if(nb_v==3){ - r = 255; - g = 255; - b = 255; + else{ + float dx = float(mousex) - float(x); + float dy= float(mousey) - float(y); + float dist=sqrt(dx*dx +dy*dy); + + if(dist<10){ + g=255; } else{ - r = 255; - g = 255; - b = 255; + r=255-int(y); } } - + // La scène prend les valeurs orgb définies + data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; } + #endif - - //data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; //0xFF000000+(int(x)<<16) ; // - int(p)*(step+1); - //data_1[p] = 0xFFF00FFF ; - //data_1[p] = 0xFF0000AA + int( 1.0 + 99999.9*sin(float(x+float(step+y))/1000.0)); -#endif } -#endif \ No newline at end of file + + + +//exemples précédents ==> main séparé du projet !!!!! +#if 0 +{ + + int compter_voisin( uint x, uint y){ + return 3; + } + + + void main() { + + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + int opacite =255; + int r = 0; + int g = 0; + int b = 0; + + // Petite Animation + #if 0 + r = 0+int(x*(y+step)); + g = 0+int(y); + b = 0+int(x); + #endif + + // Division en x ou en y de 2 couleurs fixes + #if 0 + if(y<(128/2)){ + g = g+255; + } + else{ + b = b+255; + } + #endif + + #if 0 + // Initialisation jeu de la vie + if(step==0){ + if(data_0[p]>=0){ + r = 255; + g = 255; + b = 255; + } + data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; //0xFF000000+(int(x)<<16) ; // - int(p)*(step+1); + } + else{ //jeu de la vie + + int nb_v=compter_voisin(x, y); + + if((r==0) && (g==0) && (b==00)){ + if(nb_v==3){ + r = 255; + g = 255; + b = 255; + } + else{ + r = 255; + g = 255; + b = 255; + } + } + + } + + + //data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; //0xFF000000+(int(x)<<16) ; // - int(p)*(step+1); + //data_1[p] = 0xFFF00FFF ; + //data_1[p] = 0xFF0000AA + int( 1.0 + 99999.9*sin(float(x+float(step+y))/1000.0)); + #endif + } +} +#endif diff --git a/examples/simple_circle/simple_circle.tscn b/examples/simple_circle/simple_circle.tscn index 8c68dd5..3a07914 100644 --- a/examples/simple_circle/simple_circle.tscn +++ b/examples/simple_circle/simple_circle.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://c63rtjh0eurgm"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_rlapi"] +[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"] diff --git a/project.godot b/project.godot index 725be9c..c90e901 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="res://GgProject.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" From 74da76412a854a1430076afa9c92adb07bd3ab6e Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Wed, 12 Mar 2025 17:54:41 +0100 Subject: [PATCH 05/13] Update GgProject.c --- GgProject.c | 85 +++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/GgProject.c b/GgProject.c index 7873b4b..8bbbf8e 100644 --- a/GgProject.c +++ b/GgProject.c @@ -1,4 +1,3 @@ - /* * Auteur : Gérald CALVARIN * @@ -14,6 +13,29 @@ */ +/* + + correction du prof pour un damier ! + + int case_x=int(floor(x/16.0f)); + int case_y=int(floor(y/16.0f)); + + if((case_x+case_y)%2==0){ + //case blanche + } + else{ + //case noir + } + +*/ + + struct couleur { + int r; + int g; + int b; + }; + + void main() { uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; @@ -25,63 +47,48 @@ void main() { int r = 0; int g = 0; int b = 0; - - - + int i=0; //projet principale #if 1 { + + couleur plateau[128][128]; + //définition de la dimension de chaque case - int dimension = (128/10)/2; // dimension minimale pour 4 cases + int dimension = (128/5)/2; // dimension minimale pour 4 cases int debutX = 0; // dimension minimale pour 4 cases int finX = dimension; // dimension minimale pour 4 cases - int debutY = dimension*2; // dimension minimale pour 4 cases + int debutY = 0; // dimension minimale pour 4 cases int finY = debutY+dimension; // dimension minimale pour 4 cases //on à un damier de 4 cases while(finX<128){ - if((y=debutX) && (x=debutY) && (y=debutX) &&(xdimension) && (x>dimension)){ - - // r = r+255; - // g = g+255; - // b = b+255; - - // } - - // else{ - // r = 0; - // g = 0; - // b = 0; - // } + // debutY=finY+dimension; + // finY=finY+(dimension*2); + debutX=finX+dimension; + finX=finX+(dimension*2); + //} + + } + // La scène prend les valeurs orgb définies data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r; From 2b24a3a11c465c66d6bd4cf41d61c12367a54022 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Thu, 13 Mar 2025 18:00:34 +0100 Subject: [PATCH 06/13] damier + pion mobile --- GgProject.c | 80 +++++++++++++++++++++++++++++--------------------- GgProject.tscn | 6 ++-- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/GgProject.c b/GgProject.c index 8bbbf8e..8b88910 100644 --- a/GgProject.c +++ b/GgProject.c @@ -43,7 +43,12 @@ void main() { // définition de 4 variables o,r,g,b pour faciliter la gestion des couleurs + // + définition du fond marron int opacite =255; + // int r = 92; + // int g = 64; + // int b = 51; + int r = 0; int g = 0; int b = 0; @@ -53,42 +58,49 @@ void main() { #if 1 { - - couleur plateau[128][128]; - //définition de la dimension de chaque case - int dimension = (128/5)/2; // dimension minimale pour 4 cases - int debutX = 0; // dimension minimale pour 4 cases - int finX = dimension; // dimension minimale pour 4 cases - int debutY = 0; // dimension minimale pour 4 cases - int finY = debutY+dimension; // dimension minimale pour 4 cases - - //on à un damier de 4 cases - while(finX<128){ - //while(finY<128){ - - if((y>=debutY) && (y=debutX) &&(x Date: Mon, 17 Mar 2025 09:12:32 +0100 Subject: [PATCH 07/13] Update GgProject.c --- GgProject.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/GgProject.c b/GgProject.c index 8b88910..7f16326 100644 --- a/GgProject.c +++ b/GgProject.c @@ -60,22 +60,30 @@ void main() { //définition de la dimension de chaque case int dimension = (130/10); - int cx=int(x)+(dimension/2); - int cy=int(y)+dimension/2; + + float cx = (x / dimension) * dimension + dimension / 2; + float cy = (y / dimension) * dimension + dimension / 2; if (((x / dimension) + (y / dimension)) % 2 == 0) { // Case blanche - float dx = float(mousex) - float(x); - float dy= float(mousey) - float(y); + float dx = cx - float(x); + float dy= cy - float(y); float dist=sqrt(dx*dx +dy*dy); - if(dist<(dimension/2)){ + //définition des pions noirs + if( (dist<(dimension/2)) && ( (y / dimension) < 3 )){ r = 0; g = 0; b = 0; } + //définition des pions blanc + else if( (dist<(dimension/2)) && ( (y / dimension) >= 7 ) ){ + r = 128; + g = 128; + b = 128; + } else{ r = 255; g = 255; @@ -84,15 +92,22 @@ void main() { } else { // Case marron - float dx = float(mousex) - float(x); - float dy= float(mousey) - float(y); + float dx = float(cx) - float(x); + float dy= float(cy) - float(y); float dist=sqrt(dx*dx +dy*dy); - if(dist<(dimension/2)){ + //définition des pions noirs + if( (dist<(dimension/2)) && ( (y / dimension) < 3 )){ r = 0; g = 0; b = 0; } + //définition des pions blanc + else if( (dist<(dimension/2)) && ( (y / dimension) >= 7 ) ){ + r = 128; + g = 128; + b = 128; + } else{ r = 92; g = 64; From 131721200f7166d1564b368e81b91e254ffe231e Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Mon, 17 Mar 2025 09:24:26 +0100 Subject: [PATCH 08/13] =?UTF-8?q?damier=20finial=20et=20initialis=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GgProject.c | 2 + .../compute_shader_studio_2d.gd | 21 +--- examples/example_4.tscn | 97 +++++++++++++++++++ 3 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 examples/example_4.tscn diff --git a/GgProject.c b/GgProject.c index 7f16326..851b057 100644 --- a/GgProject.c +++ b/GgProject.c @@ -114,6 +114,8 @@ void main() { b = 51; } } + + //if(mouse_button == 1){} // La scène prend les valeurs orgb définies diff --git a/addons/compute_shader_studio/compute_shader_studio_2d.gd b/addons/compute_shader_studio/compute_shader_studio_2d.gd index 1e71089..f947c2f 100644 --- a/addons/compute_shader_studio/compute_shader_studio_2d.gd +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd @@ -29,7 +29,6 @@ layout(binding = 0) buffer Params { int current_pass; int mousex; int mousey; - int mouse_button; }; """ @@ -55,21 +54,13 @@ layout(binding = 0) buffer Params { @export_file("*.cpp") var glsl_file: String ## Write your GLSL code just below or use an external file above @export_multiline var GLSL_code : String = """ -// Usable variables -// **************** -// step: execution step -// current_pass: pass number in one step -// mousex: x mouse position, mousey: y mouse position (in pixels) -// mouse_button: 0=none, 1=left, 2=right, 3=both, 4=middle mouse button -// WSX: worksize X, WSY: worksize Y -// data_0[], data_1[], etc: matrices of data. Can be viewed within a Sprite2D or TextureRect2D -// **************** // 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); + data_1[p] = 0xFF0000AA + int( 1.0 + 99999.9*sin(float(x+float(step+y))/1000.0)); } """ ## Drag and drop here your Sprite2D or TextureRect. @@ -273,20 +264,13 @@ func _process(_delta): func _update_uniforms(): var input_params : PackedInt32Array = PackedInt32Array() - # Current step input_params.append(step) - # Current pass input_params.append(current_pass) - # Mouse position var pos : Vector2 = screen_to_data0(get_viewport().get_mouse_position()) input_params.append(pos.x) input_params.append(pos.y) - # Mouse button - input_params.append(Input.get_mouse_button_mask()) - - # Binding of input_params (step, current_pass, mousex, mousey and mouse_button) var input_params_bytes := input_params.to_byte_array() buffer_params = rd.storage_buffer_create(input_params_bytes.size(), input_params_bytes) uniform_params = RDUniform.new() @@ -295,7 +279,6 @@ func _update_uniforms(): uniform_params.add_id(buffer_params) bindings[0] = uniform_params - # Binding of buffer_user (data_0, data_1, etc) buffer_user = rd.storage_buffer_create(uniform_user_data.size(), uniform_user_data) uniform_user = RDUniform.new() uniform_user.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER @@ -303,7 +286,6 @@ func _update_uniforms(): uniform_user.add_id(buffer_user) bindings[1] = uniform_user - # Uniform set of all the bindings uniform_set = rd.uniform_set_create(bindings, shader, 0) # Note: when changing the uniform set, use the same bindings Array (do not create a new Array) @@ -340,7 +322,6 @@ func _on_button_step(): func _on_button_play(): pause = false # Replace with function body. - func screen_to_data0(pos : Vector2): if data.size() <= 0 : return Vector2(0, 0) diff --git a/examples/example_4.tscn b/examples/example_4.tscn new file mode 100644 index 0000000..153d6db --- /dev/null +++ b/examples/example_4.tscn @@ -0,0 +1,97 @@ +[gd_scene load_steps=3 format=3 uid="uid://bg2ni580ra7pa"] + +[ext_resource type="Script" 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"] + +[node name="Label" type="Label" parent="."] +offset_left = 0.999908 +offset_top = 1.0 +offset_right = 232.0 +offset_bottom = 60.0 +scale = Vector2(1.72, 1.72) +text = "Compute Shader Studio +Example 4: BIG Game Of Life" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ComputeShaderStudio2D2" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_ke3fj") +pause = true +nb_passes = 2 +WSX = 512 +WSY = 512 +GLSL_code = "// Write your code HERE +#define ALIVE 0xFFFFFFFF +#define DEAD 0xFF0000FF + +void compute_next_step(uint x, uint y, uint p) { + if ( x > 0 && y > 0 && x < WSX-1 && y < WSY - 1) { // in sandbox + uint n = 0 ; // Number of living neighbors + for (uint i = x-1; i <= x+1; i++) { + for (uint j = y-1; j <= y+1; j++) { + uint k = i + j * WSX; + if (k != p && data_0[k] == ALIVE ) + n++; + } + } + if (data_0[p] == DEAD) { + if ( n == 3) + data_1[p] = ALIVE; // Birth + else + data_1[p] = DEAD ; + } else { // ALIVE + if (n <=1 || n >= 4) // Under or over population + data_1[p] = DEAD; + else + data_1[p] = ALIVE; // Survive + } + } +} + +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + if ( step == 0 ) { // initialisation ************************ + if ( current_pass == 0 ) { + data_1[p] = DEAD ; + if (data_0[p] < 0 || x==0 || y==0 || x==WSX-1 || y==WSY-1) + data_0[p] = DEAD ; + else + data_0[p] = ALIVE ; + } + } else { // in process ********************************* + if (current_pass == 0) + compute_next_step(x, y, p); + else + data_0[p] = data_1[p]; // The future is now + } +} +" +data = [NodePath("../Grid512x512_0"), null] + +[node name="ButtonStep" type="Button" parent="."] +offset_left = 91.0 +offset_top = 131.0 +offset_right = 182.0 +offset_bottom = 162.0 +scale = Vector2(2.4, 2.4) +text = "Step" + +[node name="ButtonPlay" type="Button" parent="."] +offset_left = 92.0 +offset_top = 219.0 +offset_right = 183.0 +offset_bottom = 250.0 +scale = Vector2(2.4, 2.4) +text = "Play" + +[node name="Grid512x512_0" type="Sprite2D" parent="."] +position = Vector2(762.7, 314.7) +scale = Vector2(1.2, 1.2) +texture = ExtResource("2_flqlh") + +[connection signal="pressed" from="ButtonStep" to="ComputeShaderStudio2D2" method="_on_button_step"] +[connection signal="pressed" from="ButtonPlay" to="ComputeShaderStudio2D2" method="_on_button_play"] From 782a46bc57218955e13e7b69ffb5238870610331 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Mon, 17 Mar 2025 09:31:29 +0100 Subject: [PATCH 09/13] resources update --- GgProject.c | 2 +- examples/circles/circles.tscn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GgProject.c b/GgProject.c index 851b057..1db8661 100644 --- a/GgProject.c +++ b/GgProject.c @@ -115,7 +115,7 @@ void main() { } } - //if(mouse_button == 1){} + if(mouse_button == 1){} // La scène prend les valeurs orgb définies diff --git a/examples/circles/circles.tscn b/examples/circles/circles.tscn index c66e724..1916a5c 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" 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"] From 4cb451e0649d8a52d37825d0afd5b818f72ebd77 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Mon, 17 Mar 2025 09:36:46 +0100 Subject: [PATCH 10/13] rsc update --- examples/simple_circle/simple_circle.tscn | 5 +---- project.godot | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/simple_circle/simple_circle.tscn b/examples/simple_circle/simple_circle.tscn index e8a9c92..0fe95b4 100644 --- a/examples/simple_circle/simple_circle.tscn +++ b/examples/simple_circle/simple_circle.tscn @@ -5,11 +5,8 @@ [node name="SimpleCircle" type="Node2D"] -[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +[node name="ComputeShaderStudio2D" type="Node" parent="."] script = ExtResource("1_rlapi") -WSX = 256 -glsl_file = "res://examples/simple_circle/simple_circle.cpp" -data = [NodePath("../Icon")] metadata/_custom_type_script = "uid://c8esqdv0y26yp" [node name="Icon" type="Sprite2D" parent="."] diff --git a/project.godot b/project.godot index c90e901..89c5daa 100644 --- a/project.godot +++ b/project.godot @@ -14,7 +14,3 @@ config/name="compute_shader_studio" run/main_scene="res://GgProject.tscn" 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") From 3a8981fc3d9ebe42706ed606f860fd49db3b9635 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Mon, 17 Mar 2025 09:50:36 +0100 Subject: [PATCH 11/13] . --- .../compute_shader_studio_2d.gd | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/addons/compute_shader_studio/compute_shader_studio_2d.gd b/addons/compute_shader_studio/compute_shader_studio_2d.gd index f947c2f..1e71089 100644 --- a/addons/compute_shader_studio/compute_shader_studio_2d.gd +++ b/addons/compute_shader_studio/compute_shader_studio_2d.gd @@ -29,6 +29,7 @@ layout(binding = 0) buffer Params { int current_pass; int mousex; int mousey; + int mouse_button; }; """ @@ -54,13 +55,21 @@ layout(binding = 0) buffer Params { @export_file("*.cpp") var glsl_file: String ## Write your GLSL code just below or use an external file above @export_multiline var GLSL_code : String = """ +// Usable variables +// **************** +// step: execution step +// current_pass: pass number in one step +// mousex: x mouse position, mousey: y mouse position (in pixels) +// mouse_button: 0=none, 1=left, 2=right, 3=both, 4=middle mouse button +// WSX: worksize X, WSY: worksize Y +// data_0[], data_1[], etc: matrices of data. Can be viewed within a Sprite2D or TextureRect2D +// **************** // 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); - data_1[p] = 0xFF0000AA + int( 1.0 + 99999.9*sin(float(x+float(step+y))/1000.0)); } """ ## Drag and drop here your Sprite2D or TextureRect. @@ -264,13 +273,20 @@ func _process(_delta): func _update_uniforms(): var input_params : PackedInt32Array = PackedInt32Array() + # Current step input_params.append(step) + # Current pass input_params.append(current_pass) + # Mouse position var pos : Vector2 = screen_to_data0(get_viewport().get_mouse_position()) input_params.append(pos.x) input_params.append(pos.y) + # Mouse button + input_params.append(Input.get_mouse_button_mask()) + + # Binding of input_params (step, current_pass, mousex, mousey and mouse_button) var input_params_bytes := input_params.to_byte_array() buffer_params = rd.storage_buffer_create(input_params_bytes.size(), input_params_bytes) uniform_params = RDUniform.new() @@ -279,6 +295,7 @@ func _update_uniforms(): uniform_params.add_id(buffer_params) bindings[0] = uniform_params + # Binding of buffer_user (data_0, data_1, etc) buffer_user = rd.storage_buffer_create(uniform_user_data.size(), uniform_user_data) uniform_user = RDUniform.new() uniform_user.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER @@ -286,6 +303,7 @@ func _update_uniforms(): uniform_user.add_id(buffer_user) bindings[1] = uniform_user + # Uniform set of all the bindings uniform_set = rd.uniform_set_create(bindings, shader, 0) # Note: when changing the uniform set, use the same bindings Array (do not create a new Array) @@ -322,6 +340,7 @@ func _on_button_step(): func _on_button_play(): pause = false # Replace with function body. + func screen_to_data0(pos : Vector2): if data.size() <= 0 : return Vector2(0, 0) From 70c6b3b519800e0031d398fe00fe81cfba6344a6 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Mon, 17 Mar 2025 10:10:39 +0100 Subject: [PATCH 12/13] =?UTF-8?q?damier=20avec=20pi=C3=A8ces=20qui=20s'?= =?UTF-8?q?=C3=A9clairent=20au=20clic=20de=20souris?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GgProject.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/GgProject.c b/GgProject.c index 1db8661..3806cd2 100644 --- a/GgProject.c +++ b/GgProject.c @@ -68,27 +68,10 @@ void main() { if (((x / dimension) + (y / dimension)) % 2 == 0) { // Case blanche - float dx = cx - float(x); - float dy= cy - float(y); - float dist=sqrt(dx*dx +dy*dy); - - //définition des pions noirs - if( (dist<(dimension/2)) && ( (y / dimension) < 3 )){ - r = 0; - g = 0; - b = 0; - } - //définition des pions blanc - else if( (dist<(dimension/2)) && ( (y / dimension) >= 7 ) ){ - r = 128; - g = 128; - b = 128; - } - else{ - r = 255; - g = 255; - b = 255; - } + r = 240; + g = 240; + b = 240; + } else { // Case marron @@ -101,21 +84,33 @@ void main() { r = 0; g = 0; b = 0; + + if( ((dist<(dimension/2)) && ( (y / dimension) < 3 )) && mouse_button == 1){ + r=255; + g=0; + b=0; + } } //définition des pions blanc else if( (dist<(dimension/2)) && ( (y / dimension) >= 7 ) ){ - r = 128; - g = 128; - b = 128; + r = 255; + g = 255; + b = 255; + if(((dist<(dimension/2)) && ( (y / dimension) >= 7 )) && mouse_button == 1){ + r=255; + g=0; + b=0; + } } else{ - r = 92; - g = 64; - b = 51; + r = 210; + g = 180; + b = 140; } + } - if(mouse_button == 1){} + // La scène prend les valeurs orgb définies From 297d4ac26059ddf39ff0358266c7c3e5667c0de7 Mon Sep 17 00:00:00 2001 From: GeraldCalvarin Date: Mon, 17 Mar 2025 19:25:30 +0100 Subject: [PATCH 13/13] Update GgProject.c --- GgProject.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/GgProject.c b/GgProject.c index 3806cd2..fc2efad 100644 --- a/GgProject.c +++ b/GgProject.c @@ -29,10 +29,9 @@ */ - struct couleur { - int r; - int g; - int b; + struct position { + float x; + float y; }; @@ -45,9 +44,6 @@ void main() { // définition de 4 variables o,r,g,b pour faciliter la gestion des couleurs // + définition du fond marron int opacite =255; - // int r = 92; - // int g = 64; - // int b = 51; int r = 0; int g = 0; @@ -81,25 +77,33 @@ void main() { //définition des pions noirs if( (dist<(dimension/2)) && ( (y / dimension) < 3 )){ + r = 0; g = 0; b = 0; - - if( ((dist<(dimension/2)) && ( (y / dimension) < 3 )) && mouse_button == 1){ + + if( int(mousex / dimension) == int(x / dimension) && int(mousey / dimension) == int(y / dimension) && mouse_button == 1){ r=255; g=0; b=0; + //bouge(); + } + } //définition des pions blanc else if( (dist<(dimension/2)) && ( (y / dimension) >= 7 ) ){ + r = 255; g = 255; b = 255; - if(((dist<(dimension/2)) && ( (y / dimension) >= 7 )) && mouse_button == 1){ + + if( int(mousex / dimension) == int(x / dimension) && int(mousey / dimension) == int(y / dimension) && mouse_button == 1){ r=255; g=0; b=0; + //bouge(); + } } else{ @@ -111,7 +115,6 @@ void main() { } - // La scène prend les valeurs orgb définies data_0[p] = (opacite<<24)+(b<<16)+(g<<8)+r;