IVSmoke 1.0
Loading...
Searching...
No Matches
IVSmokeHoleGeneratorComponent.h
1// Copyright (c) 2026, Team SDB. All rights reserved.
2
3#pragma once
4
5#include "Components/BoxComponent.h"
6#include "IVSmokeHoleData.h"
7#include "IVSmokeHoleGeneratorComponent.generated.h"
8
9class UTexture2D;
10class UTextureRenderTargetVolume;
12
13/**
14 * @brief Component that generates hole texture for volumetric smoke.
15 * Provides public API for penetration and explosion holes.
16 */
17UCLASS(ClassGroup = (IVSmoke), meta = (BlueprintSpawnableComponent))
18class IVSMOKE_API UIVSmokeHoleGeneratorComponent : public UBoxComponent
19{
20 GENERATED_BODY()
21
22public:
24 virtual void PostInitProperties() override;
25
26protected:
27 virtual void BeginPlay() override;
28 virtual void TickComponent(const float DeltaTime, const ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
29 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
30 virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
31
32 //~============================================================================
33 // Public API (Blueprint & C++)
34#pragma region API
35public:
36 /** Reset all holes and dynamic subjects to initial state. */
37 UFUNCTION(BlueprintCallable, Category = "IVSmoke | Hole | API")
38 void Reset();
39
40 /** Create penetration hole. Called on server via UIVSmokeHoleRequestComponent. */
41 void CreatePenetrationHole(const FVector3f& Origin, const FVector3f& Direction, const uint8 PresetID);
42
43 /** Create explosion hole. Called on server via UIVSmokeHoleRequestComponent. */
44 void CreateExplosionHole(const FVector3f& Origin, const uint8 PresetID);
45
46 /** Register dynamic object. Called on server via UIVSmokeHoleRequestComponent. */
47 void RegisterTrackDynamicHole(AActor* TargetActor, const uint8 PresetID);
48#pragma endregion
49
50 //~============================================================================
51 // Authority Only (Server & Standalone)
52#pragma region Authority Only
53private:
54
55 UPROPERTY(Transient)
56 TArray<FIVSmokeHoleDynamicSubject> DynamicSubjectList;
57
58 /** Create hole data to be rendered by GPU. (todo: must be refactored) */
59 void Authority_CreateHole(const FIVSmokeHoleData& HoleData);
60
61 /** Clean up expired hole data and notify GPU to be updated. */
62 void Authority_CleanupExpiredHoles();
63
64 /** Calculate penetration entry & exit points via raycast. */
65 bool Authority_CalculatePenetrationPoints(const FVector3f& Origin, const FVector3f& Direction, const float BulletThickness, FVector3f& OutEntry, FVector3f& OutExit);
66
67 /** Manage the dynamic object's life cycle and update dynamic hole. */
68 void Authority_UpdateDynamicSubjectList();
69#pragma endregion
70
71 //~============================================================================
72 // Local Only (Client & Standalone)
73#pragma region Local Only
74private:
75 UPROPERTY(Transient)
76 TObjectPtr<UTextureRenderTargetVolume> HoleTexture = nullptr;
77
78 /** Initialize 3D texture for hole data. */
79 void Local_InitializeHoleTexture();
80
81 /** Clear hole texture to white. Called when all holes have expired. */
82 void Local_ClearHoleTexture();
83
84 /** Rebuild entire hole texture from ActiveHoles. (todo: must be refactored) */
85 void Local_RebuildHoleTexture();
86#pragma endregion
87
88 //~============================================================================
89 // Common
90#pragma region Common
91public:
92
93 /** Maximum number of holes that can be activated. */
94 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Configuration", meta = (ClampMin = "1", ClampMax = "512"))
95 int32 MaxHoles = 128;
96
97 /** Hole voxel volume resolution. */
98 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Configuration", meta = (ClampMin = "64", ClampMax = "128"))
99 FIntVector VoxelResolution = FIntVector(64, 64, 64);
100
101 /** Maximum number of holes that can be activated. */
102 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Configuration",
103 meta = (ToolTip = "Select the type of obstacle that will block the penetration hole in the smoke"))
104 TArray<TEnumAsByte<EObjectTypeQuery>> ObstacleObjectTypes;
105
106 /** Blur radius in voxels. */
107 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Configuration", meta = (ClampMin = "0", ClampMax = "4",
108 Tooltip = "samples the surrounding pixels to reduce the aliasing. Recommended value is 2."))
109 int32 BlurStep = 2;
110
111 /** Noise settings for penetration holes. */
112 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Noise")
114
115 /** Noise settings for explosion holes. */
116 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Noise")
118
119 /** Noise settings for dynamic holes. */
120 UPROPERTY(EditAnywhere, Category = "IVSmoke | Hole | Noise")
122
123 /** Get synchronized server time. */
124 float GetSyncedTime() const;
125
126 /** Get Texture as a UTextureRenderTargetVolume to write by. */
127 FTextureRHIRef GetHoleTextureRHI() const;
128
129 /** Set BoxExtent and Component Position to VoxelAABB Center. */
130 void SetBoxToVoxelAABB();
131
132 /** Set Dirty flag whether GPU updates the texure. */
133 FORCEINLINE void MarkHoleTextureDirty(const bool bIsDirty = true) { bHoleTextureDirty = bIsDirty; }
134
135private:
136
137 /** These are the holes activated in this smoke volume.*/
138 UPROPERTY(Transient, Replicated, VisibleAnywhere, Category = "IVSmoke | Hole | Debug")
139 FIVSmokeHoleArray ActiveHoles;
140
141 /** HoleTexture dirty flag. */
142 uint8 bHoleTextureDirty : 1;
143#pragma endregion
144};
Component that generates hole texture for volumetric smoke. Provides public API for penetration and e...
Fast TArray container for delta replication of hole data.
Network-optimized hole data structure.
Noise settings for hole shape distortion.