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 edc64ba1925c78fa25999208679737de2d2b24ba
Author: Vincent Torri <vincent.to...@gmail.com>
AuthorDate: Sat Aug 19 04:09:29 2023 -0700

    Update 'Direct3D 11 for 2D: Changing the color of the triangle'
---
 ...for-2D%3A-Changing-the-color-of-the-triangle.md | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/Direct3D-11-for-2D%3A-Changing-the-color-of-the-triangle.md b/Direct3D-11-for-2D%3A-Changing-the-color-of-the-triangle.md
index 4e6b205..4e85b51 100644
--- a/Direct3D-11-for-2D%3A-Changing-the-color-of-the-triangle.md
+++ b/Direct3D-11-for-2D%3A-Changing-the-color-of-the-triangle.md
@@ -31,3 +31,65 @@ which means that the first 8 bytes (R32G32) are 2 variables of type UINT (which
 * Add the color components to `triangle_new()` and fill the vertex accordingly.
 
 * Call `triangle_new()` with the chosen color.
+
+On the shader side:
+
+* Add 4 floats in the `vs_input` and `ps_input` structures
+* Fill `output` color member with the `input` color member.
+* Return the color member of the `input` of the pixel shader `main()` function.
+
+Here is the new shader code and the diff:
+
+**shader_3.hlsl**
+
+```c
+cbuffer cv_viewport : register(b0)
+{
+    float2 viewport_inv_size;
+    float2 dummy;             /* unused, to have a multiple of 16 bytes */
+}
+
+struct vs_input
+{
+    uint2 position : POSITION;
+    float4 color : COLOR;
+};
+
+struct ps_input
+{
+    float4 position : SV_POSITION;
+    float4 color : COLOR;
+};
+
+/*
+ * vertex shater program
+ *
+ * @param input the 2 coordinates of a pixel, got from CPU
+ * @return the 4D position of the normalized coordinates of the vertex in GPU
+ * as well as the color
+ */
+ps_input main_vs(vs_input input)
+{
+    ps_input output;
+    float2 p = input.position;
+    p *= viewport_inv_size;
+    p *= 2.0f;
+    p -= 1.0f;
+    p.y *= -1.0f;
+    output.position = float4(p, 0.0f, 1.0f);
+    output.color = input.color;
+    return output;
+}
+
+/*
+ * pixel shater program
+ *
+ * @param input the 4D coordinates of a pixel and the color
+ * @return the color of the pixel in RGBA colorspace passed as input
+ */
+float4 main_ps(ps_input input) : SV_TARGET
+{
+    return input.color;
+}
+```
+

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

Reply via email to