Skip to content
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

refactor: removed egui-wgpu and egui-winit dependencies. #315

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
961 changes: 526 additions & 435 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ clap = { version = "4.5", default-features = false, features = [
"derive",
] }
dirs = "5.0"
image = { version = "0.24", default-features = false, features = ["png"] }
image = { version = "0.25", default-features = false, features = ["png"] }
puffin = "0.19"
serde = { version = "1.0", features = ["derive"] }
tetanes-core = { version = "0.11", path = "tetanes-core" }
Expand All @@ -52,7 +52,7 @@ tracing = { version = "0.1", default-features = false, features = [
] }
tracing-subscriber = "0.3"
serde_json = "1.0"
web-time = "0.2" # FIXME: winit is using an old version
web-time = "1.0"
web-sys = "0.3"

# Playable framerates in development
Expand All @@ -76,7 +76,7 @@ inherits = "release"
strip = true

[profile.dev.package."*"]
opt-level = 3
opt-level = 2

[workspace.metadata.cross.target.x86_64-unknown-linux-gnu]
pre-build = [
Expand Down
68 changes: 32 additions & 36 deletions tetanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,41 @@ workspace = true

[features]
default = ["tetanes-core/cycle-accurate"]
profiling = ["tetanes-core/profiling", "dep:puffin", "dep:puffin_egui"]
profiling = [
"tetanes-core/profiling",
"dep:puffin",
"dep:puffin_egui",
"egui/puffin",
]
cycle-accurate = []

[dependencies]
anyhow.workspace = true
bincode.workspace = true
bytemuck = "1.15"
cfg-if.workspace = true
chrono = { version = "0.4", default-features = false, features = ["clock"] }
cpal = { version = "0.15", features = ["wasm-bindgen"] }
crossbeam = "0.8"
# TODO: Remove once https://github.com/emilk/egui/pull/4372 is released
color-hex = "0.2"
dirs.workspace = true
egui-wgpu = { version = "0.27", features = ["winit", "wayland", "x11"] }
egui_extras = { version = "0.27", default-features = false, features = [
egui = { version = "0.28", features = [
"bytemuck",
"color-hex",
"default_fonts",
"log",
"persistence",
"serde",
] }
egui_extras = { version = "0.28", default-features = false, features = [
"image",
"serde",
] }
gilrs = { version = "0.10", features = ["serde-serialize"] }
hound = "3.5"
image.workspace = true
nohash-hasher = "0.2"
parking_lot = "0.12"
puffin = { workspace = true, optional = true }
puffin = { workspace = true, optional = true, features = ["web"] }
puffin_egui = { version = "0.27", optional = true }
ringbuf = "0.4"
serde.workspace = true
Expand All @@ -61,49 +75,32 @@ thiserror.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid = { version = "1.8", features = ["v4", "fast-rng", "serde"] }
# Only here to define features for egui-winit "links" feature, hence the "*"
webbrowser = { version = "*", features = ["hardened", "disable-wsl"] }
winit = { version = "0.29", features = ["serde"] }
webbrowser = { version = "1.0", features = ["hardened", "disable-wsl"] }
wgpu = { version = "0.20", features = ["webgl", "webgpu"] }
winit = { version = "0.30", features = ["serde"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap.workspace = true
cpal = "0.15"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
egui = { version = "0.27", features = [
"extra_debug_asserts",
"log",
"persistence",
"accesskit",
accesskit = "0.16"
accesskit_winit = "0.22"
arboard = { version = "3.4", default-features = false, features = [
"wayland-data-control",
] }
egui-winit = { version = "0.27", features = ["accesskit"] }
clap.workspace = true
egui = { version = "0.28", default-features = false, features = ["accesskit"] }
pollster = "0.3"
reqwest = { version = "0.12", features = ["blocking"] }
rfd = "0.14"
semver = "1"
sysinfo = "0.30"
sysinfo = { version = "0.30", default-features = false }
tracing-appender = "0.2"
wgpu = "0.19"

[target.'cfg(target_arch = "wasm32")'.dependencies]
chrono = { version = "0.4", default-features = false, features = [
"clock",
"wasmbind",
] }
base64 = "0.22"
chrono = { version = "0.4", default-features = false, features = ["wasmbind"] }
console_error_panic_hook = "0.1"
cpal = { version = "0.15", features = ["wasm-bindgen"] }
egui = { version = "0.27", features = [
"extra_debug_asserts",
"log",
"persistence",
] }
egui-winit = { version = "0.27", default-features = false, features = [
"links",
] }
# Required because of downstream dependencies: https://docs.rs/getrandom/latest/getrandom/#webassembly-support
getrandom = { version = "0.2", features = ["js"] }
puffin = { workspace = true, features = ["web"], optional = true }
tracing-web = "0.1"
wgpu = { version = "0.19", features = ["webgl", "webgpu"] }
web-sys = { workspace = true, features = [
"Clipboard",
"ClipboardEvent",
Expand All @@ -127,7 +124,6 @@ web-sys = { workspace = true, features = [
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
zip = { version = "2.1", default-features = false, features = ["deflate"] }
base64 = "0.22"

[package.metadata.docs.rs]
rustc-args = ["--cfg=web_sys_unstable_apis"]
Expand Down
56 changes: 29 additions & 27 deletions tetanes/shaders/crt-easymode.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var<private> vertices: array<vec2<f32>, 3> = array<vec2<f32>, 3>(

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) dims: vec2<f32>,
@location(1) inv_dims: vec2<f32>,
@location(0) tex_dims: vec2<f32>,
@location(1) inv_tex_dims: vec2<f32>,
@location(2) v_uv: vec2<f32>,
};

Expand All @@ -50,23 +50,25 @@ fn vs_main(
let vert = vertices[v_idx];

// Convert x from -1.0..1.0 to 0.0..1.0 and y from -1.0..1.0 to 1.0..0.0
out.dims = vec2<f32>(textureDimensions(tex));
out.inv_dims = 1.0 / out.dims;
out.v_uv = fma(vert, vec2(0.5, -0.5), vec2(0.5, 0.5));
out.position = vec4(vert, 0.0, 1.0);
out.tex_dims = vec2<f32>(textureDimensions(tex));
out.inv_tex_dims = 1.0 / out.tex_dims;
out.v_uv = fma(vert, vec2(0.5, -0.5), vec2(0.5, 0.5));
return out;
}

// Fragment shader

struct Output {
size: vec2<f32>,
padding: vec2<f32>,
screen_size: vec2<f32>,
// Uniform buffers need to be at least 16 bytes in WebGL.
// See https://github.com/gfx-rs/wgpu/issues/2072
_padding: vec2<f32>,
}

@group(0) @binding(0) var<uniform> out: Output;
@group(0) @binding(1) var tex: texture_2d<f32>;
@group(0) @binding(2) var tex_sampler: sampler;

@group(1) @binding(0) var tex: texture_2d<f32>;
@group(1) @binding(1) var tex_sampler: sampler;

const PI = 3.141592653589;

Expand All @@ -77,15 +79,15 @@ const MASK_DOT_WIDTH = 1.0;
const MASK_DOT_HEIGHT = 1.0;
const MASK_STAGGER = 0.0;
const MASK_SIZE = 1.0;
const SCANLINE_STRENGTH = 0.95;
const SCANLINE_BEAM_WIDTH_MIN = 2.5;
const SCANLINE_BEAM_WIDTH_MAX = 2.5;
const SCANLINE_BRIGHT_MIN = 0.3;
const SCANLINE_BRIGHT_MAX = 0.6;
const SCANLINE_STRENGTH = 1.0;
const SCANLINE_BEAM_WIDTH_MIN = 1.5;
const SCANLINE_BEAM_WIDTH_MAX = 1.5;
const SCANLINE_BRIGHT_MIN = 0.35;
const SCANLINE_BRIGHT_MAX = 0.65;
const SCANLINE_CUTOFF = 400.0;
const GAMMA_INPUT = 1.0;
const GAMMA_OUTPUT = 2.2;
const BRIGHT_BOOST = 1.1;
const GAMMA_INPUT = 2.0;
const GAMMA_OUTPUT = 1.8;
const BRIGHT_BOOST = 1.2;
const DILATION = 1.0;

// apply half-circle s-curve to distance for sharper (more pixelated) interpolation
Expand Down Expand Up @@ -123,12 +125,12 @@ fn get_color_matrix(co: vec2<f32>, dx: vec2<f32>) -> mat4x4<f32> {

@fragment
fn fs_main(
@location(0) dims: vec2<f32>,
@location(1) inv_dims: vec2<f32>,
@location(0) tex_dims: vec2<f32>,
@location(1) inv_tex_dims: vec2<f32>,
@location(2) v_uv: vec2<f32>
) -> @location(0) vec4<f32> {
let pix_co = v_uv * dims - vec2<f32>(0.5, 0.5);
let tex_co = (floor(pix_co) + vec2<f32>(0.5, 0.5)) * inv_dims;
let pix_co = v_uv * tex_dims - vec2<f32>(0.5, 0.5);
let tex_co = (floor(pix_co) + vec2<f32>(0.5, 0.5)) * inv_tex_dims;
let dist = fract(pix_co);

var curve_x = curve_distance(dist.x, SHARPNESS_H * SHARPNESS_H);
Expand All @@ -138,8 +140,8 @@ fn fs_main(
coeffs = 2.0 * sin(coeffs) * sin(coeffs * 0.5) / (coeffs * coeffs);
coeffs /= dot(coeffs, vec4<f32>(1.0));

let dx = vec2<f32>(inv_dims.x, 0.0);
let dy = vec2<f32>(0.0, inv_dims.y);
let dx = vec2<f32>(inv_tex_dims.x, 0.0);
let dy = vec2<f32>(0.0, inv_tex_dims.y);
var col = filter_lanczos(coeffs, get_color_matrix(tex_co, dx));
var col2 = filter_lanczos(coeffs, get_color_matrix(tex_co + dy, dx));

Expand All @@ -150,11 +152,11 @@ fn fs_main(
let bright = (max(col.r, max(col.g, col.b)) + luma) * 0.5;
let scan_bright = clamp(bright, SCANLINE_BRIGHT_MIN, SCANLINE_BRIGHT_MAX);
let scan_beam = clamp(bright * SCANLINE_BEAM_WIDTH_MAX, SCANLINE_BEAM_WIDTH_MIN, SCANLINE_BEAM_WIDTH_MAX);
var scan_weight = 1.0 - pow(cos(v_uv.y * 2.0 * PI * dims.y) * 0.5 + 0.5, scan_beam) * SCANLINE_STRENGTH;
var scan_weight = 1.0 - pow(cos(v_uv.y * 2.0 * PI * tex_dims.y) * 0.5 + 0.5, scan_beam) * SCANLINE_STRENGTH;

let insize = dims;
let insize = tex_dims;
let mask = 1.0 - MASK_STRENGTH;
let mod_fac = floor(v_uv * out.size * dims / (insize * vec2<f32>(MASK_SIZE, MASK_DOT_HEIGHT * MASK_SIZE)));
let mod_fac = floor(v_uv * out.screen_size * tex_dims / (insize * vec2<f32>(MASK_SIZE, MASK_DOT_HEIGHT * MASK_SIZE)));
let dot_no = i32(((mod_fac.x + (mod_fac.y % 2.0) * MASK_STAGGER) / MASK_DOT_WIDTH % 3.0));

var mask_weight: vec3<f32>;
Expand Down
83 changes: 83 additions & 0 deletions tetanes/shaders/gui.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Vertex shader

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) v_uv: vec2<f32>,
@location(1) v_color: vec4<f32>, // gamma 0-1
};

struct Output {
screen_size: vec2<f32>,
// Uniform buffers need to be at least 16 bytes in WebGL.
// See https://github.com/gfx-rs/wgpu/issues/2072
_padding: vec2<u32>,
};
@group(0) @binding(0) var<uniform> out: Output;

// 0-1 linear from 0-1 sRGB gamma
fn linear_from_gamma_rgb(srgb: vec3<f32>) -> vec3<f32> {
let cutoff = srgb < vec3<f32>(0.04045);
let lower = srgb / vec3<f32>(12.92);
let higher = pow((srgb + vec3<f32>(0.055)) / vec3<f32>(1.055), vec3<f32>(2.4));
return select(higher, lower, cutoff);
}

// 0-1 sRGB gamma from 0-1 linear
fn gamma_from_linear_rgb(rgb: vec3<f32>) -> vec3<f32> {
let cutoff = rgb < vec3<f32>(0.0031308);
let lower = rgb * vec3<f32>(12.92);
let higher = vec3<f32>(1.055) * pow(rgb, vec3<f32>(1.0 / 2.4)) - vec3<f32>(0.055);
return select(higher, lower, cutoff);
}

// 0-1 sRGBA gamma from 0-1 linear
fn gamma_from_linear_rgba(linear_rgba: vec4<f32>) -> vec4<f32> {
return vec4<f32>(gamma_from_linear_rgb(linear_rgba.rgb), linear_rgba.a);
}

// [u8; 4] SRGB as u32 -> [r, g, b, a] in 0.-1
fn unpack_color(color: u32) -> vec4<f32> {
return vec4<f32>(
f32(color & 255u),
f32((color >> 8u) & 255u),
f32((color >> 16u) & 255u),
f32((color >> 24u) & 255u),
) / 255.0;
}

fn position_from_screen(screen_pos: vec2<f32>) -> vec4<f32> {
return vec4<f32>(
2.0 * screen_pos.x / out.screen_size.x - 1.0,
1.0 - 2.0 * screen_pos.y / out.screen_size.y,
0.0,
1.0,
);
}

@vertex
fn vs_main(
@location(0) v_pos: vec2<f32>,
@location(1) v_uv: vec2<f32>,
@location(2) v_color: u32,
) -> VertexOutput {
var out: VertexOutput;
out.v_uv = v_uv;
out.v_color = unpack_color(v_color);
out.position = position_from_screen(v_pos);
return out;
}

// Fragment shader

@group(1) @binding(0) var tex: texture_2d<f32>;
@group(1) @binding(1) var tex_sampler: sampler;

@fragment
fn fs_main(
@location(0) v_uv: vec2<f32>,
@location(1) v_color: vec4<f32>
) -> @location(0) vec4<f32> {
let tex = textureSample(tex, tex_sampler, v_uv);
let tex_gamma = gamma_from_linear_rgba(tex);
return v_color * tex_gamma;
}
Loading