【发布时间】:2017-07-02 03:03:10
【问题描述】:
我有以下片段和顶点着色器。
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 坐标以及相应的深度来重建该点。
我需要一些帮助来构建着色器以获取特定纹理坐标处深度的世界视图位置。
【问题讨论】:
标签: directx shader hlsl ogre3d