shader coding: calculate screen coordinates of fragment
- by Jay
Good morning,
I'm new to shader coding and trying to implement some visual effects code in shaders using billboards. (Yes, I couldn't have picked anything harder to start with, but I'm lucky that way)
Setup:
I have rendered the full screen z depth to an array of floats in a previous pass.
In the fragment shader I need the scene depth where the rendered fragment is displayed (to see if it's occluded). I can use tex2d() to get the depth value if I have the screen coordinates of the point being rendered in the fragment shader.
Question:
In the fragment shader how do you calculate the screen coordinates of the pixel (in the range 0-1.0)?
Is the position passed to the fragment shader a pixel offset? If so, I guess it would be:
float2( position.x / screen-width, position.y / screen-height )
Thanks for any help/