Skip to content

Commit

Permalink
Fix viewport Y orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 20, 2024
1 parent 09ff191 commit 8ceaec9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions blade-render/code/camera.inc.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ struct CameraParams {
target_size: vec2<u32>,
}

const VFLIP: vec2<f32> = vec2<f32>(1.0, -1.0);

fn get_ray_direction(cp: CameraParams, pixel: vec2<i32>) -> vec3<f32> {
let half_size = 0.5 * vec2<f32>(cp.target_size);
let ndc = (vec2<f32>(pixel) + vec2<f32>(0.5) - half_size) / half_size;
// Right-handed coordinate system with X=right, Y=up, and Z=towards the camera
let local_dir = vec3<f32>(ndc * tan(0.5 * cp.fov), -1.0);
let local_dir = vec3<f32>(VFLIP * ndc * tan(0.5 * cp.fov), -1.0);
return normalize(qrot(cp.orientation, local_dir));
}

Expand All @@ -21,7 +23,7 @@ fn get_projected_pixel_float(cp: CameraParams, point: vec3<f32>) -> vec2<f32> {
}
let ndc = local_dir.xy / (-local_dir.z * tan(0.5 * cp.fov));
let half_size = 0.5 * vec2<f32>(cp.target_size);
return (ndc + vec2<f32>(1.0)) * half_size;
return (VFLIP * ndc + vec2<f32>(1.0)) * half_size;
}

fn get_projected_pixel(cp: CameraParams, point: vec3<f32>) -> vec2<i32> {
Expand Down
2 changes: 1 addition & 1 deletion blade-render/code/post-proc.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn postfx_vs(@builtin(vertex_index) vi: u32) -> VertexOutput {

@fragment
fn postfx_fs(vo: VertexOutput) -> @location(0) vec4<f32> {
let tc = vec2<i32>(i32(vo.clip_pos.x), i32(vo.input_size.y) - i32(vo.clip_pos.y) - 1);
let tc = vec2<i32>(i32(vo.clip_pos.x), i32(vo.clip_pos.y));
let illumunation = textureLoad(light_diffuse, tc, 0);
if (debug_params.view_mode == DebugMode_Final) {
let albedo = textureLoad(t_albedo, tc, 0).xyz;
Expand Down

0 comments on commit 8ceaec9

Please sign in to comment.