|
|
I have a situation where I want to interpolate a value from a HLSL vertex shader in screen space - not perspective-correct world space, as is done by default.
I'm rendering a 3D mesh in world space as you normally would, but I want to have some values that depend only on the screen space (post-projection) position passed to the pixel shader, and I want those values to be interpolated linearly in screen space, not world space.
Right now, the interpolation is using the w from the real vertex position to do world-space perspective correct interpolation, which is wrong for linear in screen space. It's correct at the vertices, but wrong for the interiors, which is not good enough for my situation in which I have very large tris.
I tried doing the W division myself in the vshader which makes every thing work like I want it to (since the output W becomes 1), except that then the hardware near plane clipping doesn't work right (triangles pop out as soon as they touch the plane).
I could do what I want by using the VPOS register in the pixel shader, but I'm trying to save some cycles by doing some computations in the vertex shader and passing the result to the pixel shader.
Any ideas on how I can change the nature of the interpolation?
I'm using HLSL and DX9.0c.
|