zoukankan      html  css  js  c++  java
  • Directx11教程(16) D3D11管线(5)

    本章我们学习VS中具体做些什么事情?

    首先再看看我们的VS shader代码:

    Clolor.vs


    PixelInputType ColorVertexShader(VertexInputType input)
    {
        PixelInputType output;
       

        // Change the position vector to be 4 units for proper matrix calculations.
        input.position.w = 1.0f;

        // Calculate the position of the vertex against the world, view, and projection matrices.
        output.position = mul(input.position, worldMatrix);
        output.position = mul(output.position, viewMatrix);
        output.position = mul(output.position, projectionMatrix);
       
        // Store the input color for the pixel shader to use.
        output.color = input.color;
       
        return output;

    }


        我们现在知道的信息是:MatrixBuffer被UMD放在了video memory中的const buffer,并在VS开始执行的时候被传入shader。

        shader block,通常被叫做CU或者SIMD,它有很多的stream core组成,一般stream core是一个可以执行一维向量(x,y,z,w)浮点计算的单位,一个CU有很多streamcore组成,这个我们OpenCL教程中曾经给过很多图。

    image

    image

    在VS中,很多stream core并行执行,每一个stream core处理一个顶点的VS shader计算。

    从我们的VS shader代码中,可以知道,它主要做空间转化。

    // Change the position vector to be 4 units for proper matrix calculations.
    input.position.w = 1.0f;

    // Calculate the position of the vertex against the world, view, and projection matrices.
    output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    把顶点从世界坐标系中转化到齐次clip空间中。具体的推导大家可以查询相关资料。

    推荐Mathematics.for.3D.Game.Programming.and.Computer.Graphics.Lengyel.3ed.Course2012这本书。

    注意:clip裁剪空间是一个长方体,

    -r <= x <= r (r是窗口宽高比例)

    -1 <= y <= 1

    f <= z <= n (f,n近平面和远平面距离)。

    fig4_4.jpg

       

         另外VS shader还把顶点颜色传到下一个阶段,在我们前面的教程中,我们都是直接给顶点赋颜色值,通常的做法是根据顶点法向和光照来计算颜色,这些代码通常也在VS shader中,在后面的其它教程中,我们也会逐渐学习这些知识。

         VS shader计算出来的顶点会放在一个FIFO中,在D3D11逻辑管线中,下一个stage是RS,其实在大部分硬件中,VS FIFO(不考虑GS,tessellation操作)的内容会传输到一个固定管线称作PA(体元装配),在这个阶段执行透视除法,clip等操作,下一节,我们来学习了解PA的功能。

     

  • 相关阅读:
    剑指offer题解(python版)(更新到第16题)
    Java基础知识详解:值传递
    [LeetCode] 583. Delete Operation for Two Strings
    [LeetCode] 856. Score of Parentheses
    [LeetCode] 1129. Shortest Path with Alternating Colors
    [LeetCode] 1561. Maximum Number of Coins You Can Get
    [LeetCode] 1052. Grumpy Bookstore Owner
    [LeetCode] 991. Broken Calculator
    [LeetCode] 1054. Distant Barcodes
    [LeetCode] 1245. Tree Diameter
  • 原文地址:https://www.cnblogs.com/mikewolf2002/p/2415179.html
Copyright © 2011-2022 走看看