在像素着色器中计算世界空间坐标 [英] Calculating world space coordinates in the pixel shader

查看:344
本文介绍了在像素着色器中计算世界空间坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像素着色器,我想根据我的世界空间坐标来计算每个像素的位置.我该怎么做?我需要什么?

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.

这篇关于在像素着色器中计算世界空间坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