着色器阶段
每个阶段的函数都有预定义的名称,因此建议你不要更改它们。
HSMain对应 hull shader(壳着色器)HSConstantMain对应 patch constant function(面片常量函数)DSMain对应 domain shader(域着色器)VSMain对应顶点着色器(不带参数)GSMain对应几何着色器PSMain对应像素着色器(不带参数)CSMain对应计算着色器(不带参数)
这些都是 void 方法。
几何着色器和曲面细分着色器需要某种预定义结构作为输入和输出。然而,由于 Stride 着色器是泛型的,无法事先知道结构会是什么。因此,这些着色器使用自动生成的 Input 和 Output 结构,以适配最终的着色器。
顶点着色器
顶点着色器必须设置带有 SV_Position 语义的变量。在 ShaderBase 中,它是 ShadingPosition。
例如:
override stage void VSMain()
{
...
streams.ShadingPosition = ...;
...
}
像素着色器
像素着色器必须设置带有 SV_Target 语义的变量。在 ShaderBase 中,它是 ColorTarget。
例如:
override stage void PSMain()
{
...
streams.ColorTarget = ...;
...
}
几何着色器
几何着色器示例:
[maxvertexcount(1)]
void GSMain(triangle Input input[3], inout PointStream<Output> pointStream)
{
...
// 填充 streams 对象
streams = input[0];
...
// 始终追加 streams
pointStream.Append(streams);
...
}
Input 可以在方法体中使用。它的行为与 streams 对象相同,并包含相同的成员。
Output 只在方法声明中使用。你应该将 streams 对象追加到几何着色器的输出流中。
曲面细分着色器
曲面细分着色器示例:
[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("HSConstantMain")]
[maxtessfactor(48.0)]
void HSMain(InputPatch<Input, 3> input, out Output output, uint uCPID : SV_OutputControlPointID)
{
...
output = streams;
}
void HSConstantMain(InputPatch<Input, 3> input, const OutputPatch<Input2, 3> output, out Constants constants)
{
...
output = streams;
...
}
[domain("tri")]
void DSMain(const OutputPatch<Input, 3> input, out Output output, in Constants constants, float3 f3BarycentricCoords : SV_DomainLocation)
{
...
output = streams;
...
}
Input 和 Input2 的行为都与 streams 相同。
Note
别忘了在阶段末尾将 output 赋值给 streams。
计算着色器
计算着色器示例:
[numthreads(2, 3, 5)]
void CSMain()
{
...
}
你可以继承 ComputeShaderBase 并重写 Compute 方法。