Projection Matrix in GameViewportClient::Draw()

Hi,

Here is what I have tried so far. I have overloaded the method Draw() of the class UGameViewportClient and selected my new class in the project settings to make sure that my new class is applied to the editor viewport.

Within my virtual void Draw(FViewport* Viewport, FCanvas* SceneCanvas) override; method, I essentially have a part that only modifies the perspective projection matrix as follows:

FSceneView* SceneView = LocalPlayer->CalcsceneView(&ViewFamily, ViewLocation, ViewRotation, LocalPlayer->ViewportClient->Viewport);

SceneView->ViewMatrices.ProjMatrix = MyOwnStaticMatrix;

And here comes the weird behaviour:
SceneView->ViewMatrices.ProjMatrix is correctly modified ONLY if I activate the Temporal AA in the project settings.

If I go either with no AA or FXAA, I then notice that SceneView->ViewMatrices.ProjMatrix is overwritten somewhere else in the engine. This is easily demonstrated by putting a breakpoint BEFORE SceneView->ViewMatrices.ProjMatrix = MyOwnStaticMatrix; and AFTER SceneView->ViewMatrices.ProjMatrix = MyOwnStaticMatrix; It clearly shows different values for SceneView->ViewMatrices.ProjMatrix.

If I go with TAA, then SceneView->ViewMatrices.ProjMatrix has the correct value BEFORE and AFTER SceneView->ViewMatrices.ProjMatrix = MyOwnStaticMatrix;

I have a bit of a hard time to understand why the overloading of Draw() only works with TAA.
Do you have any clue of a parameter somewhere in the editor which might cause this or if I’m doing something wrong here ?
If that’s a normal and expected behaviour I would like to try to understand why FXAA (or no AA !!) can’t work with my own projection matrix (I would have expected to have TAA not working actually)…

Thanks,

.

Hi ,

I’ve had a look through the code this morning and I had the same estimate as you, that it would be the temporal AA to go wrong. The reason it actually seems to work is because during the temporal jitter the code rebuilds the view-projection matrices (see the end of FSceneRenderer::PreVisibilityFrameSetup()) which then propagates your changes through the system. With TAA disabled it misses this step so it’s not that your data is overridden, it’s just too late for the projection matrix to be changed.

The simplest fix I can see is to either run similar code to the Temporal AA after your change:

SceneView->ViewProjectionMatrix = SceneView->ViewMatrices.ViewMatrix * SceneView->ViewMatrices.ProjMatrix;
SceneView->InvViewProjectionMatrix = SceneView->ViewMatrices.GetInvProjMatrix() * SceneView->InvViewMatrix;

if (SceneView->ViewMatrices.PreViewTranslation.IsNearlyZero())
{
	SceneView->ViewMatrices.TranslatedViewProjectionMatrix = SceneView->ViewProjectionMatrix;
	SceneView->ViewMatrices.InvTranslatedViewProjectionMatrix = SceneView->InvViewProjectionMatrix;
}
else
{
	SceneView->ViewMatrices.TranslatedViewProjectionMatrix = SceneView->ViewMatrices.TranslatedViewMatrix * SceneView->ViewMatrices.ProjMatrix;
	SceneView->ViewMatrices.InvTranslatedViewProjectionMatrix = SceneView->ViewMatrices.GetInvProjMatrix() * SceneView->ViewMatrices.TranslatedViewMatrix.GetTransposed();
}

Or alternatively you may be able to get away with just:

SceneView->UpdateViewMatrix();

Let me know how you get on,

Hi ,

This is… AWESOME !
That is exactly what my problem was.

I have tested your two solutions, and they both work !!

Thanks a million for that !

Cheers,

.