Hi,
I am trying to use the scene’s view projection matrix in a compute shader. I pass it over to HLSL from C++ where I get it with this code:
FMatrix UComputeShaderStarter::FindViewProjectionMatrix()
{
ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (LocalPlayer != nullptr && LocalPlayer->ViewportClient != nullptr && LocalPlayer->ViewportClient->Viewport)
{
FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
LocalPlayer->ViewportClient->Viewport,
GetWorld()->Scene,
LocalPlayer->ViewportClient->EngineShowFlags)
.SetRealtimeUpdate(true));FVector ViewLocation; FRotator ViewRotation; FSceneView* SceneView = LocalPlayer->CalcSceneView(&ViewFamily, ViewLocation, ViewRotation, LocalPlayer->ViewportClient->Viewport); if (SceneView != nullptr) { return SceneView->ViewMatrices.GetViewProjectionMatrix(); }
}
return FMatrix::Identity;
}
I am unsure how to verify if this gives me the correct result. As an alternative, I have read that I could use the View.WorldToClip function. I do not seem to be able to access it from HLSL though, getting this error:
error X3004: undeclared identifier ‘View’
Is it not possible to use this in a compute shader?
To summarize: What is the easiest way to get the view projection matrix in HLSL and how can I verify that it is correct?