原文: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教程中曾经给过很多图。

在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近平面和远平面距离)。

   

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

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

 

最新文章

  1. Windows Phone 如何在程序中播放提示声音?
  2. google closure--继承模块二:goog.base()demo分析
  3. 实现窗体随着鼠标移动(控件)--《用delphi开发共享软件》-15.1任务管理器
  4. swift 附属脚本
  5. 电影TS、TC、SCR、R5、BD、HD等版本是什么意思
  6. jquery 整理之一
  7. hbase日常操作及维护
  8. Hadoop 2.4.0完全分布式平台搭建、配置、安装
  9. 201521123119《Java程序设计》第7周学习总结
  10. linux 文件处理命令
  11. ExtJS初探:在项目中使用ExtJS
  12. Tomcat通过自带的Cluster方式实现Session会话共享环境操作记录
  13. Number (float bool complex)浮点型、bool 布尔型 True、False 、complex 复数类型
  14. SAP 创建 component
  15. JVM中的新生代、老年代和永生代
  16. leetcode138
  17. JS 相关
  18. 等待时间,time.sleep()和implicitly_wait()
  19. csdn获得积分
  20. ajax success和error接收了哪些状态码

热门文章

  1. 微信audio自动播放(ios播放问题)
  2. Joomla - akeeba backup(joomla网站备份、迁移扩展)
  3. csdn vip文章:使用matlab模拟镜头失真
  4. 请问Pycharm如何实现变量的批量重命名?
  5. Leetcode103. Binary Tree Zigzag Level Order Traversal二叉树的锯齿形层次遍历
  6. Leetcode563.Binary Tree Tilt二叉树的坡度
  7. Mysql指定服务器访问
  8. centos apache安装oracle扩展
  9. LintCode刷题笔记-- PaintHouse 1&amp;2
  10. Aspose Words、Excel导出等操作