我有以下片段和顶点着色器。线性深度到世界位置
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