Anybody has any idea about how to make an oblique projection w friendly so that the unity builtin fog will work instead of writing custom fog function for reflective surfaces? Here is my oblique projection function with a clip plane Code (CSharp): protected static void SetObliqueMatrix(ref Matrix4x4 mtx, Vector4 plane) { Vector4 q; q.x = (Sgn(plane.x) + mtx[8]) / mtx[0]; q.y = (Sgn(plane.y) + mtx[9]) / mtx[5]; q.z = -1f; q.w = (1.0f - mtx[10]) / mtx[14]; Vector4 c = plane * (2.0f / (Vector4.Dot(plane, q))); mtx[2] = c.x; mtx[6] = c.y; mtx[10] = c.z + 1.0f; mtx[14] = c.w; //mtx[0,0] = mtx[0,0] / mtx[2,3]; //mtx[1,1] = mtx[1,1] / mtx[2,3]; //mtx[2,2] = mtx[2,2] / mtx[2,3]; //mtx[2,3] = mtx[2,3] / mtx[2,3]; } DirectX documents mention that we should divide the above commented lines but while the fog works, the projection is also gets distorted.
Afaik this never worked correctly. Mostly because an oblique projection results in a ridiculous far clipping plane distance (+10k). This jacks the calculated fog factor in the shader, since it's based on clip space z-depth. A viable option is to temporarily disable fog before you execute the reflection render, then enabled it back again. The reflective surface would already be fogged, so it usually goes unnoticed.
When you divide, it should be normalized and actually it does if you add mtx[2,3]=1f at the end of the function, but then the projection is distorted. So i thought im doing the division wrong. Here is what directx docs say: The viable option you mention is not really viable and when it comes to tricks there are far better options. But i would prefer if this one works.