Computing global spatial coordinates in a pixel shader

I have a pixel shader, and I want to calculate the position of each pixel according to my world cosmic coordinates. How can I do it? What I need?

I have a ps_input structure that has a position of float4: SV_POSITION . I suppose this is important, but the values โ€‹โ€‹stored inside seem ridiculous.

I canโ€™t understand what they are related to. For example, if a pixel is 2d, then why does it have a w component or z component in this regard?

I am using DirectX , and the pixel shader is in HLSL . C++ as my programming language on the CPU.

Any help would be appreciated.

+4
source share
1 answer

If I remember this correctly, SV_POSITION will only be 0-> W 0-> H, so it describes where it is on the screen. this site contains additional information: http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx

To get a pixel in world space, you convert your pixel back to worldlspace. it's a little complicated with math and everyone (I think it is!) but this article should help you! http://jcoluna.wordpress.com/2011/01/27/reconstructing-view-space-position-from-depth/

another wise pixel search in view space. I know you want a worldspace, but converting everything to a viewspace is probably faster.

+4
source

Source: https://habr.com/ru/post/1438575/


All Articles