XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

pixel shader/deferred rendering - how to figure the current pixel coordinates into the target buffer?

Last post 12/08/2009 18:13 by FlyingWaffle. 2 replies.
  • 12/08/2009 12:57

    pixel shader/deferred rendering - how to figure the current pixel coordinates into the target buffer?

    Hi guys,

    I must be missing something really obvious here...

    I'm playing around with deferred rendering:

    1) I have a texture which is the size of the frame buffer and contains depth and normal information for the whole scene. That I can do just fine.

    2) In a second pass I want to compute the effect of all the lights by rendering proxy geometries for each light and writing the result into some accumulation buffer (using blending).

    When I render a proxy geometry, once I'm in my pixel shader, for the current fragment/pixel I need to look up the corresponding pixel in my depth/normal buffer (which is an input texture to my effect).
    But I'm having some trouble simply figuring out the correct texture coordinates to use to do that lookup (later on I use that lookup tex coordinates + the depth info I've read to reconstruct a world position).
    Because the input depth/normal and target accumulation buffers are "aligned", that lookup coord should simply be the current fragment position (u,v) into the target accumulation buffer... but how can I get that position (u,v)?

    What I end up doing is transforming the proxy vertex world positions to screenspace in my vertex shader (by multiplying all vertices by the world_view_proj_matrix, as usual), then rescale the x and y values of that screen position from [-1.0,1.0] to [0.0,1.0], then pass that to the pixel shader where I use the pixel-interpolated value to do the lookup in my input depth/normal buffer.
    It works ok except for the triangles in the proxy geometry that are nearly parallel to the viewing vector (very narrow and long triangles).
    For those shallow triangles in the proxy geometry it seems that because of the imprecision of the linear interpolation during rasterization, my computed coord {u',v'} are a bit different from the pipeline {u,v} coord (it looks like a small refraction effect - cute but annoying :P).

    But all this seems unecessary since, in the end, the lookup texture coord should just be the "ouput coord" of the current fragment; and that info should be visible/accessible in the pixel shader, right?

  • 12/08/2009 17:18 In reply to

    Re: pixel shader/deferred rendering - how to figure the current pixel coordinates into the target buffer?

    Looking at
    http://msdn.microsoft.com/en-us/library/bb509647(VS.85).aspx#PS

    it seems that I should be able to use the VPOS input semantic

    "VPOS - The pixel location (x,y) in screen space"

    I'll try that.

    hmm... VPOS is only available in model 3, which my card doesn't support.

    I guess I have to find a way to improve the interpolated screenspace coordinates (maybe I'm doing something wrong or I need to enable some state).
  • 12/08/2009 18:13 In reply to

    Re: pixel shader/deferred rendering - how to figure the current pixel coordinates into the target buffer?

    Answer
    Reply Quote
    According to this thread
    http://forums.xna.com/forums/p/29835/168065.aspx
    maybe I shouldn't be doing the division by w in the VS but in the PS. That could explain the distortions.


Page 1 of 1 (3 items) Previous Next