IVSmoke 1.0
Loading...
Searching...
No Matches
IVSmokeHoleShaders.h
1// Copyright (c) 2026, Team SDB. All rights reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GlobalShader.h"
7#include "ShaderParameterStruct.h"
8
10struct FIVSmokeHoleData;
11
12//~============================================================================
13// GPU Data Structure
14
15/**
16 * @struct FIVSmokeHoleGPU
17 * @brief Built from FIVSmokeHoleData + UIVSmokeHolePreset at render time.
18 */
19struct alignas(16) FIVSmokeHoleGPU
20{
21 FIVSmokeHoleGPU() = default;
22
23 /**
24 * You can Constructs a FIVSmokeHoleGPU using DynamicHoleData, Preset, and server time.
25 * @param DynamicHoleData Dynamic hole data.
26 * @param Preset HolePreset defined as DataAsset.
27 * @param CurrentServerTime The CurrentServerTime is obtained through the GetSyncedTime function.
28 */
29 FIVSmokeHoleGPU(const FIVSmokeHoleData& DynamicHoleData, const UIVSmokeHolePreset& Preset, const float CurrentServerTime);
30
31 //~============================================================================
32 // Common
33
34 /** The central point of hole creation. */
35 FVector3f Position;
36
37 /** Time after hole is called creation. */
39
40 /** 0 = Penetration, 1 = Explosion, 2 = Dynamic */
42
43 /** Radius value used to calculate values related to the range. */
44 float Radius;
45
46 /** Total duration. */
47 float Duration;
48
49 /** Edge smooth range. */
50 float Softness;
51
52 //~============================================================================
53 // Dynamic
54
55 /** the size of a hole. */
56 FVector3f Extent;
57
58 float DynamicPadding;
59
60 //~============================================================================
61 // Explosion
62
63 /** Expansion time used only for Explosion. */
65
66 /** Current fadeRange extracted from ExpansionFadeRangeCurveOverTime with values normalized to expansion time. */
68
69 /** Current fadeRange extracted from ShrinkFadeRangeCurveOverTime with values normalized to shrink time. */
71
72 /** Exponential value of the calculation of the distortion value over expansion time. */
74
75 /** Distortion degree max value. */
77
78 FVector3f PresetExplosionPadding;
79
80 //~============================================================================
81 // Penetration
82
83 /** The point at which the trajectory of the penetration ends. */
84 FVector3f EndPosition;
85
86 /** Radius at the end position. */
87 float EndRadius;
88};
89
90/**
91 * @brief Compute shader that carves holes into 3D volume texture.
92 */
93class IVSMOKE_API FIVSmokeHoleCarveCS : public FGlobalShader
94{
95public:
96 static constexpr uint32 ThreadGroupSizeX = 8;
97 static constexpr uint32 ThreadGroupSizeY = 8;
98 static constexpr uint32 ThreadGroupSizeZ = 8;
99 static constexpr const TCHAR* EventName = TEXT("IVSmokeHoleCarveCS");
100 DECLARE_GLOBAL_SHADER(FIVSmokeHoleCarveCS);
101 SHADER_USE_PARAMETER_STRUCT(FIVSmokeHoleCarveCS, FGlobalShader);
102
103public:
104
105 BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
106 // Output: 3D Volume Texture (Read and Write) - R16G16B16A16_UNORM channel
107 SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture3D<float4>, VolumeTexture)
108
109 // Input: Hole data buffer (unified structure)
110 SHADER_PARAMETER_RDG_BUFFER_SRV(StructuredBuffer<FIVSmokeHoleGPU>, HoleBuffer)
111
112 // Volume bounds (local space)
113 SHADER_PARAMETER(FVector3f, VolumeMin)
114 SHADER_PARAMETER(FVector3f, VolumeMax)
115
116 // Volume resolution
117 SHADER_PARAMETER(FIntVector, Resolution)
118
119 // Hole parameters
120 SHADER_PARAMETER(int32, NumHoles)
121
122 // Noise textures (per HoleType)
123 SHADER_PARAMETER_TEXTURE(Texture2D, PenetrationNoiseTexture)
124 SHADER_PARAMETER_TEXTURE(Texture2D, ExplosionNoiseTexture)
125 SHADER_PARAMETER_TEXTURE(Texture2D, DynamicNoiseTexture)
126 SHADER_PARAMETER_SAMPLER(SamplerState, NoiseSampler)
127
128 // Noise parameters (per HoleType)
129 SHADER_PARAMETER(float, PenetrationNoiseStrength)
130 SHADER_PARAMETER(float, PenetrationNoiseScale)
131 SHADER_PARAMETER(float, ExplosionNoiseStrength)
132 SHADER_PARAMETER(float, ExplosionNoiseScale)
133 SHADER_PARAMETER(float, DynamicNoiseStrength)
134 SHADER_PARAMETER(float, DynamicNoiseScale)
135 END_SHADER_PARAMETER_STRUCT()
136
137 static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
138 {
139 return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5);
140 }
141
142 static void ModifyCompilationEnvironment(
143 const FGlobalShaderPermutationParameters& Parameters,
144 FShaderCompilerEnvironment& OutEnvironment
145 )
146 {
147 FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
148 OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEX"), ThreadGroupSizeX);
149 OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEY"), ThreadGroupSizeY);
150 OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEZ"), ThreadGroupSizeZ);
151 }
152};
153
154/**
155 * @brief Compute shader for 1D separable blur on 3D volume texture.
156 * Run 3 times (X, Y, Z axis) for full 3D Gaussian blur.
157 */
158class IVSMOKE_API FIVSmokeHoleBlurCS : public FGlobalShader
159{
160public:
161 static constexpr uint32 ThreadGroupSizeX = 8;
162 static constexpr uint32 ThreadGroupSizeY = 8;
163 static constexpr uint32 ThreadGroupSizeZ = 8;
164 static constexpr const TCHAR* EventName = TEXT("IVSmokeHoleBlurCS");
165 DECLARE_GLOBAL_SHADER(FIVSmokeHoleBlurCS);
166 SHADER_USE_PARAMETER_STRUCT(FIVSmokeHoleBlurCS, FGlobalShader);
167
168public:
169 BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
170 // Input: Source volume texture
171 SHADER_PARAMETER_RDG_TEXTURE_SRV(Texture3D<float4>, InputTexture)
172 SHADER_PARAMETER_SAMPLER(SamplerState, InputSampler)
173
174 // Output: Destination volume texture
175 SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture3D<float4>, OutputTexture)
176
177 // Volume resolution
178 SHADER_PARAMETER(FIntVector, Resolution)
179
180 // Blur direction: (1,0,0) for X, (0,1,0) for Y, (0,0,1) for Z
181 SHADER_PARAMETER(FIntVector, BlurDirection)
182
183 // Blur radius in voxels
184 SHADER_PARAMETER(int32, BlurStep)
185 END_SHADER_PARAMETER_STRUCT()
186
187 static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
188 {
189 return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5);
190 }
191
192 static void ModifyCompilationEnvironment(
193 const FGlobalShaderPermutationParameters& Parameters,
194 FShaderCompilerEnvironment& OutEnvironment
195 )
196 {
197 FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
198 OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEX"), ThreadGroupSizeX);
199 OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEY"), ThreadGroupSizeY);
200 OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEZ"), ThreadGroupSizeZ);
201 }
202};
Compute shader for 1D separable blur on 3D volume texture. Run 3 times (X, Y, Z axis) for full 3D Gau...
Compute shader that carves holes into 3D volume texture.
Network-optimized hole data structure.
Built from FIVSmokeHoleData + UIVSmokeHolePreset at render time.
float CurExpansionFadeRangeOverTime