Use reversed infinite projection for camera
This commit is contained in:
@@ -13,6 +13,6 @@ layout(set = 1, binding = 1) uniform Object{
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(inCoord, 1.0) * object.transform * camera.transform;
|
||||
gl_ClipDistance[0] = gl_Position.z;
|
||||
gl_ClipDistance[0] = gl_Position.w - gl_Position.z;
|
||||
outUV = inUV;
|
||||
}
|
||||
|
@@ -142,7 +142,6 @@ pub fn create() void {
|
||||
Graphics.camera = Camera{
|
||||
.transform = .{},
|
||||
.near = 1.0 / 16.0,
|
||||
.far = 128.0,
|
||||
.lens = 1.5,
|
||||
.aspect = 16.0 / 9.0,
|
||||
.matrix = undefined,
|
||||
@@ -193,7 +192,7 @@ pub fn beginDraw() bool {
|
||||
.mip_level = 0,
|
||||
.texture = Graphics.fsaa_target,
|
||||
}, 1, &.{
|
||||
.clear_depth = 1.0,
|
||||
.clear_depth = 0.0,
|
||||
.load_op = sdl.GPU_LOADOP_CLEAR,
|
||||
.store_op = sdl.GPU_STOREOP_DONT_CARE,
|
||||
.stencil_load_op = sdl.GPU_STOREOP_DONT_CARE,
|
||||
@@ -219,7 +218,7 @@ pub fn clearDepth() void {
|
||||
.mip_level = 0,
|
||||
.texture = Graphics.fsaa_target,
|
||||
}, 1, &.{
|
||||
.clear_depth = 1.0,
|
||||
.clear_depth = 0.0,
|
||||
.load_op = sdl.GPU_LOADOP_CLEAR,
|
||||
.store_op = sdl.GPU_STOREOP_DONT_CARE,
|
||||
.stencil_load_op = sdl.GPU_STOREOP_DONT_CARE,
|
||||
|
@@ -8,7 +8,6 @@ transform: Transform,
|
||||
/// tangent of the half of the view angle (90 degress = 1 "lens")
|
||||
lens: f32,
|
||||
near: f32,
|
||||
far: f32,
|
||||
/// width = height * aspect
|
||||
aspect: f32,
|
||||
|
||||
@@ -19,14 +18,11 @@ pub fn computeMatrix(camera: *Camera) void {
|
||||
|
||||
const xx = 1.0 / (camera.lens * camera.aspect);
|
||||
const yy = 1.0 / camera.lens;
|
||||
const fnmod = 1.0 / (camera.far - camera.near);
|
||||
const zz = camera.far * fnmod;
|
||||
const wz = -camera.near * camera.far * fnmod;
|
||||
const projection = @Vector(16, f32){
|
||||
xx, 0, 0, 0,
|
||||
0, yy, 0, 0,
|
||||
0, 0, -zz, wz,
|
||||
0, 0, -1, 0,
|
||||
xx, 0, 0, 0,
|
||||
0, yy, 0, 0,
|
||||
0, 0, 0, camera.near,
|
||||
0, 0, -1, 0,
|
||||
};
|
||||
camera.matrix = Transform.multiplyMatrix(projection, camera.transform.inverseMatrix());
|
||||
}
|
||||
@@ -61,9 +57,9 @@ pub fn mouse_in_quad(camera: Camera, mouse: @Vector(2, f32), quad_transform: Tra
|
||||
const hh = height * 0.5;
|
||||
const pi: [4]@Vector(2, f32) = .{
|
||||
.{ -hw, -hh },
|
||||
.{ -hw, hh },
|
||||
.{ hw, hh },
|
||||
.{ hw, -hh },
|
||||
.{ -hw, hh },
|
||||
.{ hw, hh },
|
||||
.{ hw, -hh },
|
||||
};
|
||||
var po: [4]@Vector(2, f32) = undefined;
|
||||
for (0..4) |i| {
|
||||
|
@@ -12,7 +12,7 @@ pub const BLEND_NORMAL = sdl.GPUColorTargetBlendState{
|
||||
};
|
||||
|
||||
pub const DEPTH_ENABLED = sdl.GPUDepthStencilState{
|
||||
.compare_op = sdl.GPU_COMPAREOP_LESS,
|
||||
.compare_op = sdl.GPU_COMPAREOP_GREATER,
|
||||
.enable_depth_test = true,
|
||||
.enable_depth_write = true,
|
||||
};
|
||||
|
@@ -459,7 +459,7 @@ pub fn draw() void {
|
||||
);
|
||||
|
||||
Graphics.drawObject(&World.cubemap, .{
|
||||
.scale = Graphics.camera.far,
|
||||
.scale = 1e20,
|
||||
.position = Graphics.camera.transform.position,
|
||||
});
|
||||
Graphics.clearDepth();
|
||||
|
Reference in New Issue
Block a user