我有以下片段和頂點着色器。線性深度到世界位置
HLSL代碼 ` //頂點着色器 // ---------------------------------- -------------------------------------------------
void mainVP(
float4 position : POSITION,
out float4 outPos : POSITION,
out float2 outDepth : TEXCOORD0,
uniform float4x4 worldViewProj,
uniform float4 texelOffsets,
uniform float4 depthRange) //Passed as float4(minDepth, maxDepth,depthRange,1/depthRange)
{
outPos = mul(worldViewProj, position);
outPos.xy += texelOffsets.zw * outPos.w;
outDepth.x = (outPos.z - depthRange.x)*depthRange.w;//value [0..1]
outDepth.y = outPos.w;
}
// Fragment shader
void mainFP(float2 depth: TEXCOORD0, out float4 result : COLOR) {
float finalDepth = depth.x;
result = float4(finalDepth, finalDepth, finalDepth, 1);
}
`
此着色器產生的深度圖。
然後必須使用此深度圖來重建深度值的世界位置。我已經搜索了其他帖子,但他們似乎沒有使用我使用的相同公式存儲深度。唯一類似的帖子是以下內容 Reconstructing world position from linear depth
因此,我很難用深度圖和相應深度的x和y座標重建點。
我需要一些幫助來構建着色器來獲取特定紋理座標深度的世界視圖位置。
看來你的解決方案不是爲了線性深度。我有一個着色器按照你所說的方式工作,但我需要有另一個着色器以線性深度工作。 – nickygs