Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
604c1b9
Update dependencies to latest versions
hovinen Jan 6, 2024
36088c0
Add WGSL shaders
hovinen Jan 24, 2024
459e11b
Add WGPU and related crate dependencies
hovinen Jan 24, 2024
49f1771
Construct WGPU objects in Window system
hovinen Jan 24, 2024
a5cc642
Add rendering boilerplate
hovinen Jan 24, 2024
e4bcbd7
Add render pass and render attachments
hovinen Jan 24, 2024
159c850
Implement MeshRef for WGPU
hovinen Jan 24, 2024
9e6002b
Remove unused dependency
hovinen Jan 24, 2024
7125534
Add vertex descriptors
hovinen Jan 25, 2024
44f169b
Add bind group layouts
hovinen Jan 25, 2024
87229aa
Set up global bind group
hovinen Jan 26, 2024
ca1df42
Move palette to global bind group
hovinen Jan 26, 2024
abd6cd8
Implement material bind group
hovinen Jan 26, 2024
91d12df
Remove sampler from material texture
hovinen Jan 26, 2024
8373e43
Set up global bind group in Uniforms
hovinen Jan 26, 2024
a4f437e
Set up bindings for viewproj matrix
hovinen Jan 26, 2024
35c7b2b
Add bind group to mesh
hovinen Jan 26, 2024
d83fe85
Set up model bind group
hovinen Jan 26, 2024
313efd1
Use WGPU textures in texture object
hovinen Jan 26, 2024
9247631
Eliminate Glium-based rendering
hovinen Jan 26, 2024
f81ef91
Fixes to bind group layout
hovinen Jan 27, 2024
5b7a769
Port text rendering to WGPU
hovinen Jan 27, 2024
0477165
Remove implement_vertex calls
hovinen Jan 27, 2024
0d7db17
Fixes to text pipeline
hovinen Jan 27, 2024
c2e4018
Fixes to WGSL
hovinen Jan 27, 2024
a042baa
More fixes
hovinen Jan 27, 2024
e348565
More fixes
hovinen Jan 27, 2024
6b9254b
Switch type of lights buffer to u32
hovinen Jan 27, 2024
bad177a
Shader fixes
hovinen Jan 27, 2024
997e3aa
Shader and WGPU fixes
hovinen Jan 27, 2024
c05f84a
More WGPU fixes
hovinen Jan 27, 2024
2c48a65
Remove references to glium
hovinen Jan 28, 2024
418fa12
Remove glium dependency
hovinen Jan 28, 2024
66d1c4a
Remove unused trait
hovinen Jan 28, 2024
916cc73
Add label
hovinen Jan 28, 2024
5f3c2d7
Remove GLSL shaders
hovinen Jan 28, 2024
0e45638
Extract constant for MSAA sample count
hovinen Jan 28, 2024
b944ae0
Enable MSAA
hovinen Jan 28, 2024
88f3127
Remove depth stencil from text pipeline
hovinen Jan 28, 2024
c25da2f
Align MSAA for text pipeline
hovinen Jan 28, 2024
b930ced
Fix palette mapping
hovinen Jan 28, 2024
f906cd1
Implement second sampler for palette
hovinen Jan 28, 2024
2379962
Use nearest sampling rather than linear sampling
hovinen Jan 28, 2024
38e59d6
Remove padding from vertex structs
hovinen Jan 28, 2024
5fcaed6
Make model and right buffers available in mesh
hovinen Jan 28, 2024
4b87286
Update model and right in renderer
hovinen Jan 28, 2024
0520028
Update model and right in renderer
hovinen Jan 28, 2024
2f46b40
Fix sprite rendering
hovinen Jan 28, 2024
52c9ee5
Simplify logic
hovinen Jan 28, 2024
ebab1e1
Eliminate extra matrix inversion
hovinen Jan 29, 2024
b854329
Remove unneeded calls
hovinen Jan 29, 2024
f319e06
Enforce positive remainder in shader
hovinen Jan 29, 2024
c008fbf
Update time uniform
hovinen Jan 29, 2024
5fdfd47
Fix lighting and use correct time when updating lights
hovinen Jan 29, 2024
6c20524
Fix text rendering
hovinen Jan 29, 2024
67723db
Use Srgb colorspace
hovinen Jan 29, 2024
a80a8f6
Fix palette creation
hovinen Jan 29, 2024
676e89e
Actually copy text texture to GPU
hovinen Jan 29, 2024
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
2,445 changes: 1,958 additions & 487 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ engine = { path = "engine" }
game = { path = "game" }
math = { path = "math" }

env_logger = "0.8.3"
env_logger = "0.10.1"
structopt = "0.3.21"
failure = "0.1.8"

Expand All @@ -23,5 +23,3 @@ features = ["release_max_level_info"]
version = "0.4.8"

[workspace]


26 changes: 0 additions & 26 deletions assets/shaders/sky.frag

This file was deleted.

16 changes: 0 additions & 16 deletions assets/shaders/sky.vert

This file was deleted.

42 changes: 42 additions & 0 deletions assets/shaders/sky.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@group(0) @binding(0) var<uniform> u_viewproj: mat4x4<f32>;
@group(0) @binding(1) var u_atlas_sampler: sampler;
@group(0) @binding(4) var u_palette: texture_2d<f32>;
@group(0) @binding(5) var u_palette_sampler: sampler;

@group(1) @binding(0) var u_texture: texture_2d<f32>;
@group(1) @binding(2) var<uniform> u_tiled_band_size: f32;

