Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50de9c1

Browse files
committed
Fix clip coordinates/normalized device coordinates explanation
1 parent bfa5b0f commit 50de9c1

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

03_Drawing_a_triangle/02_Graphics_pipeline_basics/01_Shader_modules.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,31 @@ on to the fragment shader, like color and texture coordinates. These values will
5353
then be interpolated over the fragments by the rasterizer to produce a smooth
5454
gradient.
5555

56-
Clip coordinates are [homogeneous coordinates](https://en.wikipedia.org/wiki/Homogeneous_coordinates)
56+
A *clip coordinate* is a four dimensional vector from the vertex shader that is
57+
subsequently turned into a *normalized device coordinate* by dividing the whole
58+
vector by its last component. These normalized device coordinates are
59+
[homogeneous coordinates](https://en.wikipedia.org/wiki/Homogeneous_coordinates)
5760
that map the framebuffer to a [-1, 1] by [-1, 1] coordinate system that looks
5861
like the following:
5962

60-
![](/images/clip_coordinates.svg)
63+
![](/images/normalized_device_coordinates.svg)
6164

6265
You should already be familiar with these if you have dabbed in computer
6366
graphics before. If you have used OpenGL before, then you'll notice that the
6467
sign of the Y coordinates is now flipped. The Z coordinate now uses the same
6568
range as it does in Direct3D, from 0 to 1.
6669

6770
For our first triangle we won't be applying any transformations, we'll just
68-
specify the positions of the three vertices directly in clip coordinates to
69-
create the following shape:
71+
specify the positions of the three vertices directly as normalized device
72+
coordinates to create the following shape:
7073

7174
![](/images/triangle_coordinates.svg)
7275

76+
We can directly output normalized device coordinates by outputting them as clip
77+
coordinates from the vertex shader with the last component set to `1`. That way
78+
the division to transform clip coordinates to normalized device coordinates will
79+
not change anything.
80+
7381
Normally these coordinates would be stored in a vertex buffer, but creating a
7482
vertex buffer in Vulkan and filling it with data is not trivial. Therefore I've
7583
decided to postpone that until after we've had the satisfaction of seeing a

05_Uniform_buffers/00_Descriptor_layout_and_buffer.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ Note that the order of the `uniform`, `in` and `out` declarations doesn't
9393
matter. The `binding` directive is similar to the `location` directive for
9494
attributes. We're going to reference this binding in the descriptor layout. The
9595
line with `gl_Position` is changed to use the transformations to compute the
96-
final position in clip coordinates.
96+
final position in clip coordinates. Unlike the 2D triangles, the last component
97+
of the clip coordinates may not be `1`, which will result in a division when
98+
converted to the final normalized device coordinates on the screen. This is used
99+
in perspective projection as the *perspective division* and is essential for
100+
making closer objects look larger than objects that are further away.
97101

98102
## Descriptor set layout
99103

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)