Skip to content

Commit dfaad4a

Browse files
Color test passed (#1)
* egui color test setup * color test passed
1 parent 4d338c4 commit dfaad4a

File tree

20 files changed

+649
-346
lines changed

20 files changed

+649
-346
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
target
1+
target/
22
Cargo.lock
3-
assets/**/compiled
3+
assets/**/compiled/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
## [0.1.1] Egui example patch
2+
- Example egui renderer now features the color test window from https://www.egui.rs/#colors and passes.
3+
14
## [0.1.0] Initial release

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ log = { version = "0.4.17"}
2222
thiserror = "1.0.40"
2323

2424
[dev-dependencies]
25-
winit = "0.27.5"
26-
egui = "0.20.1"
27-
egui-winit = "0.20.1"
25+
winit = "0.28.3"
26+
egui = "0.21.0"
27+
egui-winit = "0.21.1"
2828
anyhow = "1.0.70"
2929
nalgebra-glm = "0.18.0"
30-
image = "0.24.5"
30+
image = "0.24.5"
31+
32+
[build-dependencies]
33+
copy_to_output = "2.1.0"
-180 Bytes
Binary file not shown.

assets/egui/shaders/compiled/egui.frag.txt

Lines changed: 0 additions & 74 deletions
This file was deleted.
-2.68 KB
Binary file not shown.

assets/egui/shaders/compiled/egui.vert.txt

Lines changed: 0 additions & 214 deletions
This file was deleted.
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
#version 450
22

3-
layout(location = 0) in vec4 o_color;
3+
layout(location = 0) in vec4 i_rgba_in_gamma;
44
layout(location = 1) in vec2 i_uv;
5+
layout(location = 0) out vec4 o_color;
56

67
layout(binding = 0, set = 0) uniform sampler2D fonts_sampler;
78

8-
layout(location = 0) out vec4 final_color;
9+
// 0-1 sRGB gamma from 0-1 linear
10+
vec3 srgb_gamma_from_linear(vec3 rgb) {
11+
bvec3 cutoff = lessThan(rgb, vec3(0.0031308));
12+
vec3 lower = rgb * vec3(12.92);
13+
vec3 higher = vec3(1.055) * pow(rgb, vec3(1.0 / 2.4)) - vec3(0.055);
14+
return mix(higher, lower, vec3(cutoff));
15+
}
16+
17+
// 0-1 sRGBA gamma from 0-1 linear
18+
vec4 srgba_gamma_from_linear(vec4 rgba) {
19+
return vec4(srgb_gamma_from_linear(rgba.rgb), rgba.a);
20+
}
921

1022
void main() {
11-
vec4 texture_in_gamma = texture(fonts_sampler, i_uv);
12-
final_color = o_color * texture_in_gamma;
23+
vec4 texture_in_gamma = srgba_gamma_from_linear(texture(fonts_sampler, i_uv));
24+
o_color = i_rgba_in_gamma * texture_in_gamma;
1325
}

assets/egui/shaders/original/egui.vert

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,13 @@ layout(push_constant) uniform Push {
99

1010
layout(location = 0) in vec2 i_pos;
1111
layout(location = 1) in vec2 i_uv;
12-
layout(location = 2) in vec4 i_col;
12+
layout(location = 2) in vec4 i_col_srgba;
1313

14-
layout(location = 0) out vec4 o_col;
14+
layout(location = 0) out vec4 o_col_rgba_in_gamma;
1515
layout(location = 1) out vec2 o_uv;
1616

17-
vec3 linear_from_srgb(vec3 srgb) {
18-
bvec3 cutoff = lessThan(srgb, vec3(10.31475));
19-
vec3 lower = srgb / vec3(3294.6);
20-
vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4));
21-
return mix(higher, lower, cutoff);
22-
}
23-
24-
vec4 linear_from_srgba(vec4 srgba) {
25-
return vec4(linear_from_srgb(srgba.rgb * 255.0), srgba.a);
26-
}
27-
2817
void main() {
2918
o_uv = i_uv;
30-
o_col = linear_from_srgba(i_col);
19+
o_col_rgba_in_gamma = i_col_srgba / 255.0;
3120
gl_Position = push.matrix * vec4(i_pos.xy, 0.0, 1.0);
3221
}

assets/shader_compilation/original/example.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#version 450
2-
#include "../../../assets/shader_compilation/original/example.glsl" // relative path from calling exe inside /target to assets folder
2+
#include "./assets/shader_compilation/original/example.glsl"
33

44
layout(location = 0) in vec4 i_pos_size;
55
layout(location = 1) in vec4 i_col;

0 commit comments

Comments
 (0)