Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Follow these steps:
- 1 - Add CineCameraCaptureComponent.h to ${UE_PATH}\Engine\Source\Runtime\CinematicCamera\Public\
- 2 - Add CineCameraCaptureComponent.cpp a ${UE_PATH}\Engine\Source\Runtime\CinematicCamera\Private\
- 3 - Move these functions
- [CODE]
- float GetDesiredFocusDistance(const FVector& InLocation) const;
- float GetWorldToMetersScale() const;
- [/CODE]
- from private to protected
- in ${UE_PATH}\Engine\Source\Runtime\CinematicCamera\Public\CineCameraComponent.h
- 4 - Add
- [CODE]PublicDependencyModuleNames.Add("CinematicCamera");[/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Renderer.Build.cs
- 5 - Add near the other UpdateSceneCaptureContents functions
- [CODE]virtual void UpdateSceneCaptureContents(class UCineCameraCaptureComponent* CaptureComponent) {} [/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Engine\Public\SceneInterface.h
- 6 - Add near the other UpdateSceneCaptureContents functions
- [CODE]virtual void UpdateSceneCaptureContents(class UCineCameraCaptureComponent* CaptureComponent) override;[/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\ScenePrivate.h
- 7. Add
- [CODE]
- void SetupViewVamilyForCineCameraCapture(
- FSceneViewFamily& ViewFamily,
- UCineCameraCaptureComponent* CineCameraCaptureComponent,
- const TArrayView<const FSceneCaptureViewInfo> Views,
- float MaxViewDistance,
- bool bCaptureSceneColor,
- bool bIsPlanarReflection,
- FPostProcessSettings* PostProcessSettings,
- float PostProcessBlendWeight,
- const AActor* ViewActor)
- {
- check(!ViewFamily.GetScreenPercentageInterface());
- for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ++ViewIndex)
- {
- const FSceneCaptureViewInfo& SceneCaptureViewInfo = Views[ViewIndex];
- FSceneViewInitOptions ViewInitOptions;
- ViewInitOptions.SetViewRectangle(SceneCaptureViewInfo.ViewRect);
- ViewInitOptions.ViewFamily = &ViewFamily;
- ViewInitOptions.ViewActor = ViewActor;
- ViewInitOptions.ViewOrigin = SceneCaptureViewInfo.ViewLocation;
- ViewInitOptions.ViewRotationMatrix = SceneCaptureViewInfo.ViewRotationMatrix;
- ViewInitOptions.BackgroundColor = FLinearColor::Black;
- ViewInitOptions.OverrideFarClippingPlaneDistance = MaxViewDistance;
- ViewInitOptions.StereoPass = SceneCaptureViewInfo.StereoPass;
- ViewInitOptions.SceneViewStateInterface = CineCameraCaptureComponent->GetViewState(ViewIndex);
- ViewInitOptions.ProjectionMatrix = SceneCaptureViewInfo.ProjectionMatrix;
- ViewInitOptions.LODDistanceFactor = FMath::Clamp(CineCameraCaptureComponent->LODDistanceFactor, .01f, 100.0f);
- if (bCaptureSceneColor)
- {
- ViewFamily.EngineShowFlags.PostProcessing = 0;
- ViewInitOptions.OverlayColor = FLinearColor::Black;
- }
- FSceneView* View = new FSceneView(ViewInitOptions);
- View->bIsSceneCapture = true;
- // Note: this has to be set before EndFinalPostprocessSettings
- View->bIsPlanarReflection = bIsPlanarReflection;
- for (auto It = CineCameraCaptureComponent->HiddenComponents.CreateConstIterator(); It; ++It)
- {
- // If the primitive component was destroyed, the weak pointer will return NULL.
- UPrimitiveComponent* PrimitiveComponent = It->Get();
- if (PrimitiveComponent)
- {
- View->HiddenPrimitives.Add(PrimitiveComponent->ComponentId);
- }
- }
- for (auto It = CineCameraCaptureComponent->HiddenActors.CreateConstIterator(); It; ++It)
- {
- AActor* Actor = *It;
- if (Actor)
- {
- TInlineComponentArray<UPrimitiveComponent*> PrimitiveComponents;
- Actor->GetComponents(PrimitiveComponents);
- for (int32 ComponentIndex = 0; ComponentIndex < PrimitiveComponents.Num(); ++ComponentIndex)
- {
- View->HiddenPrimitives.Add(PrimitiveComponents[ComponentIndex]->ComponentId);
- }
- }
- }
- if (CineCameraCaptureComponent->PrimitiveRenderMode == ESceneCapturePrimitiveRenderMode::PRM_UseShowOnlyList)
- {
- View->ShowOnlyPrimitives.Emplace();
- for (auto It = CineCameraCaptureComponent->ShowOnlyComponents.CreateConstIterator(); It; ++It)
- {
- // If the primitive component was destroyed, the weak pointer will return NULL.
- UPrimitiveComponent* PrimitiveComponent = It->Get();
- if (PrimitiveComponent)
- {
- View->ShowOnlyPrimitives->Add(PrimitiveComponent->ComponentId);
- }
- }
- for (auto It = CineCameraCaptureComponent->ShowOnlyActors.CreateConstIterator(); It; ++It)
- {
- AActor* Actor = *It;
- if (Actor)
- {
- TInlineComponentArray<UPrimitiveComponent*> PrimitiveComponents;
- Actor->GetComponents(PrimitiveComponents);
- for (int32 ComponentIndex = 0; ComponentIndex < PrimitiveComponents.Num(); ++ComponentIndex)
- {
- View->ShowOnlyPrimitives->Add(PrimitiveComponents[ComponentIndex]->ComponentId);
- }
- }
- }
- }
- else if (CineCameraCaptureComponent->ShowOnlyComponents.Num() > 0 || CineCameraCaptureComponent->ShowOnlyActors.Num() > 0)
- {
- static bool bWarned = false;
- if (!bWarned)
- {
- UE_LOG(LogRenderer, Log, TEXT("Scene Capture has ShowOnlyComponents or ShowOnlyActors ignored by the PrimitiveRenderMode setting! %s"), *CineCameraCaptureComponent->GetPathName());
- bWarned = true;
- }
- }
- ViewFamily.Views.Add(View);
- View->StartFinalPostprocessSettings(SceneCaptureViewInfo.ViewLocation);
- View->OverridePostProcessSettings(*PostProcessSettings, PostProcessBlendWeight);
- View->EndFinalPostprocessSettings(ViewInitOptions);
- }
- }
- [/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
- 8. Add
- [CODE]
- static FSceneRenderer* CreateSceneRendererForCineCameraCapture(
- FScene* Scene,
- UCineCameraCaptureComponent* CineCameraCaptureComponent,
- FRenderTarget* RenderTarget,
- FIntPoint RenderTargetSize,
- const FMatrix& ViewRotationMatrix,
- const FVector& ViewLocation,
- const FMatrix& ProjectionMatrix,
- float MaxViewDistance,
- bool bCaptureSceneColor,
- FPostProcessSettings* PostProcessSettings,
- float PostProcessBlendWeight,
- const AActor* ViewActor)
- {
- FSceneCaptureViewInfo SceneCaptureViewInfo;
- SceneCaptureViewInfo.ViewRotationMatrix = ViewRotationMatrix;
- SceneCaptureViewInfo.ViewLocation = ViewLocation;
- SceneCaptureViewInfo.ProjectionMatrix = ProjectionMatrix;
- SceneCaptureViewInfo.StereoPass = EStereoscopicPass::eSSP_FULL;
- SceneCaptureViewInfo.ViewRect = FIntRect(0, 0, RenderTargetSize.X, RenderTargetSize.Y);
- FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
- RenderTarget,
- Scene,
- CineCameraCaptureComponent->ShowFlags)
- .SetResolveScene(!bCaptureSceneColor)
- .SetRealtimeUpdate(CineCameraCaptureComponent->bCaptureEveryFrame || CineCameraCaptureComponent->bAlwaysPersistRenderingState));
- SetupViewVamilyForCineCameraCapture(
- ViewFamily,
- CineCameraCaptureComponent,
- { SceneCaptureViewInfo },
- MaxViewDistance,
- bCaptureSceneColor,
- /* bIsPlanarReflection = */ false,
- PostProcessSettings,
- PostProcessBlendWeight,
- ViewActor);
- // Screen percentage is still not supported in scene capture.
- ViewFamily.EngineShowFlags.ScreenPercentage = false;
- ViewFamily.SetScreenPercentageInterface(new FLegacyScreenPercentageDriver(
- ViewFamily, /* GlobalResolutionFraction = */ 1.0f, /* AllowPostProcessSettingsScreenPercentage = */ false));
- return FSceneRenderer::CreateSceneRenderer(&ViewFamily, nullptr);
- }
- [/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
- 9.Add
- [CODE]
- static FSceneRenderer* CreateSceneRendererForCineCameraCapture(
- FScene* Scene,
- UCineCameraCaptureComponent* CineCameraCaptureComponent,
- FRenderTarget* RenderTarget,
- FIntPoint RenderTargetSize,
- const FMatrix& ViewRotationMatrix,
- const FVector& ViewLocation,
- const FMatrix& ProjectionMatrix,
- float MaxViewDistance,
- bool bCaptureSceneColor,
- FPostProcessSettings* PostProcessSettings,
- float PostProcessBlendWeight,
- const AActor* ViewActor)
- {
- FSceneCaptureViewInfo SceneCaptureViewInfo;
- SceneCaptureViewInfo.ViewRotationMatrix = ViewRotationMatrix;
- SceneCaptureViewInfo.ViewLocation = ViewLocation;
- SceneCaptureViewInfo.ProjectionMatrix = ProjectionMatrix;
- SceneCaptureViewInfo.StereoPass = EStereoscopicPass::eSSP_FULL;
- SceneCaptureViewInfo.ViewRect = FIntRect(0, 0, RenderTargetSize.X, RenderTargetSize.Y);
- FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
- RenderTarget,
- Scene,
- CineCameraCaptureComponent->ShowFlags)
- .SetResolveScene(!bCaptureSceneColor)
- .SetRealtimeUpdate(CineCameraCaptureComponent->bCaptureEveryFrame || CineCameraCaptureComponent->bAlwaysPersistRenderingState));
- SetupViewVamilyForCineCameraCapture(
- ViewFamily,
- CineCameraCaptureComponent,
- { SceneCaptureViewInfo },
- MaxViewDistance,
- bCaptureSceneColor,
- /* bIsPlanarReflection = */ false,
- PostProcessSettings,
- PostProcessBlendWeight,
- ViewActor);
- // Screen percentage is still not supported in scene capture.
- ViewFamily.EngineShowFlags.ScreenPercentage = false;
- ViewFamily.SetScreenPercentageInterface(new FLegacyScreenPercentageDriver(
- ViewFamily, /* GlobalResolutionFraction = */ 1.0f, /* AllowPostProcessSettingsScreenPercentage = */ false));
- return FSceneRenderer::CreateSceneRenderer(&ViewFamily, nullptr);
- }
- [/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
- 10. Add
- [CODE]
- void FScene::UpdateSceneCaptureContents(UCineCameraCaptureComponent* CaptureComponent)
- {
- check(CaptureComponent);
- if (CaptureComponent->TextureTarget)
- {
- if (!CaptureComponent->bCaptureEveryFrame && CaptureComponent->bAlwaysPersistRenderingState)
- {
- // We assume the world is not paused since the CaptureScene() has manually been called.
- EnsureMotionBlurCacheIsUpToDate(/* bWorldIsPaused = */ false);
- }
- FTransform Transform = CaptureComponent->GetComponentToWorld();
- FVector ViewLocation = Transform.GetTranslation();
- // Remove the translation from Transform because we only need rotation.
- Transform.SetTranslation(FVector::ZeroVector);
- Transform.SetScale3D(FVector::OneVector);
- FMatrix ViewRotationMatrix = Transform.ToInverseMatrixWithScale();
- // swap axis st. x=z,y=x,z=y (unreal coord space) so that z is up
- ViewRotationMatrix = ViewRotationMatrix * FMatrix(
- FPlane(0, 0, 1, 0),
- FPlane(1, 0, 0, 0),
- FPlane(0, 1, 0, 0),
- FPlane(0, 0, 0, 1));
- const float FOV = CaptureComponent->FieldOfView * (float)PI / 360.0f;
- FIntPoint CaptureSize(CaptureComponent->TextureTarget->GetSurfaceWidth(), CaptureComponent->TextureTarget->GetSurfaceHeight());
- FMatrix ProjectionMatrix;
- if (CaptureComponent->bUseCustomProjectionMatrix)
- {
- ProjectionMatrix = CaptureComponent->CustomProjectionMatrix;
- }
- else
- {
- BuildProjectionMatrix(CaptureSize, CaptureComponent->ProjectionType, FOV, CaptureComponent->OrthoWidth, ProjectionMatrix);
- }
- const bool bUseSceneColorTexture = CaptureComponent->CaptureSource != SCS_FinalColorLDR;
- FSceneRenderer* SceneRenderer = CreateSceneRendererForCineCameraCapture(
- this,
- CaptureComponent,
- CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource(),
- CaptureSize,
- ViewRotationMatrix,
- ViewLocation,
- ProjectionMatrix,
- CaptureComponent->MaxViewDistanceOverride,
- bUseSceneColorTexture,
- &CaptureComponent->CameraLensPostProcessSettings,
- CaptureComponent->PostProcessBlendWeight,
- CaptureComponent->GetViewOwner());
- SceneRenderer->ViewFamily.SceneCaptureSource = CaptureComponent->CaptureSource;
- SceneRenderer->ViewFamily.SceneCaptureCompositeMode = CaptureComponent->CompositeMode;
- {
- FPlane ClipPlane = FPlane(CaptureComponent->ClipPlaneBase, CaptureComponent->ClipPlaneNormal.GetSafeNormal());
- for (FSceneView& View : SceneRenderer->Views)
- {
- View.bCameraCut = CaptureComponent->bCameraCutThisFrame;
- if (CaptureComponent->bEnableClipPlane)
- {
- View.GlobalClippingPlane = ClipPlane;
- // Jitter can't be removed completely due to the clipping plane
- View.bAllowTemporalJitter = false;
- }
- }
- }
- // Reset scene capture's camera cut.
- CaptureComponent->bCameraCutThisFrame = false;
- FTextureRenderTargetResource* TextureRenderTarget = CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource();
- FString EventName;
- if (!CaptureComponent->ProfilingEventName.IsEmpty())
- {
- EventName = CaptureComponent->ProfilingEventName;
- }
- else if (CaptureComponent->GetOwner())
- {
- CaptureComponent->GetOwner()->GetFName().ToString(EventName);
- }
- ENQUEUE_RENDER_COMMAND(CaptureCommand)(
- [SceneRenderer, TextureRenderTarget, EventName](FRHICommandListImmediate& RHICmdList)
- {
- UpdateSceneCaptureContent_RenderThread(RHICmdList, SceneRenderer, TextureRenderTarget, TextureRenderTarget, EventName, FResolveParams());
- }
- );
- }
- }
- [/CODE]
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
- 11. Add
- [CODE]UCineCameraCaptureComponent::UpdateDeferredCaptures(Scene);[/CODE]
- inside the function void FRendererModule::BeginRenderingViewFamily(FCanvas* Canvas, FSceneViewFamily* ViewFamily) after the line USceneCaptureComponent::UpdateDeferredCaptures(Scene);
- in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneRendering.cpp
- 12. Add
- [CODE]
- #include "CineCameraCaptureComponent.h"
- [/CODE]
- in the includes section of ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneRendering.cpp and ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
- Compile the Engine from source.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement