The near and far planes operation makes the depth resolution poop.
I want every object in front and in the field of view of the camera to be rendered doesn't matter the distance, until its so small it can't be seen but still rendered.
with or without the depth buffer?
if with depth buffer, how would you want to map 0 to infinity into the depth buffer? there must be some kind of range you want, because you have just 32bit (usually).
In the vertex shader after the Projection multiplication I have tried this:
float4 r = mul(Pos, Projection);
r.xy /= abs(Pos.z);
r.z = Pos.z*MAX_DEPTH;
r.w = 1.0f;
if(Pos.z<0.0f)
{
r.w = -1.0f;
}
return r;
MAX_DEPTH is (1.0f/16777216.0f) so that any float distance gets rendered...16777216 = 2^24
but it still doesn't works, well the mesh is rendered correctly but when the camera is near and you read the depth and positions pixels across the mesh they are off and this off thing increases as the pixels gets near the camera
I want to know what is happening to SV_POSITION after it leaves the vertex shader?
I know that "xyz" get divided by the abs() of "w"
no, that's not correct. xyz is divided by w (without the abs). that is actually the whole problem and why you need a near plane. you cannot divide by w<=0, it breaks the spaces. even with your abs, some w will be 0, so you divide by 0, what place on the screen should xy/0 be?
that's why you define a near plane. the near plane is not just a distance from the view origin, it is actually the distance to a little rect in the world that you draw on.
what other operations happen in that part were it gets divided by "w"?
after the vertex shader, the triangles get clipped (cut), so that z is always >= 0., because then w is always >0, then the division is made.
if someone has already a way to render the way I want can you share it too?
first, describe why you want that. what is the problem you want to solve? maybe your solution attempt is not the right one and we have a better way.
if you want a custom depth, you can have that, the pixel shader allows you to write your own depth values.
if you want infinite far view distances, you can maybe use an infinite projection matrix (check out: http://www.terathon.com/gdc07_lengyel.pdf )
if you want objects as close as 0 (and behind), then this is mathematically not really possible with projected rasterization. you can use ray tracing that can start at 0 (and even pick objects from behind), but that might not result in what you expect.