@group(2) @binding(0) var<uniform> u_model: mat4x4<f32>;

struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@location(0) v_r: vec2<f32>,
@location(1) v_p: vec4<f32>,
}

@vertex
fn main_vs(@location(0) a_pos: vec3<f32>) -> VertexOutput {
var out: VertexOutput;
let transform = u_viewproj * u_model;
let forward = transform[2];
out.v_r = vec2(atan(forward.x / forward.z), forward.y / forward.w);
let projected_pos = transform * vec4(a_pos, 1);
out.v_p = projected_pos;
out.clip_position = projected_pos;
return out;
}

@fragment
fn main_fs(in: VertexOutput) -> @location(0) vec4<f32> {
var uv = vec2(in.v_p.x, in.v_p.y) / in.v_p.w * vec2(1, -1);
uv = vec2(uv.x - 4.0 * in.v_r.x / 3.14159265358, uv.y + 1.0 + in.v_r.y);
if uv.y < 0.0 {
uv.y = abs((-uv.y + u_tiled_band_size) % (u_tiled_band_size * 2.0) - u_tiled_band_size);
} else if uv.y >= 2.0 {
uv.y = abs((uv.y - 2.0 + u_tiled_band_size) % (u_tiled_band_size * 2.0) - u_tiled_band_size);
} else if uv.y >= 1.0 {
uv.y = 1.0 - uv.y;
}
let palette_index = textureSample(u_texture, u_atlas_sampler, uv).r;
return vec4(textureSample(u_palette, u_palette_sampler, vec2(palette_index, 0.0)).rgb, 1.0);
}
28 changes: 0 additions & 28 deletions assets/shaders/sprite.frag

This file was deleted.

47 changes: 0 additions & 47 deletions assets/shaders/sprite.vert

This file was deleted.

75 changes: 75 additions & 0 deletions assets/shaders/sprite.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@group(0) @binding(0) var<uniform> u_viewproj: mat4x4<f32>;
@group(0) @binding(1) var u_atlas_sampler: sampler;
@group(0) @binding(2) var<storage, read> u_lights: array<f32>;
@group(0) @binding(3) var<uniform> u_time: f32;
@group(0) @binding(4) var u_palette: texture_2d<f32>;
@group(0) @binding(5) var u_palette_sampler: sampler;

@group(1) @binding(0) var u_atlas: texture_2d<f32>;
@group(1) @binding(1) var<uniform> u_atlas_size: vec2<f32>;

@group(2) @binding(0) var<uniform> u_model: mat4x4<f32>;
@group(2) @binding(1) var<uniform> u_right: vec3<f32>;

struct VertexInput {
@location(0) a_pos: vec3<f32>,
@location(1) a_atlas_uv: vec2<f32>,
@location(2) a_tile_uv: vec2<f32>,
@location(3) a_tile_size: vec2<f32>,
@location(4) a_local_x: f32,
@location(5) a_num_frames: i32,
@location(6) a_light: i32,
}

struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@location(0) v_dist: f32,
@location(1) v_tile_uv: vec2<f32>,
@location(2) v_atlas_uv: vec2<f32>,
@location(3) v_tile_size: vec2<f32>,
@location(4) v_light: f32,
}

const ANIM_FPS: f32 = 8.0 / 35.0;

@vertex
fn main_vs(in: VertexInput) -> VertexOutput {
var out: VertexOutput;
out.v_tile_uv = in.a_tile_uv;
if in.a_num_frames == 1 {
out.v_atlas_uv = in.a_atlas_uv;
} else {
let frame_index = floor((u_time / ANIM_FPS) % f32(in.a_num_frames));

var atlas_u = in.a_atlas_uv.x + frame_index * in.a_tile_size.x;
let n_rows_down = ceil((atlas_u + in.a_tile_size.x) / u_atlas_size.x) - 1.0;
atlas_u += (u_atlas_size.x - in.a_atlas_uv.x) % in.a_tile_size.x * n_rows_down;

let atlas_v = in.a_atlas_uv.y + n_rows_down * in.a_tile_size.y;
out.v_atlas_uv = vec2(atlas_u, atlas_v);
}
out.v_tile_size = in.a_tile_size;

let pos = in.a_pos + u_right * in.a_local_x;
let projected_pos = u_viewproj * (u_model * vec4(pos, 1.0));
out.v_light = u_lights[in.a_light];
out.v_dist = projected_pos.w;
out.clip_position = projected_pos;
return out;
}

const DIST_SCALE: f32 = 0.9;
const LIGHT_SCALE: f32 = 2.0;

@fragment
fn main_fs(in: VertexOutput) -> @location(0) vec4<f32> {
let uv = in.v_tile_uv % in.v_tile_size + in.v_atlas_uv;
let palette_index = textureSample(u_atlas, u_atlas_sampler, uv / u_atlas_size).rg;
if palette_index.g > .5 { // Transparent pixel.
discard;
} else {
let dist_term = min(1.0, 1.0 - DIST_SCALE / (in.v_dist + DIST_SCALE));
let light = min(in.v_light, in.v_light * LIGHT_SCALE - dist_term);
return vec4(textureSample(u_palette, u_palette_sampler, vec2(palette_index.r, 0.0)).rgb * light, 1.0);
}
}
28 changes: 0 additions & 28 deletions assets/shaders/static.frag

This file was deleted.

45 changes: 0 additions & 45 deletions assets/shaders/static.vert

This file was deleted.

Loading