Skip to content

Fractal Boxes #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions addons/compute_shader_studio/compute_shader_studio_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,11 @@ func screen_to_data0(pos : Vector2):
return pos;
else:
return Vector2(0,0)


func _on_button_pressed() -> void:
$ComputeShaderStudio2D2.pause = !$ComputeShaderStudio2D2.pause
if $ComputeShaderStudio2D2.pause:
$Button.text = "Play"
else:
$Button.text = "Pause" # Replace with function body.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://ymdghjh2i2lw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bnu0bag13mvgw
1 change: 1 addition & 0 deletions examples/LabelStepPass.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dxa1wiefqey1t
103 changes: 103 additions & 0 deletions examples/boxes/fichier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Adapte de https://www.shadertoy.com/view/wc2XRh
// Version optimisee pour la bibliotheque Compute Shader Studio dans Godot.
#define POINTCOUNT 8
#define PI 3.14159
#define iResolution vec2(float(WSX), float(WSY))
#define inBox(low, high, point) (low.x <= point.x && low.y <= point.y && high.x > point.x && high.y > point.y)
#define toUv(point) (2.0 * (point - 0.5 * iResolution) / iResolution.y)

void main()
{
// Recuperer les coordonnees du pixel
uint x = gl_GlobalInvocationID.x;
uint y = gl_GlobalInvocationID.y;
// Calculer l'indice lineaire dans data_0
uint p = x + y * WSX;

// Convertir les coordonnees du pixel en coordonnees uv
vec2 fragCoord = vec2(x, y);
vec2 uv = toUv(fragCoord);
// Determiner les bornes inferieure et superieure de la cellule
vec2 low = floor(uv);
vec2 high = ceil(uv);
// Restriction de uv dans la cellule
uv = mod(uv, vec2(1.0));

// Calculer le temps a partir de la variable step
float t = float(step) * 0.005;

// Creer un tableau de POINTCOUNT points
vec2 points[POINTCOUNT];
for (int i = 0; i < POINTCOUNT; i++)
{
float fi = float(i);
points[i] = vec2(
(1.75 - 0.125 * fi) * cos(1.333 * t - (1.0 - 0.2 * t) * fi / PI),
(1.0 - 0.1 * fi) * sin((fi + 1.0) * t + PI * 0.5)
);
}

// Boucle de subdivision pour determiner le niveau de subdivision
int iters = 0;
while (iters < 8)
{
iters++;
bool sub = false;
// Verifier si un point se trouve dans la cellule
for (int i = 0; i < POINTCOUNT; i++)
{
if (inBox(low, high, points[i]))
{
sub = true;
break;
}
}
if (sub)
{
// Calculer le centre de la cellule
vec2 center = (high + low) * 0.5;
// Subdivision horizontale
if (uv.x > 0.5)
{
low.x = center.x;
uv.x = uv.x * 2.0 - 1.0;
}
else
{
high.x = center.x;
uv.x *= 2.0;
}
// Subdivision verticale
if (uv.y > 0.5)
{
low.y = center.y;
uv.y = uv.y * 2.0 - 1.0;
}
else
{
high.y = center.y;
uv.y *= 2.0;
}
}
else
{
break;
}
}

// Calculer une mesure "m" de la distance par rapport au centre de la cellule
float m = max(abs(uv.x - 0.5), abs(uv.y - 0.5)) * 2.0;
// "s" est une valeur lisse en fonction du nombre d'iterations
float s = smoothstep(1.0 - 0.01 * pow(2.0, float(iters)), 1.0, m);
// Creer une couleur en niveaux de gris
vec3 col = vec3(s);

// Conversion de la couleur en valeurs entieres (0 a 255)
int a = 255;
int r = int(clamp(col.r, 0.0, 1.0) * 255.0);
int g = int(clamp(col.g, 0.0, 1.0) * 255.0);
int b = int(clamp(col.b, 0.0, 1.0) * 255.0);

// Stocker la couleur dans data_0 en format ARGB
data_0[p] = (a << 24) | (r << 16) | (g << 8) | b;
}
19 changes: 19 additions & 0 deletions examples/boxes/fichier.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends Node2D


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass


func _on_button_pressed() -> void:
$ComputeShaderStudio2D2.pause = !$ComputeShaderStudio2D2.pause
if $ComputeShaderStudio2D2.pause:
$Button.text = "Play"
else:
$Button.text = "Pause" # Replace with function body.
1 change: 1 addition & 0 deletions examples/boxes/fichier.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://2wy07yux7xmu
43 changes: 43 additions & 0 deletions examples/boxes/fichier.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[gd_scene load_steps=6 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" path="res://examples/boxes/fichier.gd" id="1_y3tek"]

[sub_resource type="FastNoiseLite" id="FastNoiseLite_pm7bb"]

[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_nxi5j"]
width = 256
height = 128
noise = SubResource("FastNoiseLite_pm7bb")

[sub_resource type="Theme" id="Theme_xvegm"]

[node name="CompShadStudioEx5" type="Node2D"]
script = ExtResource("1_y3tek")

[node name="ComputeShaderStudio2D2" type="Node" parent="." node_paths=PackedStringArray("data")]
script = ExtResource("1_cogap")
pause = true
WSX = 1152
WSY = 648
glsl_file = "res://examples/boxes/fichier.cpp"
data = [NodePath("../TextureRect")]

[node name="TextureRect" type="TextureRect" parent="."]
offset_left = -5.0
offset_top = -2.0
offset_right = 573.0
offset_bottom = 369.0
size_flags_horizontal = 3
size_flags_vertical = 3
texture = SubResource("NoiseTexture2D_nxi5j")

[node name="Button" type="Button" parent="."]
offset_left = 2.0
offset_top = 8.0
offset_right = 76.0
offset_bottom = 41.0
theme = SubResource("Theme_xvegm")
text = "Jouer"

[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
1 change: 1 addition & 0 deletions examples/cells/cells.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dxrckgtq1eqrv
1 change: 1 addition & 0 deletions examples/example_mandelbrot.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://jvjmvstxk5po
37 changes: 37 additions & 0 deletions icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://773pfp1ieglx"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
Binary file added screenshots/initial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.