Directx11教程(16) D3D11管线(5)
2012-03-24 09:57
309 查看
本章我们学习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的功能。
首先再看看我们的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的功能。
相关文章推荐
- Directx11教程(15) D3D11管线(4)
- Directx11教程(13) D3D11管线(1)
- Directx11教程(17) D3D11管线(6)
- Directx11教程(53) D3D11管线(8) GS的调度执行
- Directx11教程(14) D3D11管线(3)
- Directx11教程(18) D3D11管线(7)
- Directx11教程(14) D3D11管线(2)
- Directx11教程(66) D3D11屏幕文本输出(1)
- Play Framework Web开发教程(16): 处理HTTP请求和响应
- Directx11基础教程三之VertexShader,PixelShader,buffer
- 免安装版mysql5.7.10-16配置教程(1)
- Ubuntu16. 04仿Mac美化教程
- vb.net 教程 5-16 图像处理之ImageAttributes 类2 颜色矩阵3
- java初学者实践教程16-static关键字
- vb.net 教程 5-16 图像处理之ImageAttributes 类2 颜色矩阵4
- Win10/Win7 U盘安装Ubuntu16.04/Ubuntu 14.04/16 双系统详细教程[亲测]
- 16_传智播客Spring2.5视频教程_使用CGLIB实现AOP功能与AOP概念解释
- 2013 duilib入门简明教程 -- 结合win32和MFC (16)
- 【D3D11系列教程】 第一讲 初始化Direct3D
- Directx11教程(12) 禁止alt+enter全屏窗口