在像素着色器中计算世界空间坐标
我有一个像素着色器,我想根据我的世界空间坐标来计算每个像素的位置.我该怎么做?我需要什么?
I have a pixel shader and I want to calculate the position of each pixel in terms of my world space coordinates. How would I do this? What would I need?
我有一个ps_input
结构,该结构的float4位置为:SV_POSITION
.我假设这很重要,但是存储在里面的值似乎有点可笑.
I have a ps_input
structure which has a float4 position : SV_POSITION
. I'm assuming this is important, but the values stored inside seems to be kind of funny.
我似乎无法弄清楚它们之间的关系.例如,如果一个像素是2d,那么为什么它具有w分量或z分量呢?
I can't seem to figure out what they relate to. For instance, if a pixel is 2d, how come it has a w component, or a z component for that matter?
我正在使用DirectX
,并且像素着色器位于HLSL
中. C++
作为我在CPU上的编程语言.
I'm using DirectX
and the pixel shader is in HLSL
. C++
as my programing language on the CPU.
任何帮助将不胜感激.
如果我没记错的话,SV_POSITION仅是0-> W 0-> H,因此它描述了它在屏幕上的位置.该站点包含更多信息: http: //msdn.microsoft.com/zh-CN/library/windows/desktop/bb509647(v=vs.85).aspx
If i remember this correctly, SV_POSITION is only 0->W 0->H, so it describes where it is on the screen. this site contains more information : http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx
要使像素进入世界空间,请将像素坐标转换回世界空间.数学和所有数学都有些棘手(我想是!) 但是这篇文章应该可以帮到您! http://jcoluna.wordpress.com/2011/01/27/reconstructing-view-space-position-from-depth/
To get the pixel to world space, you transform your pixelcordinate back to worlspace. it´s a bit tricky with the math and all ( i think it is! ) but this article should help you out! http://jcoluna.wordpress.com/2011/01/27/reconstructing-view-space-position-from-depth/
否则,明智地搜索像素到视域.我知道您想要世界空间,但将所有内容转换为视图空间可能更快.
else wise search for pixel to viewspace. i know you wanted worldspace, but converting everything to viewspace is probably faster.