Camera Projection Matrix Perturbation


I need to make a sub pixel camera perturbation in projection matrix for doing accumulative anti aliasing, and I do something like this for that::

    projMatrix.setRowFromFloats(0, projMatrix.getRow(0).x, projMatrix.getRow(0).y, offsetX, projMatrix.getRow(0).w);
    projMatrix.setRowFromFloats(1, projMatrix.getRow(1).x, projMatrix.getRow(1).y, offsetY, projMatrix.getRow(1).w);

But I don’t really see the expected jitter in the scene. is the above way correct?

Hi @spidersharma

The last row is the translation. You can modify the X and Y values to tranlaste in clip space.
Like in this PG:

Hi @Cedric,
Thanks for your reply!

For a perspective matrix , for a perturbation, if I do an offset in the left/bottom parameters by a small number, I get a matrix which has first two entries of the third column as non zero.

basically for a symmetric frustum
right + left = 0
top + bottom = 0,
But if I add some jitter in left/bottom values, I will get right + left = 2 * offset.

I have done similar changes in three.js , and pure webgl, and it shows me the jitter, But not in babylon.

Your example does show the jitter, But I wonder why my changes dosen’t in the same way.



Actually, if I do the folowing, I get the desired behaviour

(projMatrix as any).m[8] = offsetX;
(projMatrix as any).m[9] = offsetY;

1 Like