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?