[oden] Cleanup texture a little
This commit is contained in:
parent
e3f345052c
commit
205ed27b48
2 changed files with 5 additions and 21 deletions
|
|
@ -7,12 +7,13 @@ struct ScreenUniform {
|
||||||
var<uniform> screen : ScreenUniform;
|
var<uniform> screen : ScreenUniform;
|
||||||
|
|
||||||
struct VertexInput {
|
struct VertexInput {
|
||||||
@location(0) position : vec3<f32>, @location(1) tex_coords : vec2<f32>,
|
@location(0) position : vec3<f32>,
|
||||||
|
@location(1) tex_coords : vec2<f32>,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexOutput {
|
struct VertexOutput {
|
||||||
@builtin(position) clip_position : vec4<f32>,
|
@builtin(position) clip_position : vec4<f32>,
|
||||||
@location(0) tex_coords : vec2<f32>,
|
@location(0) tex_coords : vec2<f32>,
|
||||||
};
|
};
|
||||||
|
|
||||||
const RES = vec2f(320.0, 240.0); // The logical resolution of the screen.
|
const RES = vec2f(320.0, 240.0); // The logical resolution of the screen.
|
||||||
|
|
@ -55,24 +56,7 @@ const RES = vec2f(320.0, 240.0); // The logical resolution of the screen.
|
||||||
@group(0) @binding(1) var s_diffuse : sampler;
|
@group(0) @binding(1) var s_diffuse : sampler;
|
||||||
|
|
||||||
@fragment fn fs_main(in : VertexOutput)->@location(0) vec4<f32> {
|
@fragment fn fs_main(in : VertexOutput)->@location(0) vec4<f32> {
|
||||||
// The "screen" is centered in the window, so anything outside of the
|
|
||||||
// screen borders should be black. But *where are they*?
|
|
||||||
let RES_AR = RES.x / RES.y; // The aspect ratio of the logical screen.
|
|
||||||
let screen_ar = screen.resolution.x / screen.resolution.y;
|
|
||||||
var black_mod = 1.0;
|
|
||||||
if (screen_ar > RES_AR) {
|
|
||||||
// Wider than tall, bars are on the left and right.
|
|
||||||
let active_width = screen.resolution.y * RES_AR;
|
|
||||||
let half_delta = (screen.resolution.x - active_width) / 2.0;
|
|
||||||
if (in.clip_position.x < half_delta ||
|
|
||||||
in.clip_position.x > half_delta + active_width) {
|
|
||||||
black_mod = 0.0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Taller than wide, bars are on top and bottom.
|
|
||||||
}
|
|
||||||
|
|
||||||
let dims = vec2f(textureDimensions(t_diffuse));
|
let dims = vec2f(textureDimensions(t_diffuse));
|
||||||
|
|
||||||
return black_mod * textureSample(t_diffuse, s_diffuse, in.tex_coords / dims);
|
return textureSample(t_diffuse, s_diffuse, in.tex_coords / dims);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ impl Texture {
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||||
mag_filter: wgpu::FilterMode::Linear,
|
mag_filter: wgpu::FilterMode::Nearest,
|
||||||
min_filter: wgpu::FilterMode::Nearest,
|
min_filter: wgpu::FilterMode::Nearest,
|
||||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue