需求:根据当前像素的Depth计算出其View空间的Position
先说一种惯性思维的方法:既然知道depth是怎么算出来的,那么进行逆运算回去不就得到position了?
先说说depth是怎么出来的:
Vertexshader:
output.position=mul(input.postion,matWorldViewProject);
output.depth.xy=output.position.zw;
|
Pixelshader(输出z/w):
returninput.depth.x/input.depth.y;
|
那么,逆运算回去就很直接了(input.uv是全屏矩形的纹理坐标):
floatz=tex2D(DepthSampler,input.uv);
//transformtoprojectionspace
floatx=input.uv.x*2-1;
floaty=(1-input.uv.y)*2-1;
float4vProjectedPos=float4(x,y,z,1);
//transformtoviewspace
float4vPosition=mul(vProjectedPos,matInvProject);
return(vPosition.xyz/vPosition.w);
|
那么这样做有什么缺点呢?
lz/w是非线性分布的,经过RTT后再变换回去会有精度上的损失
l计算量有点大,要知道PS里的每个指令都是很宝贵的.
下面说说另一种非常快的算法,而且也可以解决精度问题.先看看摄像机视锥体的抽象形式:
从摄像机位置到远裁剪面发射一条射线,那么,对于可见的任意一点,有这么个关系:
vPositionView=vViewRayDir*fLinearDepth;
|
其中,fLinearDepth代表规格化的Z,它是线性分布的,即:
fLinearDepth=vPositionView.z/fFarClipDist;
|
剩下的,就是这个屏幕射线vViewRayDir从哪来的问题了.
我们知道,在View空间,摄像机位置是(0,0,0).那么,对于每条射线的方向,等价于射线与远裁剪面的交点坐标.即:
vViewRayDir=float3(fFarClipX,fFarClipY,fFarClipDist);
|
远裁剪面上的4个顶点坐标我们是可以算出来的,就是Frustum中的四个顶点.如果我们把这四个顶点坐标写入全屏矩形的顶点坐标中,然后在VS中输出,那么在PS中得到的就是已经插值好的射线方向了!
整理一下整个思路:
1.把vPositionView.z/fFarClipDist输出到RTT,这里因为是线性分布的,在精度允许的前提下可以进行压缩
2.从RTT里得到fLinearDepth,从VS_OUTPUT出的寄存器里得到已经插值好的vViewRayDir.xy,vViewRayDir.z就是fFarClipDist,Position的重建只需要一句计算就可以得到:
vPositionView=vViewRayDir*fLinearDepth;
|
Reference(要):http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/
<!--EndFragment-->
分享到:
相关推荐
An Improved AM-FM-Based Approach for Reconstructing Fingerprints from Minutiae
SFM论文——Structure-from-Motion Revisited,省的大家从网上再找了。这篇论文写于2016年,对于三维重建感兴趣的同学,这篇论文算是必读的。
We propose an algorithm to predict room layout from a single image that generalizes across panoramas and perspective images, cuboid layouts and more general layouts (e.g. “L”-shape room). Our method...
化石摇蚊与水深之关系:一种西北干旱区水文气候变化重建工具,陈建徽,张恩楼,代用指标的现代过程研究是古气候、古环境研究的基础,对于准确提取蕴含在地质载体中的气候环境信息有着不可替代的重要意义。...
An ExcelTM spreadsheet program for reconstructing the surface profile of former mountain glaciers and ice caps
RePEConstruct: Reconstructing binaries with self-modifying code and import address table destruction
from label maps, reconstructing objects from edge maps, and colorizing images, among other tasks. As a commu- nity, we no longer hand-engineer our mapping functions, and this work suggests we can ...
针对凸松弛方法在解决三维人体姿势估计的问题时存在迭代次数较多、准确度不高的不足,提出一种基于遗传优化的自适应凸松弛人体姿势估计算法。该算法首先对关键参数的更新方式进行自适应处理,然后利用遗传优化算法对...
RePEconstruct_Reconstructing_paper_self_源码.zip
A top story of the MIT Technology Review reviewed our work on May 6, 2017; CAS News and Daily Mail reported our work.本研究初步工作发表在OHBM 2017年会, oral presentation, acceptance rate = 3%,并获...
结膜细胞外基质利于结膜缺损的重建,文丹,王华,目的:本文着重调查同种异体结膜和结膜细胞外基质作为结膜组织替代物的特点与疗效。方法:实验采用30只兔子,其中6只为球结膜缺损
Reconstructing-Valid-CityJSON-model
结构光轮廓测量技术中的相位重构算法讨论,朱勇建,李安虎,针对三维数字化结构光轮廓测量技术,讨论了五种相位重构算法,即Schofield的快速傅里叶变换算法(采用4次傅里叶变换和逆变换),Volko
单幅图像人体运动3维重建,用到压缩感知的思想,很新颖。
the respective overlapping area and reconstructing only the updated part of the surface mesh. The proposed framework is flexible enough to be integrated with additional point label information, where ...
Reconstructing a PET attenuation map via penalized-likelihood estimation from real 2D PET transmission data.
Compressed sensing (also known as compressive sensing, compressive sampling, or sparse sampling) is a signal processing technique for efficiently acquiring and reconstructing a signal, by finding ...
We propose a region stepwise reconstruction method in CW-DOT scheme for reconstructing the background absorption and reduced scattering coefficients of the two-layered slab sample with the known ...
We describe a procedure for reconstructing documents that have been shredded by hand, a problem that often arises in forensics. The proposed method first applies a polygonal approximation in order to...
重构 Ruby 该库表示通过上发布的博客系列所做的工作 。 目的是使用 C 从头开始编写一个完全有效的 ruby 实现。