Quick Syntax
hlsl
struct VSIn { float3 position : POSITION; float2 uv : TEXCOORD0; };
struct VSOut { float4 position : SV_POSITION; float2 uv : TEXCOORD0; };
VSOut VSMain(VSIn input)
{
VSOut output;
output.position = float4(input.position, 1.0);
output.uv = input.uv;
return output;
}
float4 PSMain(VSOut input) : SV_TARGET
{
return float4(input.uv, 0.0, 1.0);
}VS는 rasterizer가 사용할 clip-space SV_POSITION을 내보내야 합니다. 다른 field는 VS 출력과 PS 입력의 semantic index·component type이 호환되어야 보간됩니다.
보간
UV, color, world position 같은 값은 triangle 내부에서 perspective-correct 방식으로 보간됩니다. Integer ID나 primitive 전체에서 같은 값은 nointerpolation 같은 modifier가 필요할 수 있습니다. Normal과 tangent는 보간 뒤 길이가 1이 아닐 수 있으므로 PS에서 다시 normalize합니다.
SV_VertexID, SV_InstanceID, SV_PrimitiveID, SV_IsFrontFace는 pipeline이 제공하는 system value입니다. 어느 stage에서 사용할 수 있는지는 shader model 계약을 확인합니다.
자주 틀리는 점
POSITION과SV_POSITION을 같은 역할로 보지 않습니다.- Semantic 이름만 맞고 float component 수가 다르면 호환 여부를 확인합니다.
- World-space 값과 view-space 값을 같은 dot 계산에 섞지 않습니다.
- PS가 필요 없는 큰 struct를 모두 넘겨 interpolation bandwidth를 늘리지 않습니다.
참고 링크
2 sources