HLSL顶点声明语义问题

时间:2013-07-29 21:42:49

标签: xna directx hlsl monogame

当我将一个byte4设置为POSITION语义中的顶点声明时会发生什么,并且在着色器中我使用unit4作为相应的数据类型(因为没有byte4)。

  

uint4测试:POSITION0;

这里会发生什么,有浮动?

  

float4 Tint:POSTION0;

1 个答案:

答案 0 :(得分:2)

uint4是正确的。

无论顶点缓冲区数据是8位,16位还是32位整数,数据都将转换为32位整数。对于浮点数也是如此,着色器处理32位浮点数(除非您使用双精度类型)并且任何输入数据都从其基础格式转换。

然而,你不能做的是从整数和浮点转换为获取顶点缓冲区的一部分。获得数据后,您可以在float和integer之间自由转换,但输入属性类型(uint或float)必须与输入布局中指定的DXGI_FORMAT匹配。如果您尝试将输入声明为浮动4,当它实际上是一个uint4时,您将收到类似于此的警告:

D3D11 WARNING: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'POSITION'/0 and component(s) of the type 'float32'.  However, the matching entry in the Input Layout declaration, element[0], specifies mismatched format: 'R8G8B8A8_UINT'.  This is not an error, since behavior is well defined: The element format determines what data conversion algorithm gets applied before it shows up in a shader register. Independently, the shader input signature defines how the shader will interpret the data that has been placed in its input registers, with no change in the bits stored.  It is valid for the application to reinterpret data as a different type once it is in the vertex shader, so this warning is issued just in case reinterpretation was not intended by the author. [ STATE_CREATION WARNING #391: CREATEINPUTLAYOUT_TYPE_MISMATCH]