This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository Direct3D.wiki.
View the commit online.
commit 3985557d861da239bb6843fbd87a88e06df02fbf
Author: Vincent Torri <vincent.to...@gmail.com>
AuthorDate: Fri Aug 18 22:41:08 2023 -0700
Update 'Direct3D 11 for 2D: Display a pink triangle'
---
Direct3D-11-for-2D%3A-Display-a-pink-triangle.md | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md b/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
index b6f2364..7b783fe 100644
--- a/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
+++ b/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
@@ -1219,4 +1219,21 @@ When the program is launched, you should obtain a window with a pink triangle, l
<p align="center">
<img alt="coordinates system" src="" width="30%" height="30%">
-</p>
\ No newline at end of file
+</p>
+
+### Scale the coordinates in the vertex shader
+
+Two macros were added to scale from pixels coordinates to the normalized coordinates:
+
+```c
+#define XF(w,x) ((float)(2 * (x) - (w)) / (float)(w))
+#define YF(h,y) ((float)((h) - 2 * (y)) / (float)(h))
+```
+
+Note that the width and height are obviously needed for the computations. These computations can be done in the shader. But the size is still needed. The classic way to provide some values in a shader is a global variable. This global varial is stored in a `constant buffer`. Mathematically, only *1/w* and *1/h* are needed in the shader, so 2 `floats`. But to create a `constant buffer`, one need to pass a multiple of 16 bytes (according to the [documentation of MSDN](https://web.archive.o [...]
+
+```c
+FLOAT ivps[4]; /* inverse viewport size */
+```
+
+and the 2 first elements are the inverse of the width and height. The 2 other elements are unused and set to 0. Once this array is filled, we copy it to the GPU with the `Map()` function. Here are the shader and C files, with their diff:
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.