HLSL基本以C语言的习惯来写的,但是如果完全以C语言的角度来看,我个人感觉入门最难理解就是顶点着色器和像素着色器的两个函数的参数传递了。
下面以最简单的HLSL中效果框架举例说下自己的理解。
uniform extern float4x4 gWVP;
struct OutputVS
{
float4 posH : POSITION0;
float4 color : COLOR0;
};
OutputVS ColorVS(float3 posL : POSITION0, float4 c : COLOR0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);
// Just pass the vertex color into the pixel shader.
outVS.color = c;
// Done--return the output.
return outVS;
}
float4 ColorPS(float4 c : COLOR0) : COLOR
{
return c;
}
technique ColorTech
{
pass P0