Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.50 KB | None | 0 0
  1. Follow these steps:
  2.  
  3. 1 - Add CineCameraCaptureComponent.h to ${UE_PATH}\Engine\Source\Runtime\CinematicCamera\Public\
  4.  
  5. 2 - Add CineCameraCaptureComponent.cpp a ${UE_PATH}\Engine\Source\Runtime\CinematicCamera\Private\
  6.  
  7. 3 - Move these functions 
  8. [CODE]
  9. float GetDesiredFocusDistance(const FVector& InLocation) const;
  10. float GetWorldToMetersScale() const;
  11. [/CODE]
  12. from private to protected
  13. in ${UE_PATH}\Engine\Source\Runtime\CinematicCamera\Public\CineCameraComponent.h
  14.  
  15. 4 - Add
  16. [CODE]PublicDependencyModuleNames.Add("CinematicCamera");[/CODE]
  17. in ${UE_PATH}\Engine\Source\Runtime\Renderer\Renderer.Build.cs
  18.  
  19. 5 - Add near the other UpdateSceneCaptureContents functions
  20. [CODE]virtual void UpdateSceneCaptureContents(class UCineCameraCaptureComponent* CaptureComponent) {} [/CODE]
  21. in ${UE_PATH}\Engine\Source\Runtime\Engine\Public\SceneInterface.h
  22.  
  23. 6 - Add near the other UpdateSceneCaptureContents functions
  24. [CODE]virtual void UpdateSceneCaptureContents(class UCineCameraCaptureComponent* CaptureComponent) override;[/CODE]
  25. in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\ScenePrivate.h
  26.  
  27. 7. Add
  28. [CODE]
  29. void SetupViewVamilyForCineCameraCapture(
  30.   FSceneViewFamily& ViewFamily,
  31.   UCineCameraCaptureComponent* CineCameraCaptureComponent,
  32.   const TArrayView<const FSceneCaptureViewInfo> Views,
  33.   float MaxViewDistance,
  34.   bool bCaptureSceneColor,
  35.   bool bIsPlanarReflection,
  36.   FPostProcessSettings* PostProcessSettings,
  37.   float PostProcessBlendWeight,
  38.   const AActor* ViewActor)
  39. {
  40.   check(!ViewFamily.GetScreenPercentageInterface());
  41.  
  42.   for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ++ViewIndex)
  43.   {
  44.     const FSceneCaptureViewInfo& SceneCaptureViewInfo = Views[ViewIndex];
  45.  
  46.     FSceneViewInitOptions ViewInitOptions;
  47.     ViewInitOptions.SetViewRectangle(SceneCaptureViewInfo.ViewRect);
  48.     ViewInitOptions.ViewFamily = &ViewFamily;
  49.     ViewInitOptions.ViewActor = ViewActor;
  50.     ViewInitOptions.ViewOrigin = SceneCaptureViewInfo.ViewLocation;
  51.     ViewInitOptions.ViewRotationMatrix = SceneCaptureViewInfo.ViewRotationMatrix;
  52.     ViewInitOptions.BackgroundColor = FLinearColor::Black;
  53.     ViewInitOptions.OverrideFarClippingPlaneDistance = MaxViewDistance;
  54.     ViewInitOptions.StereoPass = SceneCaptureViewInfo.StereoPass;
  55.     ViewInitOptions.SceneViewStateInterface = CineCameraCaptureComponent->GetViewState(ViewIndex);
  56.     ViewInitOptions.ProjectionMatrix = SceneCaptureViewInfo.ProjectionMatrix;
  57.     ViewInitOptions.LODDistanceFactor = FMath::Clamp(CineCameraCaptureComponent->LODDistanceFactor, .01f, 100.0f);
  58.  
  59.     if (bCaptureSceneColor)
  60.     {
  61.       ViewFamily.EngineShowFlags.PostProcessing = 0;
  62.       ViewInitOptions.OverlayColor = FLinearColor::Black;
  63.     }
  64.  
  65.     FSceneView* View = new FSceneView(ViewInitOptions);
  66.  
  67.     View->bIsSceneCapture = true;
  68.     // Note: this has to be set before EndFinalPostprocessSettings
  69.     View->bIsPlanarReflection = bIsPlanarReflection;
  70.  
  71.     for (auto It = CineCameraCaptureComponent->HiddenComponents.CreateConstIterator(); It; ++It)
  72.     {
  73.       // If the primitive component was destroyed, the weak pointer will return NULL.
  74.       UPrimitiveComponent* PrimitiveComponent = It->Get();
  75.       if (PrimitiveComponent)
  76.       {
  77.         View->HiddenPrimitives.Add(PrimitiveComponent->ComponentId);
  78.       }
  79.     }
  80.  
  81.     for (auto It = CineCameraCaptureComponent->HiddenActors.CreateConstIterator(); It; ++It)
  82.     {
  83.       AActor* Actor = *It;
  84.  
  85.       if (Actor)
  86.       {
  87.         TInlineComponentArray<UPrimitiveComponent*> PrimitiveComponents;
  88.         Actor->GetComponents(PrimitiveComponents);
  89.         for (int32 ComponentIndex = 0; ComponentIndex < PrimitiveComponents.Num(); ++ComponentIndex)
  90.         {
  91.           View->HiddenPrimitives.Add(PrimitiveComponents[ComponentIndex]->ComponentId);
  92.         }
  93.       }
  94.     }
  95.  
  96.     if (CineCameraCaptureComponent->PrimitiveRenderMode == ESceneCapturePrimitiveRenderMode::PRM_UseShowOnlyList)
  97.     {
  98.       View->ShowOnlyPrimitives.Emplace();
  99.  
  100.       for (auto It = CineCameraCaptureComponent->ShowOnlyComponents.CreateConstIterator(); It; ++It)
  101.       {
  102.         // If the primitive component was destroyed, the weak pointer will return NULL.
  103.         UPrimitiveComponent* PrimitiveComponent = It->Get();
  104.         if (PrimitiveComponent)
  105.         {
  106.           View->ShowOnlyPrimitives->Add(PrimitiveComponent->ComponentId);
  107.         }
  108.       }
  109.  
  110.       for (auto It = CineCameraCaptureComponent->ShowOnlyActors.CreateConstIterator(); It; ++It)
  111.       {
  112.         AActor* Actor = *It;
  113.  
  114.         if (Actor)
  115.         {
  116.           TInlineComponentArray<UPrimitiveComponent*> PrimitiveComponents;
  117.           Actor->GetComponents(PrimitiveComponents);
  118.           for (int32 ComponentIndex = 0; ComponentIndex < PrimitiveComponents.Num(); ++ComponentIndex)
  119.           {
  120.             View->ShowOnlyPrimitives->Add(PrimitiveComponents[ComponentIndex]->ComponentId);
  121.           }
  122.         }
  123.       }
  124.     }
  125.     else if (CineCameraCaptureComponent->ShowOnlyComponents.Num() > 0 || CineCameraCaptureComponent->ShowOnlyActors.Num() > 0)
  126.     {
  127.       static bool bWarned = false;
  128.  
  129.       if (!bWarned)
  130.       {
  131.         UE_LOG(LogRenderer, Log, TEXT("Scene Capture has ShowOnlyComponents or ShowOnlyActors ignored by the PrimitiveRenderMode setting! %s"), *CineCameraCaptureComponent->GetPathName());
  132.         bWarned = true;
  133.       }
  134.     }
  135.  
  136.    
  137.  
  138.     ViewFamily.Views.Add(View);
  139.  
  140.     View->StartFinalPostprocessSettings(SceneCaptureViewInfo.ViewLocation);
  141.     View->OverridePostProcessSettings(*PostProcessSettings, PostProcessBlendWeight);
  142.     View->EndFinalPostprocessSettings(ViewInitOptions);
  143.   }
  144. }
  145. [/CODE]
  146. in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
  147.  
  148. 8. Add
  149. [CODE]
  150. static FSceneRenderer* CreateSceneRendererForCineCameraCapture(
  151.   FScene* Scene,
  152.   UCineCameraCaptureComponent* CineCameraCaptureComponent,
  153.   FRenderTarget* RenderTarget,
  154.   FIntPoint RenderTargetSize,
  155.   const FMatrix& ViewRotationMatrix,
  156.   const FVector& ViewLocation,
  157.   const FMatrix& ProjectionMatrix,
  158.   float MaxViewDistance,
  159.   bool bCaptureSceneColor,
  160.   FPostProcessSettings* PostProcessSettings,
  161.   float PostProcessBlendWeight,
  162.   const AActor* ViewActor)
  163. {
  164.   FSceneCaptureViewInfo SceneCaptureViewInfo;
  165.   SceneCaptureViewInfo.ViewRotationMatrix = ViewRotationMatrix;
  166.   SceneCaptureViewInfo.ViewLocation = ViewLocation;
  167.   SceneCaptureViewInfo.ProjectionMatrix = ProjectionMatrix;
  168.   SceneCaptureViewInfo.StereoPass = EStereoscopicPass::eSSP_FULL;
  169.   SceneCaptureViewInfo.ViewRect = FIntRect(0, 0, RenderTargetSize.X, RenderTargetSize.Y);
  170.  
  171.   FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
  172.     RenderTarget,
  173.     Scene,
  174.     CineCameraCaptureComponent->ShowFlags)
  175.     .SetResolveScene(!bCaptureSceneColor)
  176.     .SetRealtimeUpdate(CineCameraCaptureComponent->bCaptureEveryFrame || CineCameraCaptureComponent->bAlwaysPersistRenderingState));
  177.  
  178.  
  179.   SetupViewVamilyForCineCameraCapture(
  180.     ViewFamily,
  181.     CineCameraCaptureComponent,
  182.     { SceneCaptureViewInfo },
  183.     MaxViewDistance,
  184.     bCaptureSceneColor,
  185.     /* bIsPlanarReflection = */ false,
  186.     PostProcessSettings,
  187.     PostProcessBlendWeight,
  188.     ViewActor);
  189.  
  190.   // Screen percentage is still not supported in scene capture.
  191.   ViewFamily.EngineShowFlags.ScreenPercentage = false;
  192.   ViewFamily.SetScreenPercentageInterface(new FLegacyScreenPercentageDriver(
  193.     ViewFamily, /* GlobalResolutionFraction = */ 1.0f, /* AllowPostProcessSettingsScreenPercentage = */ false));
  194.  
  195.   return FSceneRenderer::CreateSceneRenderer(&ViewFamily, nullptr);
  196. }
  197. [/CODE]
  198. in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
  199.  
  200. 9.Add
  201. [CODE]
  202. static FSceneRenderer* CreateSceneRendererForCineCameraCapture(
  203.   FScene* Scene,
  204.   UCineCameraCaptureComponent* CineCameraCaptureComponent,
  205.   FRenderTarget* RenderTarget,
  206.   FIntPoint RenderTargetSize,
  207.   const FMatrix& ViewRotationMatrix,
  208.   const FVector& ViewLocation,
  209.   const FMatrix& ProjectionMatrix,
  210.   float MaxViewDistance,
  211.   bool bCaptureSceneColor,
  212.   FPostProcessSettings* PostProcessSettings,
  213.   float PostProcessBlendWeight,
  214.   const AActor* ViewActor)
  215. {
  216.   FSceneCaptureViewInfo SceneCaptureViewInfo;
  217.   SceneCaptureViewInfo.ViewRotationMatrix = ViewRotationMatrix;
  218.   SceneCaptureViewInfo.ViewLocation = ViewLocation;
  219.   SceneCaptureViewInfo.ProjectionMatrix = ProjectionMatrix;
  220.   SceneCaptureViewInfo.StereoPass = EStereoscopicPass::eSSP_FULL;
  221.   SceneCaptureViewInfo.ViewRect = FIntRect(0, 0, RenderTargetSize.X, RenderTargetSize.Y);
  222.  
  223.   FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
  224.     RenderTarget,
  225.     Scene,
  226.     CineCameraCaptureComponent->ShowFlags)
  227.     .SetResolveScene(!bCaptureSceneColor)
  228.     .SetRealtimeUpdate(CineCameraCaptureComponent->bCaptureEveryFrame || CineCameraCaptureComponent->bAlwaysPersistRenderingState));
  229.  
  230.  
  231.   SetupViewVamilyForCineCameraCapture(
  232.     ViewFamily,
  233.     CineCameraCaptureComponent,
  234.     { SceneCaptureViewInfo },
  235.     MaxViewDistance,
  236.     bCaptureSceneColor,
  237.     /* bIsPlanarReflection = */ false,
  238.     PostProcessSettings,
  239.     PostProcessBlendWeight,
  240.     ViewActor);
  241.  
  242.   // Screen percentage is still not supported in scene capture.
  243.   ViewFamily.EngineShowFlags.ScreenPercentage = false;
  244.   ViewFamily.SetScreenPercentageInterface(new FLegacyScreenPercentageDriver(
  245.     ViewFamily, /* GlobalResolutionFraction = */ 1.0f, /* AllowPostProcessSettingsScreenPercentage = */ false));
  246.  
  247.   return FSceneRenderer::CreateSceneRenderer(&ViewFamily, nullptr);
  248. }
  249. [/CODE]
  250. in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
  251.  
  252. 10. Add
  253. [CODE]
  254. void FScene::UpdateSceneCaptureContents(UCineCameraCaptureComponent* CaptureComponent)
  255. {
  256.  check(CaptureComponent);
  257.  if (CaptureComponent->TextureTarget)
  258.  {
  259.  if (!CaptureComponent->bCaptureEveryFrame && CaptureComponent->bAlwaysPersistRenderingState)
  260.  {
  261.  // We assume the world is not paused since the CaptureScene() has manually been called.
  262.  EnsureMotionBlurCacheIsUpToDate(/* bWorldIsPaused = */ false);
  263.  }
  264.  FTransform Transform = CaptureComponent->GetComponentToWorld();
  265.  FVector ViewLocation = Transform.GetTranslation();
  266.  // Remove the translation from Transform because we only need rotation.
  267.  Transform.SetTranslation(FVector::ZeroVector);
  268.  Transform.SetScale3D(FVector::OneVector);
  269.  FMatrix ViewRotationMatrix = Transform.ToInverseMatrixWithScale();
  270.  // swap axis st. x=z,y=x,z=y (unreal coord space) so that z is up
  271.  ViewRotationMatrix = ViewRotationMatrix * FMatrix(
  272.  FPlane(0, 0, 1, 0),
  273.  FPlane(1, 0, 0, 0),
  274.  FPlane(0, 1, 0, 0),
  275.  FPlane(0, 0, 0, 1));
  276.  const float FOV = CaptureComponent->FieldOfView * (float)PI / 360.0f;
  277.  FIntPoint CaptureSize(CaptureComponent->TextureTarget->GetSurfaceWidth(), CaptureComponent->TextureTarget->GetSurfaceHeight());
  278.  FMatrix ProjectionMatrix;
  279.  if (CaptureComponent->bUseCustomProjectionMatrix)
  280.  {
  281.  ProjectionMatrix = CaptureComponent->CustomProjectionMatrix;
  282.  }
  283.  else
  284.  {
  285.  BuildProjectionMatrix(CaptureSize, CaptureComponent->ProjectionType, FOV, CaptureComponent->OrthoWidth, ProjectionMatrix);
  286.  }
  287.  const bool bUseSceneColorTexture = CaptureComponent->CaptureSource != SCS_FinalColorLDR;
  288.  FSceneRenderer* SceneRenderer = CreateSceneRendererForCineCameraCapture(
  289.  this,
  290.  CaptureComponent,
  291.  CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource(),
  292.  CaptureSize,
  293.  ViewRotationMatrix,
  294.  ViewLocation,
  295.  ProjectionMatrix,
  296.  CaptureComponent->MaxViewDistanceOverride,
  297.  bUseSceneColorTexture,
  298.  &CaptureComponent->CameraLensPostProcessSettings,
  299.  CaptureComponent->PostProcessBlendWeight,
  300.  CaptureComponent->GetViewOwner());
  301.  SceneRenderer->ViewFamily.SceneCaptureSource = CaptureComponent->CaptureSource;
  302.  SceneRenderer->ViewFamily.SceneCaptureCompositeMode = CaptureComponent->CompositeMode;
  303.  {
  304.  FPlane ClipPlane = FPlane(CaptureComponent->ClipPlaneBase, CaptureComponent->ClipPlaneNormal.GetSafeNormal());
  305.  for (FSceneView& View : SceneRenderer->Views)
  306.  {
  307.  View.bCameraCut = CaptureComponent->bCameraCutThisFrame;
  308.  if (CaptureComponent->bEnableClipPlane)
  309.  {
  310.  View.GlobalClippingPlane = ClipPlane;
  311.  // Jitter can't be removed completely due to the clipping plane
  312.  View.bAllowTemporalJitter = false;
  313.  }
  314.  }
  315.  }
  316.  // Reset scene capture's camera cut.
  317.  CaptureComponent->bCameraCutThisFrame = false;
  318.  FTextureRenderTargetResource* TextureRenderTarget = CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource();
  319.  FString EventName;
  320.  if (!CaptureComponent->ProfilingEventName.IsEmpty())
  321.  {
  322.  EventName = CaptureComponent->ProfilingEventName;
  323.  }
  324.  else if (CaptureComponent->GetOwner())
  325.  {
  326.  CaptureComponent->GetOwner()->GetFName().ToString(EventName);
  327.  }
  328.  
  329.  ENQUEUE_RENDER_COMMAND(CaptureCommand)(
  330.  [SceneRenderer, TextureRenderTarget, EventName](FRHICommandListImmediate& RHICmdList)
  331.  {
  332.  UpdateSceneCaptureContent_RenderThread(RHICmdList, SceneRenderer, TextureRenderTarget, TextureRenderTarget, EventName, FResolveParams());
  333.  }
  334.  );
  335.  }
  336. }
  337. [/CODE]
  338. in ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
  339.  
  340. 11. Add
  341. [CODE]UCineCameraCaptureComponent::UpdateDeferredCaptures(Scene);[/CODE]
  342. inside the function void FRendererModule::BeginRenderingViewFamily(FCanvas* Canvas, FSceneViewFamily* ViewFamily) after the line USceneCaptureComponent::UpdateDeferredCaptures(Scene); 
  343. in  ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneRendering.cpp
  344.  
  345. 12. Add
  346. [CODE]
  347. #include "CineCameraCaptureComponent.h"
  348. [/CODE]
  349. in the includes section of ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneRendering.cpp and ${UE_PATH}\Engine\Source\Runtime\Renderer\Private\SceneCaptureRendering.cpp
  350.  
  351. Compile the Engine from source.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement