raycasting question
I have a texture containing the world positions represented by every
pixel that is rendered. By rendering a fullscreen quad, for each pixel
that is rendered I extract the world position and I want to take 20
samples into the screen, thereby determining 20 world positions from
the camera to the rendered pixel, so that I can test those positions
against a shadow map. This is to hopefully achieve a basic volume
lighting effect.
I get the world position:
float4 worldPos = texDepth.Sample(g_samPoint, input.texcoord);
and multiply by the view projection matrix:
worldPos = mul(float4(worldPos.xyz, 1.0f), g_viewProjectionMatrix);
If I started off with worldPos in viewspace (screen space?) and wanted
to go back to world space, I would do this:
worldPos = mul(worldPos, g_inverseViewProjectionMatrix);
worldPos.xyz /= worldPos.w;
(Let me know if I am wrong about the above)
But if I want to calculate the world position using a different depth,
let's say a depth that is halfway between the camera and the pixel's
world position, how do I do this?
worldPos = mul(worldPos.xy, worldPos.z, worldPos.w*0.5f,
g_inverseViewProjectionMatrix);
worldPos.xyz /= worldPos.w;
or is it
worldPos = mul(worldPos.xy, worldPos.z * 0.5f, worldPos.w
g_inverseViewProjectionMatrix);
worldPos.xyz /= worldPos.w;
I can't seem to find the correct formula. Either I've hit upon the
correct formula and the rest of my shader is wrong, or the initial
calculation is wrong.
Is anybody able to help?
Thanks,
Peter
date: Sun, 29 Jun 2008 22:55:33 -0700 (PDT)
author: unknown