I have a question about vertex shader output interpolation. Fox example, when implement shadow map, we need a depth map. Let's first suppose that we need a non-linear depth map, Z/W. Consider following two shaders, which is the correct way to output a non-linear depth map. I have seen online that someone use the first version, while others use second. But I think only first version is right in math.

// Version 1

void NonLinearDepthVS(in float3 iPos : POSITION, out float4 oPos : SV_Position, out float oDepth : TEXCOORD0)

{

oPos = mul(iPos, mul(World, ViewProj));

oDepth = oPos.z / oPos.w;

}

float4 NonLinearDepthPS(in float oDepth : TEXCOORD0) : SV_Target0

{

return float4(oDepth, 0, 0, 0);

}

// Version 2

void NonLinearDepthVS(in float3 iPos : POSITION, out float4 oPos : SV_Position, out float2 oDepth : TEXCOORD0)

{

oPos = mul(iPos, mul(World, ViewProj));

oDepth = oPos.zw;

}

float4 NonLinearDepthPS(in float2 oDepth : TEXCOORD0) : SV_Target0

{

return float4(oDepth.x / oDepth.y, 0, 0, 0);

}