Repository navigation
Expand file tree
/
Copy pathLightCacheInterface.cpp
More file actions
284 lines (248 loc) · 10.1 KB
/
Copy pathLightCacheInterface.cpp
File metadata and controls
284 lines (248 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
class ENGINE_API FLightMap : private FDeferredCleanupInterface {
TArray<FGuid> LightGuids;/** The GUIDs of lights which this light-map stores. */
}
class ENGINE_API FLightMap2D : public FLightMap {
// ULightMapVirtualTexture2D *VirtualTexture = nullptr; /** The virtual textures containing the light-map data. */
ULightMapTexture2D* Textures[2] = {nullptr, nullptr};/** The textures containing the {HQ,LQ} light-map data. */
FVector4 ScaleVectors[4];/** A scale to apply to the coefficients. */
FVector4 AddVectors[4];/** Bias value to apply to the coefficients. */
FVector2D CoordinateScale;/** The scale which is applied to the light-map coordinates before sampling the light-map textures. */
FVector2D CoordinateBias;/** The bias which is applied to the light-map coordinates before sampling the light-map textures. */
ULightMapTexture2D* SkyOcclusionTexture = nullptr;
ULightMapTexture2D* AOMaterialMaskTexture = nullptr;
UShadowMapTexture2D* ShadowMapTexture = nullptr;
FVector4 InvUniformPenumbraSize;/** Stores the inverse of the penumbra size, normalized. Stores 1 to interpret the shadowmap as a shadow factor directly, instead of as a distance field. */
bool bShadowChannelValid[4];/** Tracks which of the 4 channels has valid texture data. */
};
class ENGINE_API FShadowMap : public FShadowMap {
TArray<FGuid> LightGuids;/** The GUIDs of lights which this shadow-map stores. */
}
class ENGINE_API FShadowMap2D : public FShadowMap {
UShadowMapTexture2D* Texture;/** The texture which contains the shadow-map data. */
FVector2D CoordinateScale;/** The scale which is applied to the shadow-map coordinates before sampling the shadow-map textures. */
FVector2D CoordinateBias;/** The bias which is applied to the shadow-map coordinates before sampling the shadow-map textures. */
bool bChannelValid[4];/** Tracks which of the 4 channels has valid texture data. */
FVector4 InvUniformPenumbraSize;/** Stores the inverse of the penumbra size, normalized. Stores 1 to interpret the shadowmap as a shadow factor directly, instead of as a distance field. */
};
class FLightCacheInterface {/** An interface to cached lighting for a specific mesh. */
bool bGlobalVolumeLightmap = false;
const FLightMap* LightMap = nullptr;
const FShadowMap* ShadowMap = nullptr;
const FLightmapResourceCluster* ResourceCluster = nullptr;
FUniformBufferRHIRef PrecomputedLightingUniformBuffer;/** The uniform buffer holding mapping the lightmap policy resources. */
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
class FLightMapInteraction {/**Information about an interaction between a light and a mesh.*/
FVector4 HighQualityCoefficientScales[2];
FVector4 HighQualityCoefficientAdds[2];
const ULightMapTexture2D* HighQualityTexture = nullptr;
const ULightMapTexture2D* SkyOcclusionTexture = nullptr;
const ULightMapTexture2D* AOMaterialMaskTexture = nullptr;
//const ULightMapVirtualTexture2D* VirtualTexture = nullptr;
FVector4 LowQualityCoefficientScales[2];
FVector4 LowQualityCoefficientAdds[2];
const ULightMapTexture2D* LowQualityTexture = nullptr;
bool bAllowHighQualityLightMaps;
uint32 NumLightmapCoefficients;
ELightMapInteractionType Type = LMIT_None;
FVector2D CoordinateScale;
FVector2D CoordinateBias;
};
FLightMapInteraction FLightCacheInterface::GetLightMapInteraction(ERHIFeatureLevel::Type InFeatureLevel) const
{
if (bGlobalVolumeLightmap)
{
return FLightMapInteraction::GlobalVolume();
}
return LightMap ? LightMap->GetInteraction(InFeatureLevel) : FLightMapInteraction();
}
FLightMapInteraction FLightMap2D::GetInteraction(ERHIFeatureLevel::Type InFeatureLevel) const
{
bool bHighQuality = TEXT("r.HighQualityLightMaps") != 0;
int32 LightmapIndex = bHighQuality ? 0 : 1;
bool bValidTextures = Textures[LightmapIndex] && Textures[LightmapIndex]->Resource;
if (bValidTextures)
{
return FLightMapInteraction::Texture(Textures, SkyOcclusionTexture, AOMaterialMaskTexture,
ScaleVectors, AddVectors, CoordinateScale, CoordinateBias, bHighQuality);
}
return FLightMapInteraction();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
class FShadowMapInteraction {/** Information about the static shadowing information for a primitive. */
UShadowMapTexture2D* ShadowTexture = nullptr;
//const ULightMapVirtualTexture2D* VirtualTexture = nullptr;
FVector2D CoordinateScale;
FVector2D CoordinateBias;
bool bChannelValid[4] = {false,false,false,false};
FVector4 InvUniformPenumbraSize = FVector4(0, 0, 0, 0);
EShadowMapInteractionType Type = SMIT_None;
}
FShadowMapInteraction FLightCacheInterface::GetShadowMapInteraction(ERHIFeatureLevel::Type InFeatureLevel) const
{
if (bGlobalVolumeLightmap)
{
return FShadowMapInteraction::GlobalVolume();
}
return ShadowMap ? ShadowMap->GetInteraction(InFeatureLevel) : FShadowMapInteraction();
}
FShadowMapInteraction FShadowMap2D::GetInteraction() const
{
if (Texture)
{
return FShadowMapInteraction::Texture(Texture, CoordinateScale, CoordinateBias, bChannelValid, InvUniformPenumbraSize);
}
return FShadowMapInteraction();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
class ENGINE_API FStaticMeshSceneProxy : public FPrimitiveSceneProxy {
class FLODInfo : public FLightCacheInterface {
}
}
FStaticMeshSceneProxy::FStaticMeshSceneProxy(UStaticMeshComponent* InComponent, false)
{
for(int32 LODIndex = 0;LODIndex < RenderData->LODResources.Num(); LODIndex++)
{
FLODInfo* NewLODInfo = new (LODs) FLODInfo(
InComponent,
RenderData->LODVertexFactories,
LODIndex,
ClampedMinLOD,
RenderData->bLODsShareStaticLighting);
}
}
FStaticMeshSceneProxy::FLODInfo::FLODInfo(
const UStaticMeshComponent* InComponent,
const FStaticMeshVertexFactoriesArray& InLODVertexFactories,
int32 LODIndex,
int32 InClampedMinLOD,
bool bLODsShareStaticLighting)
{
if (InComponent->LightmapType == ELightmapType::ForceVolumetric)
{
bGlobalVolumeLightmap = true;
}
if (LODIndex < InComponent->LODData.Num() && LODIndex >= InClampedMinLOD)
{
const FStaticMeshComponentLODInfo& ComponentLODInfo = InComponent->LODData[LODIndex];
if (InComponent->LightmapType != ELightmapType::ForceVolumetric)
{
const FMeshMapBuildData* MeshMapBuildData = InComponent->GetMeshMapBuildData(ComponentLODInfo);
if (MeshMapBuildData)
{
LightMap = MeshMapBuildData->LightMap;
ShadowMap = MeshMapBuildData->ShadowMap;
ResourceCluster = MeshMapBuildData->ResourceCluster;
IrrelevantLights = MeshMapBuildData->IrrelevantLights;
}
}
...
}
...
}
// Convert FStaticMeshComponentLODInfo to FMeshMapBuildData
FMeshMapBuildData* UStaticMeshComponent::GetMeshMapBuildData(const FStaticMeshComponentLODInfo& LODInfo)
{
if (LODInfo.OverrideMapBuildData)
{
return LODInfo.OverrideMapBuildData.Get();
}
AActor* Owner = GetOwner();
if ( GetOwner()
&& GetOwner()->GetLevel()
&& GetOwner()->GetLevel()->MapBuildData)
{
UMapBuildDataRegistry* MapBuildData = GetOwner()->GetLevel()->MapBuildData;
return MapBuildData->GetMeshBuildData(LODInfo.MapBuildDataId);
}
return NULL;
}
class ENGINE_API AActor : public UObject {
void InvalidateLightingCache()
{
if (GIsEditor && !GIsDemoMode)
{
InvalidateLightingCacheDetailed(false);
}
}
void InvalidateLightingCacheDetailed(bool bTranslationOnly)
{
if(GIsEditor && !GIsDemoMode)
{
for (UActorComponent* Component : GetComponents())
{
if (Component && Component->IsRegistered())
{
Component->InvalidateLightingCacheDetailed(true, bTranslationOnly);
}
}
}
}
}
class ENGINE_API UActorComponent : public UObject {
void InvalidateLightingCache()
{
InvalidateLightingCacheDetailed(true, false);
}
virtual void InvalidateLightingCacheDetailed(bool bInvalidateBuildEnqueuedLighting, bool bTranslationOnly) {}
}
class ENGINE_API UPrimitiveComponent : public USceneComponent {
int32 VisibilityId;/** Used for precomputed visibility */
void InvalidateLightingCacheDetailed(bool bInvalidateBuildEnqueuedLighting, bool bTranslationOnly)
{
if (bInvalidateBuildEnqueuedLighting)
{// If a static lighting build has been enqueued for this primitive, don't stomp on its visibility ID.
VisibilityId = INDEX_NONE;
}
}
}
class ENGINE_API UStaticMeshComponent : public UMeshComponent {
TArray<FStaticMeshComponentLODInfo> LODData;/** Contains static lighting data along with instanced mesh vertex colors. */
void InvalidateLightingCacheDetailed(bool bInvalidateBuildEnqueuedLighting, bool bTranslationOnly)
{
Modify(true);// Save the static mesh state for transactions
Super::InvalidateLightingCacheDetailed(bInvalidateBuildEnqueuedLighting, bTranslationOnly);
for(int32 i = 0; i < LODData.Num(); i++)
{
LODData[i].MapBuildDataId.Invalidate(); // = 0;
}
MarkRenderStateDirty();
}
}
class ENGINE_API ULightComponentBase : public USceneComponent {
/**
* GUID used to associate a light component with precomputed shadowing information across levels.
* The GUID changes whenever the light position changes.
*/
FGuid LightGuid;
}
void ULightComponent::InvalidateLightingCacheDetailed(bool bInvalidateBuildEnqueuedLighting, bool bTranslationOnly)
{
if (Mobility != EComponentMobility::Movable)
{
Modify();// Save the light state for transactions.
BeginReleaseResource(&StaticShadowDepthMap);
LightGuid = FGuid::NewGuid();
MarkRenderStateDirty();
}
else
{
LightGuid.Invalidate(); // = 0;
}
if (GIsEditor
&& GetWorld() != NULL
&& Mobility == EComponentMobility::Stationary)
{
ReassignStationaryLightChannels(GetWorld(), false, NULL);
}
}
void UDirectionalLightComponent::InvalidateLightingCacheDetailed(bool bInvalidateBuildEnqueuedLighting, bool bTranslationOnly)
{
if (!bTranslationOnly)// Directional lights don't care about translation
{
Super::InvalidateLightingCacheDetailed(bInvalidateBuildEnqueuedLighting, bTranslationOnly);
}
}