Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 701efca

Browse files
authored
Merge pull request #43 from ChaoticByte/release/v7.0
Release/v7.0
2 parents 50ddf6e + 6419ab1 commit 701efca

18 files changed

+337
-135
lines changed

LICENSE

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
MIT License
1+
BSD 3-Clause License
22

3-
Copyright (c) 2024 Julian Müller (ChaoticByte)
3+
Copyright (c) 2025, Julian Müller (ChaoticByte)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
117

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
1410

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,33 @@ void fragment() {
7474
COLOR = hsv_offset(COLOR, 0.32, 0.2, 0.0);
7575
}
7676
```
77+
78+
## Commandline interface
79+
80+
You can run Fragmented from the commandline or scripts.
81+
82+
> Note: Headless mode is not supported. Using the commandline interface still opens a window.
83+
84+
### Usage
85+
86+
```
87+
./Fragmented cmd --shader PATH [--load-image PATH]
88+
89+
--shader PATH The path to the shader
90+
--output PATH Where to write the resulting image to
91+
--load-image PATH The path to the image. This will overwrite the
92+
load directive of the shader file (optional)
93+
94+
```
95+
96+
You can also run `./Fragmented cmd help` to show the help message.
97+
98+
#### Examples
99+
100+
```
101+
./Fragmented cmd --shader ./examples/oklab.gdshader --output ./output.png
102+
```
103+
104+
```
105+
./Fragmented cmd --shader ./examples/oklab.gdshader --load-image ~/Pictures/test.png --output ./output.png
106+
```

examples/blur.gdshader

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
shader_type canvas_item;
2+
3+
//!load ./images/swamp.jpg
4+
#include "res://shaderlib/blur.gdshaderinc"
5+
6+
void fragment() {
7+
COLOR = gaussian_blur(TEXTURE, UV, 48, 24.0);
8+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
shader_type canvas_item;
22

3-
#include "res://shaderlib/hsv.gdshaderinc"
3+
#include "res://shaderlib/colorspaces.gdshaderinc"
44
#include "res://shaderlib/effects.gdshaderinc"
55

66
//!load ./images/swamp.jpg
77

88
void fragment() {
99
COLOR = pixelate(TEXTURE, UV, 200.0);
1010
vec4 hsv = rgb2hsv(COLOR);
11-
COLOR = hsv_offset(COLOR, 0.65, .42-(hsv.y*.3), -.125);
12-
COLOR = hsv_multiply(COLOR, 1.0, 1.0, 1.25);
11+
hsv.xyz += vec3(0.65, .42-(hsv.y*.3), -.125);
12+
hsv.xyz *= vec3(1.0, 1.0, 1.25);
13+
COLOR = hsv2rgb(hsv);
1314
}

examples/oklab.gdshader

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
shader_type canvas_item;
2+
3+
#include "res://shaderlib/colorspaces.gdshaderinc"
4+
5+
//!load ./images/swamp.jpg
6+
7+
void fragment() {
8+
vec4 oklab = rgb2oklab(COLOR);
9+
vec4 oklch = oklab2oklch(oklab);
10+
oklch.z -= 2.0;
11+
COLOR = oklab2rgb(oklch2oklab(oklch));
12+
}

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config_version=5
1111
[application]
1212

1313
config/name="Fragmented"
14-
config/version="v6.2"
14+
config/version="v7.0"
1515
run/main_scene="res://scenes/main.tscn"
1616
config/features=PackedStringArray("4.3", "Mobile")
1717
run/low_processor_mode=true

scenes/main.tscn

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[gd_scene load_steps=10 format=3 uid="uid://bjah7k4bxo044"]
22

33
[ext_resource type="Script" path="res://src/Main.gd" id="1_2625y"]
4-
[ext_resource type="Script" path="res://src/Compositor.gd" id="2_hvo65"]
4+
[ext_resource type="Script" path="res://src/ImageCompositor.gd" id="2_4thch"]
55
[ext_resource type="Shader" path="res://src/shader/ivd_outline.gdshader" id="3_6xihe"]
66
[ext_resource type="Script" path="res://src/ImageViewportDisplay.gd" id="3_n4itb"]
77
[ext_resource type="Script" path="res://src/UIWindow.gd" id="6_8k0ha"]
@@ -20,14 +20,7 @@ script = ExtResource("1_2625y")
2020

2121
[node name="Compositor" type="SubViewport" parent="."]
2222
unique_name_in_owner = true
23-
disable_3d = true
24-
transparent_bg = true
25-
canvas_item_default_texture_filter = 0
26-
render_target_update_mode = 4
27-
script = ExtResource("2_hvo65")
28-
29-
[node name="ImageSprite" type="Sprite2D" parent="Compositor"]
30-
unique_name_in_owner = true
23+
script = ExtResource("2_4thch")
3124

3225
[node name="ImageViewportDisplay" type="Sprite2D" parent="."]
3326
unique_name_in_owner = true
@@ -44,6 +37,7 @@ unique_name_in_owner = true
4437
disable_3d = true
4538
position = Vector2i(48, 36)
4639
size = Vector2i(704, 704)
40+
visible = false
4741
script = ExtResource("6_8k0ha")
4842

4943
[node name="UserInterfaceContainer" parent="EditorWindow" instance=ExtResource("7_5ci0e")]

screenshot.png

-5.61 KB
Loading

shaderlib/blur.gdshaderinc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
/*
3+
gaussian_blur adapted from https://godotshaders.com/shader/customizable-gausian-blur/
4+
original code by https://godotshaders.com/author/djbob-gaming-yt/
5+
maximum radius is 64
6+
*/
7+
vec4 gaussian_blur(sampler2D texture, vec2 uv, int radius, float sigma) {
8+
vec2 resolution = 1.0 / vec2(textureSize(texture, 0));
9+
// calculate kernel
10+
float kernel[64];
11+
float sum = 0.0;
12+
for (int i = 0; i <= radius; i++) {
13+
kernel[i] = exp(-0.5 * float(i * i) / (sigma * sigma));
14+
sum += i == 0 ? kernel[i] : 2.0 * kernel[i];
15+
}
16+
for (int i = 0; i <= radius; i++) {
17+
kernel[i] /= sum;
18+
}
19+
//
20+
vec4 final_color = vec4(0.0);
21+
float total_weight = 0.0;
22+
for (int x = -radius; x <= radius; x++) {
23+
for (int y = -radius; y <= radius; y++) {
24+
float weight = kernel[abs(x)] * kernel[abs(y)];
25+
vec2 offset = vec2(float(x), float(y)) * resolution;
26+
final_color += texture(texture, uv + offset) * weight;
27+
total_weight += weight;
28+
}
29+
}
30+
final_color /= total_weight;
31+
return final_color;
32+
}

shaderlib/colorspaces.gdshaderinc

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
/*
3+
Color space conversion functions always work with vec4.
4+
The fourth value is always alpha.
5+
*/
6+
7+
#include "res://shaderlib/common.gdshaderinc"
8+
9+
/*
10+
rgb2hsv and hsv2rgb functions adapted
11+
from https://godotshaders.com/shader/hsv-adjustment/
12+
original code by https://godotshaders.com/author/al1-ce/
13+
*/
14+
15+
// Convert RGB to HSV (hue, saturation, brightness)
16+
vec4 rgb2hsv(vec4 c) {
17+
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
18+
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
19+
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
20+
float d = q.x - min(q.w, q.y);
21+
float e = 1.0e-10;
22+
return vec4(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x, c.a);
23+
}
24+
25+
// Convert HSV back to RGB (red, green, blue)
26+
vec4 hsv2rgb(vec4 c) {
27+
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
28+
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
29+
vec3 rgb = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
30+
return vec4(rgb.r, rgb.g, rgb.b, c.a);
31+
}
32+
33+
/*
34+
OkLab and OkLCh
35+
For more details on oklab, see
36+
- https://bottosson.github.io/posts/oklab/
37+
- https://en.wikipedia.org/wiki/Oklab_color_space
38+
*/
39+
40+
vec4 rgb2oklab(vec4 c) {
41+
float l = 0.4122214708f * c.r + 0.5363325363f * c.g + 0.0514459929f * c.b;
42+
float m = 0.2119034982f * c.r + 0.6806995451f * c.g + 0.1073969566f * c.b;
43+
float s = 0.0883024619f * c.r + 0.2817188376f * c.g + 0.6299787005f * c.b;
44+
45+
float l_ = cbrt(l);
46+
float m_ = cbrt(m);
47+
float s_ = cbrt(s);
48+
49+
return vec4(
50+
0.2104542553f*l_ + 0.7936177850f*m_ - 0.0040720468f*s_,
51+
1.9779984951f*l_ - 2.4285922050f*m_ + 0.4505937099f*s_,
52+
0.0259040371f*l_ + 0.7827717662f*m_ - 0.8086757660f*s_,
53+
c.a
54+
);
55+
}
56+
57+
vec4 oklab2rgb(vec4 c) {
58+
float l_ = c.x + 0.3963377774f * c.y + 0.2158037573f * c.z;
59+
float m_ = c.x - 0.1055613458f * c.y - 0.0638541728f * c.z;
60+
float s_ = c.x - 0.0894841775f * c.y - 1.2914855480f * c.z;
61+
62+
float l = l_*l_*l_;
63+
float m = m_*m_*m_;
64+
float s = s_*s_*s_;
65+
66+
return vec4(
67+
+4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s,
68+
-1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s,
69+
-0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s,
70+
c.a
71+
);
72+
}
73+
74+
vec4 oklab2oklch(vec4 c) {
75+
return vec4(
76+
c.x,
77+
sqrt((c.y * c.y) + (c.z * c.z)),
78+
atan(c.z, c.y),
79+
c.a
80+
);
81+
}
82+
83+
vec4 oklch2oklab(vec4 c) {
84+
return vec4(
85+
c.x,
86+
c.y * cos(c.z),
87+
c.y * sin(c.z),
88+
c.a
89+
);
90+
}

0 commit comments

Comments
 (0)