From 31dd3db82ef70c360e8570d31cfb026abedc47c3 Mon Sep 17 00:00:00 2001 From: pwbh Date: Thu, 21 Nov 2024 08:48:48 +0200 Subject: [PATCH 1/4] Add explanation for the depth on ortho projection --- webgpu/lessons/webgpu-orthographic-projection.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/webgpu/lessons/webgpu-orthographic-projection.md b/webgpu/lessons/webgpu-orthographic-projection.md index f8eabc74..e198a20d 100644 --- a/webgpu/lessons/webgpu-orthographic-projection.md +++ b/webgpu/lessons/webgpu-orthographic-projection.md @@ -628,7 +628,14 @@ Just like we needed to convert from pixels to clip space for X and Y, for Z we need to do the same thing. In this case we making the Z axis "pixel units" as well?. We'll pass in some value similar to `width` for the `depth` so our space will be 0 to `width` pixels wide, 0 to `height` pixels tall, but -for `depth` it will be `-depth / 2` to `+depth / 2`. +for `depth` it will be from 0 to `depth`, unlike the clip sapce on X and Y which +are between -1, 1 the Z coordinate (our depth) is between 0 and 1 so we have to +project to it accordingly this is why we devide the depth we set by 0.5 +(see 10th mattrix element) and add 0.5 (see 14th matrix element). + +For example lets try with depth of 400 unit pixels, simillarly to how we transformed pixels to clip space we will use the following formula `(0 >= Z coordinate of a vertex <= depth) * (0.5 / depth) + 0.5`: + +So for a some vertex where Z coordinate is 150px and the maximum depth is 400px we will get `150 * (0.5 / 400) + 0.5 = 0.6875`. We need to provide a 4x4 matrix in our uniforms From d1bf914385438261bd59f09f2bfb50bc2a877f50 Mon Sep 17 00:00:00 2001 From: pwbh Date: Thu, 21 Nov 2024 08:54:09 +0200 Subject: [PATCH 2/4] typo --- webgpu/lessons/webgpu-orthographic-projection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webgpu/lessons/webgpu-orthographic-projection.md b/webgpu/lessons/webgpu-orthographic-projection.md index e198a20d..98485474 100644 --- a/webgpu/lessons/webgpu-orthographic-projection.md +++ b/webgpu/lessons/webgpu-orthographic-projection.md @@ -631,7 +631,7 @@ so our space will be 0 to `width` pixels wide, 0 to `height` pixels tall, but for `depth` it will be from 0 to `depth`, unlike the clip sapce on X and Y which are between -1, 1 the Z coordinate (our depth) is between 0 and 1 so we have to project to it accordingly this is why we devide the depth we set by 0.5 -(see 10th mattrix element) and add 0.5 (see 14th matrix element). +(see 10th matrix element) and add 0.5 (see 14th matrix element). For example lets try with depth of 400 unit pixels, simillarly to how we transformed pixels to clip space we will use the following formula `(0 >= Z coordinate of a vertex <= depth) * (0.5 / depth) + 0.5`: From d9666c4e999b7b6d1f623af304f5d452a3efc193 Mon Sep 17 00:00:00 2001 From: pwbh Date: Thu, 21 Nov 2024 21:57:55 +0200 Subject: [PATCH 3/4] break lines --- webgpu/lessons/webgpu-orthographic-projection.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webgpu/lessons/webgpu-orthographic-projection.md b/webgpu/lessons/webgpu-orthographic-projection.md index 98485474..96d9b305 100644 --- a/webgpu/lessons/webgpu-orthographic-projection.md +++ b/webgpu/lessons/webgpu-orthographic-projection.md @@ -633,9 +633,12 @@ are between -1, 1 the Z coordinate (our depth) is between 0 and 1 so we have to project to it accordingly this is why we devide the depth we set by 0.5 (see 10th matrix element) and add 0.5 (see 14th matrix element). -For example lets try with depth of 400 unit pixels, simillarly to how we transformed pixels to clip space we will use the following formula `(0 >= Z coordinate of a vertex <= depth) * (0.5 / depth) + 0.5`: +For example lets try with depth of 400 unit pixels, simillarly to how we +transformed pixels to clip space we will use the following formula +`(0 >= Z coordinate of a vertex <= depth) * (0.5 / depth) + 0.5`: -So for a some vertex where Z coordinate is 150px and the maximum depth is 400px we will get `150 * (0.5 / 400) + 0.5 = 0.6875`. +So for a some vertex where Z coordinate is 150px and the maximum depth +is 400px we will get `150 * (0.5 / 400) + 0.5 = 0.6875`. We need to provide a 4x4 matrix in our uniforms From 9f24a9e979a338c4e76289cb287e6b4dba9d8fd0 Mon Sep 17 00:00:00 2001 From: pwbh <127856937+pwbh@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:48:13 +0200 Subject: [PATCH 4/4] fix typo --- webgpu/lessons/webgpu-orthographic-projection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webgpu/lessons/webgpu-orthographic-projection.md b/webgpu/lessons/webgpu-orthographic-projection.md index 96d9b305..9d7d918d 100644 --- a/webgpu/lessons/webgpu-orthographic-projection.md +++ b/webgpu/lessons/webgpu-orthographic-projection.md @@ -637,7 +637,7 @@ For example lets try with depth of 400 unit pixels, simillarly to how we transformed pixels to clip space we will use the following formula `(0 >= Z coordinate of a vertex <= depth) * (0.5 / depth) + 0.5`: -So for a some vertex where Z coordinate is 150px and the maximum depth +So for some vertex where Z coordinate is 150px and the maximum depth is 400px we will get `150 * (0.5 / 400) + 0.5 = 0.6875`. We need to provide a 4x4 matrix in our uniforms