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 c1a6e2fe36de7d7d101b2374e6c3d86b623d7da4
Author: Vincent Torri <vincent.to...@gmail.com>
AuthorDate: Fri Aug 18 21:03:11 2023 -0700

    Update 'Direct3D 11 for 2D: Display a pink triangle'
---
 Direct3D-11-for-2D%3A-Display-a-pink-triangle.md | 47 ++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 4 deletions(-)

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 fa6087e..0d025d7 100644
--- a/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
+++ b/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
@@ -2,7 +2,7 @@
 
 The first step for an Evas software engine is to draw pixels in a rectangle. In Direct3D, a rectangle is composed of two triangles, so the first step is to draw one triangle. The next section will modify the code to draw a pink rectangle.
 
-For now, we have used the Rasterizer and Output Merger stages of the pipeline. The following stages are needed to draw something:
+For now, we have used the Rasterizer and Output Merger stages of the pipeline. The following additional stages are needed to draw something:
 
 1. the Input Asembler (IA) stage, which reads the geometric data,
 2. the Vertex Shader (VS) stage that transforms the geometric data built in the IA stage,
@@ -32,7 +32,7 @@ The vertices are displayed in a (normalized) coordinate system different from th
 
 So the normalized coordinate system goes from (-1, 1), corresponding to pixel (0,0) in the window of size (w, h) pixels, to (1, -1), corresponding to pixel (w, h) outside the window. So the normalized coordinate (0, 0) corresponds to the center of the window.
 
-So conversion from pixel coordinates on the screen (from (0, 0) to (w, h), that is 1 pixel outside the window) to normalized coordinates (from (-1, 1) to (1, -1)) must be computed. It is basic math. Let us call xf(x) the value of the normalized coordinates, function of the x coordinate of a pixel. The value xf(x) is affine in x, meaning xf(x) = ax + b, a and b being real numbers. So
+Conversion from pixel coordinates on the screen (from (0, 0) to (w, h), that is 1 pixel outside the window) to normalized coordinates (from (-1, 1) to (1, -1)) must be computed. It is basic math. Let us call xf(x) the value of the normalized coordinates, function of the x coordinate of a pixel. The value xf(x) is affine in x, meaning xf(x) = ax + b, a and b being real numbers. So
 
 * xf(0) = -1 = b, and
 * xf(w) = 1 = aw - 1
@@ -48,7 +48,7 @@ These two macros will be used in the final code below.
 
 ### The scene
 
-We have to pass the vertices of our triangle to the GPU. Several steps are needed:
+We have to pass the vertices of our triangle (which are the geometric data) to the GPU. Several steps are needed:
 
 * A vertex buffer which contains the list of the vertices (and other values). The vertices must be set in clock-wise order. The vertex buffer will be binding to the pipeline in the IA stage with `IASetVertexBuffers()`.
 * An index buffer which is a lit of indices (integer numbers) that index the vertices in the vertex buffer. For a triangle, it is useless, but for a rectangle, it will be used. Index buffers are used for memory and speed optimizations.. The vertex buffer will be binding to the pipeline in the IA stage with `IASetIndexBuffer()`.
@@ -66,4 +66,43 @@ We have to pass the vertices of our triangle to the GPU. Several steps are neede
 
 ### Vertex and Pixel shaders
 
-The following code is the HLSL code which contains both the function `main_vs()` for the vertex shader program, and the function `main_ps()` for the pixel shader program:
\ No newline at end of file
+The following code is the HLSL code which contains both the function `main_vs()` for the vertex shader program, and the function `main_ps()` for the pixel shader program:
+
+```c
+struct vs_input
+{
+    float2 position : POSITION;
+};
+
+struct ps_input
+{
+    float4 position : SV_POSITION;
+};
+
+/*
+ * vertex shater program
+ *
+ * @param input the 2 coordinates of a vertex, got from CPU
+ * @return the 4D position of the pixel corresponding to the vertex in GPU
+ */
+ps_input main_vs(vs_input input )
+{
+    ps_input output;
+    output.position = float4(input.position, 0.0f, 1.0f);
+    return output;
+}
+
+/*
+ * pixel shater program
+ *
+ * @param input the 4D coordinates of a pixel
+ * @return the color of the pixel in RGBA colorspace, here pink
+ */
+float4 main_ps(ps_input input) : SV_TARGET
+{
+    return float4(1.0f, 0.0f, 1.0f, 1.0f);
+}
+```
+
+* The vertex shader program, named `main_vs()`, take as input a structure which has the coordinates of a vertex (of our triangle). It must be identical to the `Vertex structure above. It can also contains a color or a texture. The function returns a position with the 3 coordinates x, y and z, plus a fourth one (used for matrix transformations). The 4 coordinates are used when rotations or translations are needed. Then, they are transformed with a matrix of size 4x4. The new coordinates a [...]
+* The pixel shader program, named `main_ps()`, takes as input the output of `` main_vs()`, that is, the final coordinate of the vertex. It will be called for each pixel in the polygon (that is a triangle in our case). It returns the color a the corresponding pixel, that is pink for each pixel in our case.

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to