[oden] Re-work the way that scaling works

This is part of making the text scale properly, you'll see.
This commit is contained in:
John Doty 2023-09-02 08:33:45 -07:00
parent 21cd767140
commit 994be3e493
5 changed files with 100 additions and 137 deletions

View file

@ -1,3 +1,4 @@
// @include 'util.wgsl'
// ----------------------------------------------------------------------------
// Vertex shader
// ----------------------------------------------------------------------------
@ -59,44 +60,3 @@ struct VertexOutput {
);
//return vec4<f32>(1.0,1.0,1.0,1.0);
}
// ----------------------------------------------------------------------------
// Resolution Handling
// ----------------------------------------------------------------------------
struct ScreenUniform {
resolution : vec2f,
};
@group(0) @binding(0) // 1.
var<uniform> screen : ScreenUniform;
const RES = vec2f(320.0, 240.0); // The logical resolution of the screen.
fn adjust_for_resolution(in_pos: vec2<f32>) -> vec2<f32> {
// Adjust in_pos for the "resolution" of the screen.
let RES_AR = RES.x / RES.y; // The aspect ratio of the logical screen.
// the actual resolution of the screen.
let screen_ar = screen.resolution.x / screen.resolution.y;
// Compute the difference in resolution ... correctly?
//
// nudge is the amount to add to the logical resolution so that the pixels
// stay the same size but we respect the aspect ratio of the screen. (So
// there's more of them in either the x or y direction.)
var nudge = vec2f(0.0);
if (screen_ar > RES_AR) {
nudge.x = (RES.y * screen_ar) - RES.x;
} else {
nudge.y = (RES.x / screen_ar) - RES.y;
}
var new_logical_resolution = RES + nudge;
// Now we can convert the incoming position to clip space, in the new screen.
let centered = in_pos + (nudge / 2.0);
var position = (2.0 * centered / new_logical_resolution) - 1.0;
position.y = -position.y;
return position;
}