diff --git a/blade-render/code/camera.inc.wgsl b/blade-render/code/camera.inc.wgsl index bffbbbd9..c7132373 100644 --- a/blade-render/code/camera.inc.wgsl +++ b/blade-render/code/camera.inc.wgsl @@ -6,11 +6,13 @@ struct CameraParams { target_size: vec2, } +const VFLIP: vec2 = vec2(1.0, -1.0); + fn get_ray_direction(cp: CameraParams, pixel: vec2) -> vec3 { let half_size = 0.5 * vec2(cp.target_size); let ndc = (vec2(pixel) + vec2(0.5) - half_size) / half_size; // Right-handed coordinate system with X=right, Y=up, and Z=towards the camera - let local_dir = vec3(ndc * tan(0.5 * cp.fov), -1.0); + let local_dir = vec3(VFLIP * ndc * tan(0.5 * cp.fov), -1.0); return normalize(qrot(cp.orientation, local_dir)); } @@ -21,7 +23,7 @@ fn get_projected_pixel_float(cp: CameraParams, point: vec3) -> vec2 { } let ndc = local_dir.xy / (-local_dir.z * tan(0.5 * cp.fov)); let half_size = 0.5 * vec2(cp.target_size); - return (ndc + vec2(1.0)) * half_size; + return (VFLIP * ndc + vec2(1.0)) * half_size; } fn get_projected_pixel(cp: CameraParams, point: vec3) -> vec2 { diff --git a/blade-render/code/post-proc.wgsl b/blade-render/code/post-proc.wgsl index c0681446..dc708bb3 100644 --- a/blade-render/code/post-proc.wgsl +++ b/blade-render/code/post-proc.wgsl @@ -30,7 +30,7 @@ fn postfx_vs(@builtin(vertex_index) vi: u32) -> VertexOutput { @fragment fn postfx_fs(vo: VertexOutput) -> @location(0) vec4 { - let tc = vec2(i32(vo.clip_pos.x), i32(vo.input_size.y) - i32(vo.clip_pos.y) - 1); + let tc = vec2(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;