# HG changeset patch # User sam # Date 1722167746 -25200 # Node ID e9b8d87b9883e501f43ee6ccc9458ca21462cfbc # Parent bfb75c934f4e5ff9bf4d35e270fac2f638871737 fix: super stupid bug in perspective matrix X( diff -r bfb75c934f4e -r e9b8d87b9883 semiconginev2/core/matrix.nim --- a/semiconginev2/core/matrix.nim Sun Jul 28 17:33:41 2024 +0700 +++ b/semiconginev2/core/matrix.nim Sun Jul 28 18:55:46 2024 +0700 @@ -444,12 +444,12 @@ makeRandomMatrixInit(TMat4) func Perspective*(fovy, aspect, zNear, zFar: float32): Mat4 = - let tanHalfFovy = tan(fovy / 2) + let tanHalfFovy = 1 / tan(fovy / 2) return Mat4(data: [ - 1 / (aspect * tanHalfFovy), 0, 0, 0, - 0, 1 / tanHalfFovy, 0, 0, + tanHalfFovy / aspect, 0, 0, 0, + 0, tanHalfFovy, 0, 0, 0, 0, zFar / (zFar - zNear), -(zFar * zNear) / (zFar - zNear), - 0, 0, 1, 1, + 0, 0, 1, 0, ]) func Ortho*(left, right, top, bottom, zNear, zFar: float32): Mat4 = diff -r bfb75c934f4e -r e9b8d87b9883 semiconginev2/rendering.nim --- a/semiconginev2/rendering.nim Sun Jul 28 17:33:41 2024 +0700 +++ b/semiconginev2/rendering.nim Sun Jul 28 18:55:46 2024 +0700 @@ -293,6 +293,7 @@ defer: deallocCStringArray(deviceExtensionsC) let enabledFeatures = VkPhysicalDeviceFeatures( fillModeNonSolid: true, + depthClamp: true, wideLines: true, largePoints: true, ) diff -r bfb75c934f4e -r e9b8d87b9883 semiconginev2/rendering/shaders.nim --- a/semiconginev2/rendering/shaders.nim Sun Jul 28 17:33:41 2024 +0700 +++ b/semiconginev2/rendering/shaders.nim Sun Jul 28 18:55:46 2024 +0700 @@ -364,6 +364,7 @@ cullMode: openArray[VkCullModeFlagBits] = [VK_CULL_MODE_BACK_BIT], frontFace: VkFrontFace = VK_FRONT_FACE_CLOCKWISE, lineWidth = 1'f32, + depthClampEnable = false, ): Pipeline[TShader] = # create pipeline @@ -445,7 +446,7 @@ ) rasterizer = VkPipelineRasterizationStateCreateInfo( sType: VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - depthClampEnable: VK_FALSE, + depthClampEnable: depthClampEnable, rasterizerDiscardEnable: VK_FALSE, polygonMode: polygonMode, lineWidth: lineWidth, diff -r bfb75c934f4e -r e9b8d87b9883 tests/test_gltf.nim --- a/tests/test_gltf.nim Sun Jul 28 17:33:41 2024 +0700 +++ b/tests/test_gltf.nim Sun Jul 28 18:55:46 2024 +0700 @@ -138,8 +138,10 @@ camPos += camDir * forward * dt camPos += camDirSide * sideward * dt + let fovH = PI / 2 + let fovV = 2 * arctan(tan(fovH / 2) * 1 / GetAspectRatio()) descriptors.data.camera.data.viewPerspective = ( - Perspective(PI/3, aspect = GetAspectRatio(), zNear = 0.1, zFar = 1) * + Perspective(fovV, aspect = GetAspectRatio(), zNear = 0.01, zFar = 20) * Rotate(-camPitch, X) * Rotate(-camYaw, Y) * Translate(-camPos) )