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?
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.
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?
I'm using DirectX
and the pixel shader is in HLSL
. C++
as my programing language on the CPU.
Any help would be appreciated.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With