130 friend class FPixelReader2;
137 void SetImageSize(uint32 Width, uint32 Height);
141 return CaptureComponent2D;
154 UFUNCTION(BlueprintCallable)
155 void EnablePostProcessingEffects(
bool Enable = true)
157 bEnablePostProcessingEffects = Enable;
160 UFUNCTION(BlueprintCallable)
161 bool ArePostProcessingEffectsEnabled()
const
163 return bEnablePostProcessingEffects;
169 UFUNCTION(BlueprintCallable)
170 void SetDLSSUpscale(
bool Enable,
float ScreenPercentage)
172 bEnableDLSSUpscale = Enable;
173 DLSSScreenPercentage = FMath::Clamp(ScreenPercentage, 25.0f, 100.0f);
176 UFUNCTION(BlueprintCallable)
177 bool IsDLSSUpscaleEnabled()
const
179 return bEnableDLSSUpscale;
182 UFUNCTION(BlueprintCallable)
183 void SetUseRayTracing(
bool Enable);
185 UFUNCTION(BlueprintCallable)
186 bool GetUseRayTracing()
const
188 return bUseRayTracing;
194 static bool ResolveCameraRayTracing(
bool bSensorEnabled,
bool bRequired);
199 UFUNCTION(BlueprintCallable)
200 void SetShowOnlyTags(const FString &CommaSeparatedLabels)
202 ShowOnlyFilter.SetShowOnlyTags(CommaSeparatedLabels);
208 UFUNCTION(BlueprintCallable)
209 void SetShadowCatcherTags(const FString &CommaSeparatedLabels)
211 ShowOnlyFilter.SetShadowCatcherTags(CommaSeparatedLabels);
215 UFUNCTION(BlueprintCallable)
216 void SetShowOnlyActorIds(const FString &CommaSeparatedIds)
218 ShowOnlyFilter.SetShowOnlyActorIds(CommaSeparatedIds);
221 UFUNCTION(BlueprintCallable)
222 bool IsShowOnlyEnabled()
const
224 return ShowOnlyFilter.IsEnabled();
229 return ShowOnlyFilter;
232 UFUNCTION(BlueprintCallable)
233 void Enable16BitFormat(
bool Enable = false)
235 bEnable16BitFormat = Enable;
238 UFUNCTION(BlueprintCallable)
239 bool Is16BitFormatEnabled()
const
241 return bEnable16BitFormat;
244 UFUNCTION(BlueprintCallable)
245 void SetFOVAngle(
float FOVAngle);
247 UFUNCTION(BlueprintCallable)
248 float GetFOVAngle()
const;
250 UFUNCTION(BlueprintCallable)
251 void SetTargetGamma(
float InTargetGamma)
253 TargetGamma = InTargetGamma;
256 UFUNCTION(BlueprintCallable)
257 float GetTargetGamma()
const
262 UFUNCTION(BlueprintCallable)
263 void SetBloomMethod(EBloomMethod Method);
265 UFUNCTION(BlueprintCallable)
266 EBloomMethod GetBloomMethod()
const;
268 UFUNCTION(BlueprintCallable)
269 FVector4 GetGlobalGain()
const;
271 UFUNCTION(BlueprintCallable)
272 void SetGlobalGain(FVector4 Gain);
274 UFUNCTION(BlueprintCallable)
275 float GetBlueCorrection()
const;
277 UFUNCTION(BlueprintCallable)
278 void SetBlueCorrection(
float Val);
280 UFUNCTION(BlueprintCallable)
281 float GetDetailStrength()
const;
283 UFUNCTION(BlueprintCallable)
284 void SetDetailStrength(
float Val);
286 UFUNCTION(BlueprintCallable)
287 float GetFilmGrainIntensity()
const;
289 UFUNCTION(BlueprintCallable)
290 void SetFilmGrainIntensity(
float Val);
292 UFUNCTION(BlueprintCallable)
293 void SetAOIntensity(
float Intensity);
295 UFUNCTION(BlueprintCallable)
296 float GetAOIntensity()
const;
298 UFUNCTION(BlueprintCallable)
299 void SetAORadius(
float Radius);
301 UFUNCTION(BlueprintCallable)
302 float GetAORadius()
const;
304 UFUNCTION(BlueprintCallable)
305 void SetExposureMethod(EAutoExposureMethod Method);
307 UFUNCTION(BlueprintCallable)
308 EAutoExposureMethod GetExposureMethod()
const;
310 UFUNCTION(BlueprintCallable)
311 void SetLocalExposureMethod(ELocalExposureMethod Method);
313 UFUNCTION(BlueprintCallable)
314 ELocalExposureMethod GetLocalExposureMethod()
const;
316 UFUNCTION(BlueprintCallable)
317 UTexture2D *GetBloomKernelTexture()
const;
319 UFUNCTION(BlueprintCallable)
320 void SetBloomConvolutionTexture(UTexture2D *Texture);
322 UFUNCTION(BlueprintCallable)
323 void SetExposureCompensation(
float Compensation);
325 UFUNCTION(BlueprintCallable)
326 float GetExposureCompensation()
const;
328 UFUNCTION(BlueprintCallable)
329 float GetDirtMaskIntensity()
const;
331 UFUNCTION(BlueprintCallable)
332 void SetDirtMaskIntensity(
float Intensity);
334 UFUNCTION(BlueprintCallable)
335 void SetShutterSpeed(
float Speed);
337 UFUNCTION(BlueprintCallable)
338 float GetShutterSpeed()
const;
340 UFUNCTION(BlueprintCallable)
341 void SetISO(
float ISO);
343 UFUNCTION(BlueprintCallable)
344 float GetISO()
const;
346 UFUNCTION(BlueprintCallable)
347 void SetAperture(
float Aperture);
349 UFUNCTION(BlueprintCallable)
350 float GetAperture()
const;
352 UFUNCTION(BlueprintCallable)
353 void SetSensorWidth(
float Width);
355 UFUNCTION(BlueprintCallable)
356 float GetSensorWidth()
const;
358 UFUNCTION(BlueprintCallable)
359 void SetFocalDistance(
float Distance);
361 UFUNCTION(BlueprintCallable)
362 float GetFocalDistance()
const;
364 UFUNCTION(BlueprintCallable)
365 void SetDepthBlurAmount(
float Amount);
367 UFUNCTION(BlueprintCallable)
368 float GetDepthBlurAmount()
const;
370 UFUNCTION(BlueprintCallable)
371 void SetDepthBlurRadius(
float Radius);
373 UFUNCTION(BlueprintCallable)
374 float GetDepthBlurRadius()
const;
376 UFUNCTION(BlueprintCallable)
377 void SetBladeCount(
int Count);
379 UFUNCTION(BlueprintCallable)
380 int GetBladeCount()
const;
382 UFUNCTION(BlueprintCallable)
383 void SetDepthOfFieldMinFstop(
float MinFstop);
385 UFUNCTION(BlueprintCallable)
386 float GetDepthOfFieldMinFstop()
const;
388 UFUNCTION(BlueprintCallable)
389 void SetFilmSlope(
float Slope);
391 UFUNCTION(BlueprintCallable)
392 float GetFilmSlope()
const;
394 UFUNCTION(BlueprintCallable)
395 void SetFilmToe(
float Toe);
397 UFUNCTION(BlueprintCallable)
398 float GetFilmToe()
const;
400 UFUNCTION(BlueprintCallable)
401 void SetFilmShoulder(
float Shoulder);
403 UFUNCTION(BlueprintCallable)
404 float GetFilmShoulder()
const;
406 UFUNCTION(BlueprintCallable)
407 void SetFilmBlackClip(
float BlackClip);
409 UFUNCTION(BlueprintCallable)
410 float GetFilmBlackClip()
const;
412 UFUNCTION(BlueprintCallable)
413 void SetFilmWhiteClip(
float WhiteClip);
415 UFUNCTION(BlueprintCallable)
416 float GetFilmWhiteClip()
const;
418 UFUNCTION(BlueprintCallable)
419 void SetExposureMinBrightness(
float Brightness);
421 UFUNCTION(BlueprintCallable)
422 float GetExposureMinBrightness()
const;
424 UFUNCTION(BlueprintCallable)
425 void SetExposureMaxBrightness(
float Brightness);
427 UFUNCTION(BlueprintCallable)
428 float GetExposureMaxBrightness()
const;
430 UFUNCTION(BlueprintCallable)
431 void SetExposureSpeedDown(
float Speed);
433 UFUNCTION(BlueprintCallable)
434 float GetExposureSpeedDown()
const;
436 UFUNCTION(BlueprintCallable)
437 void SetExposureSpeedUp(
float Speed);
439 UFUNCTION(BlueprintCallable)
440 float GetExposureSpeedUp()
const;
442 UFUNCTION(BlueprintCallable)
443 void SetExposureCalibrationConstant(
float Constant);
445 UFUNCTION(BlueprintCallable)
446 float GetExposureCalibrationConstant()
const;
448 UFUNCTION(BlueprintCallable)
449 void SetMotionBlurIntensity(
float Intensity);
451 UFUNCTION(BlueprintCallable)
452 float GetMotionBlurIntensity()
const;
454 UFUNCTION(BlueprintCallable)
455 void SetMotionBlurMaxDistortion(
float MaxDistortion);
457 UFUNCTION(BlueprintCallable)
458 float GetMotionBlurMaxDistortion()
const;
460 UFUNCTION(BlueprintCallable)
461 void SetMotionBlurMinObjectScreenSize(
float ScreenSize);
463 UFUNCTION(BlueprintCallable)
464 float GetMotionBlurMinObjectScreenSize()
const;
466 UFUNCTION(BlueprintCallable)
467 void SetLensFlareIntensity(
float Intensity);
469 UFUNCTION(BlueprintCallable)
470 float GetLensFlareIntensity()
const;
472 UFUNCTION(BlueprintCallable)
473 void SetBloomIntensity(
float Intensity);
475 UFUNCTION(BlueprintCallable)
476 float GetBloomIntensity()
const;
478 UFUNCTION(BlueprintCallable)
479 void SetWhiteTemp(
float Temp);
481 UFUNCTION(BlueprintCallable)
482 float GetWhiteTemp()
const;
484 UFUNCTION(BlueprintCallable)
485 void SetWhiteTint(
float Tint);
487 UFUNCTION(BlueprintCallable)
488 float GetWhiteTint()
const;
490 UFUNCTION(BlueprintCallable)
491 void SetChromAberrIntensity(
float Intensity);
493 UFUNCTION(BlueprintCallable)
494 float GetChromAberrIntensity()
const;
496 UFUNCTION(BlueprintCallable)
497 void SetChromAberrOffset(
float ChromAberrOffset);
499 UFUNCTION(BlueprintCallable)
500 float GetChromAberrOffset()
const;
502 UFUNCTION(BlueprintCallable)
503 void SetColorSaturation(FVector4 ColorSaturation);
505 UFUNCTION(BlueprintCallable)
506 FVector4 GetColorSaturation()
const;
508 UFUNCTION(BlueprintCallable)
509 void SetColorSaturationMidtones(FVector4 ColorSaturation);
511 UFUNCTION(BlueprintCallable)
512 FVector4 GetColorSaturationMidtones()
const;
514 UFUNCTION(BlueprintCallable)
515 void SetColorSaturationHighlights(FVector4 ColorSaturation);
517 UFUNCTION(BlueprintCallable)
518 FVector4 GetColorSaturationHighlights()
const;
520 UFUNCTION(BlueprintCallable)
521 void SetColorContrast(FVector4 ColorContrast);
523 UFUNCTION(BlueprintCallable)
524 FVector4 GetColorContrast()
const;
526 UFUNCTION(BlueprintCallable)
527 void SetColorContrastMidtones(FVector4 ColorContrast);
529 UFUNCTION(BlueprintCallable)
530 FVector4 GetColorContrastMidtones()
const;
532 UFUNCTION(BlueprintCallable)
533 void SetColorContrastHighlights(FVector4 ColorContrast);
535 UFUNCTION(BlueprintCallable)
536 FVector4 GetColorContrastHighlights()
const;
538 UFUNCTION(BlueprintCallable)
539 void SetColorGamma(FVector4 ColorGamma);
541 UFUNCTION(BlueprintCallable)
542 FVector4 GetColorGamma()
const;
544 UFUNCTION(BlueprintCallable)
545 void SetHighlightsGamma(FVector4 HighlightsGamma);
547 UFUNCTION(BlueprintCallable)
548 FVector4 GetHighlightsGamma()
const;
550 UFUNCTION(BlueprintCallable)
551 void SetToneCurveAmount(
float ToneCurveAmount);
553 UFUNCTION(BlueprintCallable)
554 float GetToneCurveAmount()
const;
556 UFUNCTION(BlueprintCallable)
557 void SetSceneColorTint(FLinearColor SceneColorTint);
559 UFUNCTION(BlueprintCallable)
560 FLinearColor GetSceneColorTint()
const;
562 UFUNCTION(BlueprintCallable)
563 void SetVignetteIntensity(
float VignetteIntensity);
565 UFUNCTION(BlueprintCallable)
566 float GetVignetteIntensity()
const;
568 UFUNCTION(BlueprintCallable)
569 void SetHighlightContrastScale(
float HighlightContrastScale);
571 UFUNCTION(BlueprintCallable)
572 float GetHighlightContrastScale()
const;
574 UFUNCTION(BlueprintCallable)
575 void SetShadowContrastScale(
float ShadowContrastScale);
577 UFUNCTION(BlueprintCallable)
578 float GetShadowContrastScale()
const;
580 virtual void UpdatePostProcessConfig(
584 UFUNCTION(BlueprintCallable)
585 bool ReadPixels(TArray<FColor> &BitMap)
const
587 check(CaptureRenderTarget !=
nullptr);
592 UFUNCTION(BlueprintCallable)
593 void SaveCaptureToDisk(const FString &FilePath)
const
595 check(CaptureRenderTarget !=
nullptr);
599 UFUNCTION(BlueprintCallable)
602 return CaptureComponent2D;
605 UFUNCTION(BlueprintCallable)
606 UTextureRenderTarget2D *GetCaptureRenderTarget()
608 return CaptureRenderTarget;
617 void EnqueueRenderSceneImmediate();
643 UFUNCTION(BlueprintCallable)
644 static bool ApplyPostProcessVolumeToSensor(APostProcessVolume *Origin,
ASceneCaptureSensor *Dest,
bool bOverrideCurrentCamera =
false);
656#ifdef CARLA_HAS_GBUFFER_API
657 virtual void SendGBufferTextures(FGBufferRequest &GBuffer);
660 virtual void BeginPlay()
override;
662 virtual void PrePhysTick(
float DeltaSeconds)
override;
663 virtual void PostPhysTick(UWorld *World, ELevelTick TickType,
float DeltaTime)
override;
666 void UpdateExposureMotionBlur(UWorld *World,
float DeltaTime);
669 double LastCaptureTime = -1.0;
672 float ExposureSeconds = 0.0f;
674 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason)
override;
679 UPROPERTY(VisibleAnywhere)
680 TObjectPtr<UTextureRenderTarget2D> CaptureRenderTarget =
nullptr;
683 UPROPERTY(VisibleAnywhere)
694 UPROPERTY(EditAnywhere)
695 float TargetGamma = 2.2f;
698 UPROPERTY(EditAnywhere)
699 uint32 ImageWidth = 800u;
702 UPROPERTY(EditAnywhere)
703 uint32 ImageHeight = 600u;
706 UPROPERTY(EditAnywhere)
707 bool bEnablePostProcessingEffects = true;
715 UPROPERTY(EditAnywhere)
716 bool bUseRayTracing = true;
719 UPROPERTY(EditAnywhere)
720 bool bEnable16BitFormat = false;
728 UPROPERTY(EditAnywhere)
729 bool bEnableDLSSUpscale = false;
733 UPROPERTY(EditAnywhere)
734 float DLSSScreenPercentage = 50.0f;
746 bool IsAnyGBufferClientListening() const;
751 bool ShouldCaptureThisFrame();
754 void ApplyRayTracingSetting();
757 int32 NumCaptures = 0;
759#ifdef CARLA_HAS_GBUFFER_API
762 typename CameraGBufferT>
763 static void SendGBuffer(
765 CameraGBufferT &CameraGBuffer,
766 FGBufferRequest &GBufferData,
767 EGBufferTextureID TextureID)
769 using PixelType =
typename std::conditional<
774 TArray<PixelType> Pixels;
775 if (GBufferData.WaitForTextureTransfer(TextureID))
777 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"GBuffer Decode");
780 FIntPoint SourceExtent;
781 GBufferData.MapTextureData(
786 auto Format = GBufferData.Readbacks[(size_t)TextureID]->GetFormat();
787 ViewSize = GBufferData.ViewRect.Size();
788 Pixels.AddUninitialized(ViewSize.X * ViewSize.Y);
789 FReadSurfaceDataFlags Flags = {};
790 Flags.SetLinearToGamma(
true);
799 GBufferData.UnmapTextureData(TextureID);
803 ViewSize = GBufferData.ViewRect.Size();
804 Pixels.SetNum(ViewSize.X * ViewSize.Y);
805 for (
auto &Pixel : Pixels)
806 Pixel = PixelType::Black;
808 auto GBufferStream = CameraGBuffer.GetDataStream(Self);
809 auto Buffer = GBufferStream.PopBufferFromPool();
817 SCOPE_CYCLE_COUNTER(STAT_CarlaSensorStreamSend);
818 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"Stream Send");
819 GBufferStream.SerializeAndSend(
829#ifdef CARLA_HAS_GBUFFER_API
830 template <
typename T>
831 void SendGBufferTexturesInternal(T &Self, FGBufferRequest &GBufferData)
833 for (
size_t i = 0; i != FGBufferRequest::TextureCount; ++i)
835 if ((GBufferData.DesiredTexturesMask & (UINT64_C(1) << i)) == 0)
839 auto &C = CameraGBuffers;
840 EGBufferTextureID ID = (EGBufferTextureID)i;
843 case EGBufferTextureID::SceneColor:
844 SendGBuffer(Self, C.SceneColor, GBufferData, ID);
846 case EGBufferTextureID::SceneDepth:
847 SendGBuffer(Self, C.SceneDepth, GBufferData, ID);
849 case EGBufferTextureID::SceneStencil:
850 SendGBuffer(Self, C.SceneStencil, GBufferData, ID);
852 case EGBufferTextureID::GBufferA:
853 SendGBuffer(Self, C.GBufferA, GBufferData, ID);
855 case EGBufferTextureID::GBufferB:
856 SendGBuffer(Self, C.GBufferB, GBufferData, ID);
858 case EGBufferTextureID::GBufferC:
859 SendGBuffer(Self, C.GBufferC, GBufferData, ID);
861 case EGBufferTextureID::GBufferD:
862 SendGBuffer(Self, C.GBufferD, GBufferData, ID);
864 case EGBufferTextureID::GBufferE:
865 SendGBuffer(Self, C.GBufferE, GBufferData, ID);
867 case EGBufferTextureID::GBufferF:
868 SendGBuffer(Self, C.GBufferF, GBufferData, ID);
870 case EGBufferTextureID::Velocity:
871 SendGBuffer(Self, C.Velocity, GBufferData, ID);
873 case EGBufferTextureID::SSAO:
874 SendGBuffer(Self, C.SSAO, GBufferData, ID);
876 case EGBufferTextureID::CustomDepth:
877 SendGBuffer(Self, C.CustomDepth, GBufferData, ID);
879 case EGBufferTextureID::CustomStencil:
880 SendGBuffer(Self, C.CustomStencil, GBufferData, ID);