keijiro/DepthInverseProjection

Double multiplied by far clip plane

Closed this issue · 3 comments

float3 rayPers = mul(unity_CameraInvProjection, vpos) * far;

Shouldn't the far clip plane already be accounted for by the inverse projection? Why is the ray multiplied by far again?

No. vpos is on the near clip plane in the clip space, then mul(unity_CameraInvProjection, vpos) gives the positions of the near clip plane vertices. We can get the far vertices of the view frustum by multiplying it with far.

I'm closing this issue. Please feel free to reopen for further questions.

That doesn't make sense to me, why would near * far = far?

I haven't done the math yet, but my hunch is that ray should be divided by W (after mul), but W is currently ignored. I check the math and report back, no need to reopen.