Skip to content

Commit 2c7a36a

Browse files
committedNov 11, 2023
move to opengl to remove wgpu
1 parent 8022e5a commit 2c7a36a

File tree

11 files changed

+761
-1189
lines changed

11 files changed

+761
-1189
lines changed
 

‎Cargo.lock

+331-607
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"crates/jokoapi",
88
"crates/jokolay",
99
"crates/joko_core",
10+
"crates/joko_ext",
1011
]
1112
resolver = "2"
1213

‎crates/joko_ext/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "joko_ext"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎crates/joko_ext/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

‎crates/joko_render/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
egui_render_wgpu = { version = "0.5" }
9+
egui_render_three_d = { version = "*" }
1010
egui_window_glfw_passthrough = { version = "0.5" }
1111
bytemuck = { version = "1", default-features = false }
1212
jokolink = { path = "../jokolink" }
13-
pollster = { version = "*" }
1413
glam = { workspace = true, features = ["bytemuck"] }
1514
tracing = { workspace = true }
1615
serde = { workspace = true }

‎crates/joko_render/shaders/marker.fs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#version 450
2+
3+
layout(location = 0) in vec2 vtex_coord;
4+
layout(location = 1) in float valpha;
5+
layout(location = 2) in vec4 vcolor;
6+
7+
layout(location = 0) out vec4 ocolor;
8+
9+
layout(location = 1) uniform sampler2D sam;
10+
11+
void main() {
12+
vec4 color = texture(sam, vtex_coord, -2.0);
13+
color.a = color.a * valpha;
14+
if (color.a < 0.01) {
15+
discard;
16+
}
17+
ocolor = color;
18+
}

‎crates/joko_render/shaders/marker.vs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#version 450
2+
3+
layout(location = 0) in vec4 position;
4+
layout(location = 1) in float alpha;
5+
layout(location = 2) in vec2 tex_coord;
6+
layout(location = 3) in vec2 fade_near_far;
7+
layout(location = 4) in vec4 color;
8+
9+
layout(location = 0) out vec2 vtex_coord;
10+
layout(location = 1) out float valpha;
11+
layout(location = 2) out vec4 vcolor;
12+
13+
14+
layout(location = 0) uniform vec3 camera_pos;
15+
// location 1 is for sampler in frag shader
16+
layout(location = 2) uniform mat4 transform;
17+
18+
19+
void main(
20+
) {
21+
valpha = alpha;
22+
vtex_coord = tex_coord;
23+
gl_Position = transform * position;
24+
vcolor = color;
25+
26+
float dist = distance(camera_pos, position.xyz);
27+
if (fade_near_far.x > 0.0 && dist >= fade_near_far.x) {
28+
// if distance is exactly fade_near, we will multiply with 1.0
29+
// if its more, then we will multiply with how far we are in between fade_near and fade_far
30+
float ratio = 1.0 - (abs(dist - fade_near_far.x) / abs(fade_near_far.y - fade_near_far.x));
31+
// The actual alpha
32+
valpha *= ratio;
33+
}
34+
if (fade_near_far.y > 0.0 && dist >= fade_near_far.y) {
35+
valpha = 0.0;
36+
}
37+
}
38+
39+
-60
Original file line numberDiff line numberDiff line change
@@ -1,60 +0,0 @@
1-
struct VertexInput {
2-
@location(0) position: vec4<f32>,
3-
@location(1) tex_coord: vec2<f32>,
4-
@location(2) alpha: f32,
5-
@location(3) color: vec4<f32>,
6-
@location(4) fade_near_far: vec2<f32>,
7-
}
8-
struct VertexOutput {
9-
@location(0) tex_coord: vec2<f32>,
10-
@location(1) alpha: f32,
11-
@location(2) color: vec4<f32>,
12-
@builtin(position) position: vec4<f32>,
13-
};
14-
struct UniformInput {
15-
transform: mat4x4<f32>,
16-
player_pos: vec3<f32>,
17-
}
18-
19-
@group(0)
20-
@binding(0)
21-
var<uniform> uni: UniformInput;
22-
23-
@vertex
24-
fn vs_main(
25-
vin: VertexInput
26-
) -> VertexOutput {
27-
var result: VertexOutput;
28-
result.alpha = vin.alpha;
29-
30-
var dist = distance(uni.player_pos, vin.position.xyz);
31-
if vin.fade_near_far.x > 0.0 && dist >= vin.fade_near_far.x {
32-
// if distance is exactly fade_near, we will multiply with 1.0
33-
// if its more, then we will multiply with how far we are in between fade_near and fade_far
34-
var ratio = 1.0 - (abs(dist - vin.fade_near_far.x) / abs(vin.fade_near_far.y - vin.fade_near_far.x));
35-
// The actual alpha
36-
result.alpha *= ratio;
37-
}
38-
if vin.fade_near_far.y > 0.0 && dist >= vin.fade_near_far.y {
39-
result.alpha = 0.0;
40-
}
41-
result.tex_coord = vin.tex_coord;
42-
result.position = uni.transform * vin.position;
43-
result.color = vin.color;
44-
45-
return result;
46-
}
47-
48-
@group(1) @binding(0) var r_tex_color: texture_2d<f32>;
49-
@group(1) @binding(1) var r_tex_sampler: sampler;
50-
51-
@fragment
52-
fn fs_main(vout: VertexOutput) -> @location(0) vec4<f32> {
53-
var color: vec4<f32> = textureSampleBias(r_tex_color, r_tex_sampler, vout.tex_coord, -2.0);
54-
color.a = color.a * vout.alpha;
55-
if color.a < 0.01 {
56-
discard;
57-
}
58-
return color;
59-
}
60-

0 commit comments

Comments
 (0)
Please sign in to comment.