Payback 0.0.1
CK Graduation Project
로딩중...
검색중...
일치하는것 없음
UToonLightingComponent 클래스 참조

#include <ToonLightingComponent.h>

UToonLightingComponent에 대한 상속 다이어그램 :
Inheritance graph
UToonLightingComponent에 대한 협력 다이어그램:
Collaboration graph

클래스

struct  FLocalLightCandidate
 

Public 멤버 함수

 UToonLightingComponent ()
 

Protected 멤버 함수

virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 

Protected 속성

bool bApplyToonShadeToMeshes = true
 
bool bEnableGroundShadow = false
 
TObjectPtr< UMaterialInterface > GroundShadowMaterial
 
float GroundShadowRadiusScale = 1.5f
 
float GroundShadowLitOpacity = 0.055f
 
float GroundShadowShadeOpacity = 0.2f
 
float GroundShadowFadeHeight = 220.0f
 
float ReferenceIlluminance = 0.5f
 
float LocalLightInfluence = 0.125f
 
float DirectionalTraceDistance = 20000.0f
 
float TransitionSeconds = 0.4f
 
float CurrentShadeAmount = 0.0f
 

Private 멤버 함수

void UpdateGroundShadow (float ShadeAmount)
 
void DestroyGroundShadow ()
 
bool ResolveSamplingReference ()
 
void RefreshTrackedComponents ()
 
void SampleLighting ()
 
void UpdateShadeAmount ()
 
void SmoothShadeAmount (float DeltaSeconds)
 
void ApplyShadeAmount (float Value)
 
bool IsUsableLight (const ULightComponent *Light) const
 
float EstimateContribution (const ULightComponent *Light, const FVector &Position) const
 
bool IsLightVisible (const ULightComponent *Light, const FVector &Position) const
 

정적 Private 멤버 함수

static bool IsProfilingPaused ()
 

Private 속성

TObjectPtr< UDecalComponent > GroundShadowDecal
 
TObjectPtr< UMaterialInstanceDynamic > GroundShadowMID
 
TWeakObjectPtr< UCapsuleComponent > Capsule
 
TWeakObjectPtr< UMeshComponent > CharacterMesh
 
TArray< TWeakObjectPtr< UMeshComponent > > Meshes
 
TArray< TWeakObjectPtr< ULightComponent > > Lights
 
FTimerHandle RefreshTimer
 
FTimerHandle SampleTimer
 
FTimerHandle SmoothingTimer
 
float TargetShadeAmount = 0.0f
 
double LastUpdateTime = 0.0
 
bool bFoundLight = false
 

생성자 & 소멸자 문서화

◆ UToonLightingComponent()

UToonLightingComponent::UToonLightingComponent ( )
35{
36#if WITH_EDITOR
37 PrimaryComponentTick.bCanEverTick = true;
38 PrimaryComponentTick.bStartWithTickEnabled = false;
39 PrimaryComponentTick.TickInterval = 0.1f;
40 bTickInEditor = true;
41#else
42 PrimaryComponentTick.bCanEverTick = false;
43#endif
44}

멤버 함수 문서화

◆ ApplyShadeAmount()

void UToonLightingComponent::ApplyShadeAmount ( float  Value)
private
459{
460 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_ApplyCPD);
461 UpdateGroundShadow(Value);
462 if (bApplyToonShadeToMeshes == false)
463 {
464 return;
465 }
466 for (const TWeakObjectPtr<UMeshComponent>& MeshPtr : Meshes)
467 {
468 if (UMeshComponent* Mesh = MeshPtr.Get())
469 {
470 // ToonShadeAmount의 CPD 인덱스. MID와 슬롯별 툰 설정은 변경하지 않는다.
471 Mesh->SetCustomPrimitiveDataFloat(0, Value);
472 }
473 }
474}
bool bApplyToonShadeToMeshes
Definition ToonLightingComponent.h:36
TArray< TWeakObjectPtr< UMeshComponent > > Meshes
Definition ToonLightingComponent.h:109
void UpdateGroundShadow(float ShadeAmount)
Definition ToonLightingComponent.cpp:487

다음을 참조함 : bApplyToonShadeToMeshes, Meshes, UpdateGroundShadow().

다음에 의해서 참조됨 : BeginPlay(), EndPlay(), RefreshTrackedComponents(), SmoothShadeAmount().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ BeginPlay()

void UToonLightingComponent::BeginPlay ( )
overrideprotectedvirtual
122{
123 Super::BeginPlay();
124#if WITH_EDITOR
125 SetComponentTickEnabled(false);
126#endif
127 UWorld* World = GetWorld();
128 if (World == nullptr || World->GetNetMode() == NM_DedicatedServer || GetOwner() == nullptr)
129 {
130 return;
131 }
136 LastUpdateTime = World->GetTimeSeconds();
137 World->GetTimerManager().SetTimer(RefreshTimer, this, &ThisClass::RefreshTrackedComponents, 1.5f, true);
138 World->GetTimerManager().SetTimer(SampleTimer, this, &ThisClass::SampleLighting, 0.1f, true);
139 World->GetTimerManager().SetTimer(SmoothingTimer, this, &ThisClass::UpdateShadeAmount, 0.05f, true);
140}
void ApplyShadeAmount(float Value)
Definition ToonLightingComponent.cpp:458
double LastUpdateTime
Definition ToonLightingComponent.h:115
void RefreshTrackedComponents()
Definition ToonLightingComponent.cpp:189
FTimerHandle RefreshTimer
Definition ToonLightingComponent.h:111
float CurrentShadeAmount
Definition ToonLightingComponent.h:74
FTimerHandle SampleTimer
Definition ToonLightingComponent.h:112
float TargetShadeAmount
Definition ToonLightingComponent.h:114
FTimerHandle SmoothingTimer
Definition ToonLightingComponent.h:113
void SampleLighting()
Definition ToonLightingComponent.cpp:332

다음을 참조함 : ApplyShadeAmount(), CurrentShadeAmount, LastUpdateTime, RefreshTimer, RefreshTrackedComponents(), SampleLighting(), SampleTimer, SmoothingTimer, TargetShadeAmount.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ DestroyGroundShadow()

void UToonLightingComponent::DestroyGroundShadow ( )
private
478{
479 GroundShadowMID = nullptr;
481 {
482 GroundShadowDecal->DestroyComponent();
483 GroundShadowDecal = nullptr;
484 }
485}
TObjectPtr< UMaterialInstanceDynamic > GroundShadowMID
Definition ToonLightingComponent.h:95
TObjectPtr< UDecalComponent > GroundShadowDecal
Definition ToonLightingComponent.h:92

다음을 참조함 : GroundShadowDecal, GroundShadowMID.

다음에 의해서 참조됨 : EndPlay(), UpdateGroundShadow().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ EndPlay()

void UToonLightingComponent::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual
143{
144 if (UWorld* World = GetWorld())
145 {
146 World->GetTimerManager().ClearTimer(RefreshTimer);
147 World->GetTimerManager().ClearTimer(SampleTimer);
148 World->GetTimerManager().ClearTimer(SmoothingTimer);
149 }
150 ApplyShadeAmount(0.0f);
151 Meshes.Reset();
152 Lights.Reset();
154 Super::EndPlay(EndPlayReason);
155}
void DestroyGroundShadow()
Definition ToonLightingComponent.cpp:477
TArray< TWeakObjectPtr< ULightComponent > > Lights
Definition ToonLightingComponent.h:110

다음을 참조함 : ApplyShadeAmount(), DestroyGroundShadow(), Lights, Meshes, RefreshTimer, SampleTimer, SmoothingTimer.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ EstimateContribution()

float UToonLightingComponent::EstimateContribution ( const ULightComponent *  Light,
const FVector &  Position 
) const
private
239{
240 if (IsUsableLight(Light) == false)
241 {
242 return 0.0f;
243 }
244 const float Brightness = Light->ComputeLightBrightness() * Light->GetLightColor().GetLuminance();
245 if (FMath::IsFinite(Brightness) == false || (Brightness > 0.0f) == false)
246 {
247 return 0.0f;
248 }
249 if (Cast<UDirectionalLightComponent>(Light))
250 {
251 return Brightness;
252 }
253 const ULocalLightComponent* Local = Cast<ULocalLightComponent>(Light);
254 if (Local == nullptr || Local->AttenuationRadius < KINDA_SMALL_NUMBER)
255 {
256 return 0.0f;
257 }
258 const FVector FromLight = Position - Light->GetComponentLocation();
259 const float DistanceSquared = FromLight.SizeSquared();
260 const float NormalizedDistanceSquared = DistanceSquared / FMath::Square(Local->AttenuationRadius);
261 if (NormalizedDistanceSquared >= 1.0f)
262 {
263 return 0.0f;
264 }
265 // 엔진의 반경 마스크와 cm 단위 밝기를 사용하며, 광원 근처의 급증은 1m에서 제한한다.
266 float Attenuation = FMath::Square(FMath::Clamp(1.0f - FMath::Square(NormalizedDistanceSquared), 0.0f, 1.0f))
267 / FMath::Max(DistanceSquared, 10000.0f);
268 if (const UPointLightComponent* Point = Cast<UPointLightComponent>(Light))
269 {
270 if (Point->bUseInverseSquaredFalloff == false)
271 {
272 Attenuation = FMath::Pow(1.0f - NormalizedDistanceSquared, FMath::Max(Point->LightFalloffExponent, 0.0f));
273 }
274 }
275 const float Facing = FVector::DotProduct(FromLight.GetSafeNormal(), Light->GetDirection());
276 if (const USpotLightComponent* Spot = Cast<USpotLightComponent>(Light))
277 {
278 const FVector2f Cone = Spot->GetClampedConeAngles();
279 const float OuterCos = FMath::Cos(Cone.Y);
280 const float ConeRange = FMath::Max(FMath::Cos(Cone.X) - OuterCos, SMALL_NUMBER);
281 Attenuation *= FMath::Square(FMath::Clamp((Facing - OuterCos) / ConeRange, 0.0f, 1.0f));
282 }
283 else if (Cast<URectLightComponent>(Light))
284 {
285 Attenuation *= FMath::Max(Facing, 0.0f);
286 }
287 return Brightness * Attenuation;
288}
bool IsUsableLight(const ULightComponent *Light) const
Definition ToonLightingComponent.cpp:220

다음을 참조함 : IsUsableLight().

다음에 의해서 참조됨 : SampleLighting().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsLightVisible()

bool UToonLightingComponent::IsLightVisible ( const ULightComponent *  Light,
const FVector &  Position 
) const
private
291{
292 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_Visibility);
293 if (Light->CastShadows == false)
294 {
295 return true;
296 }
297 UWorld* World = GetWorld();
298 if (World == nullptr)
299 {
300 return false;
301 }
302 const FVector End = Cast<UDirectionalLightComponent>(Light)
303 ? Position - Light->GetDirection() * FMath::Max(DirectionalTraceDistance, 1.0f)
304 : Light->GetComponentLocation();
305 FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(ToonLighting), true, GetOwner());
306 if (AActor* Owner = GetOwner())
307 {
308 TArray<AActor*> AttachedActors;
309 Owner->GetAttachedActors(AttachedActors, true, true);
310 QueryParams.AddIgnoredActors(AttachedActors);
311 }
312 FCollisionObjectQueryParams ObjectParams;
313 ObjectParams.AddObjectTypesToQuery(ECC_WorldStatic);
314 ObjectParams.AddObjectTypesToQuery(ECC_WorldDynamic);
315 ObjectParams.AddObjectTypesToQuery(ECC_PhysicsBody);
316 TArray<FHitResult> Hits;
317 {
318 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_CollisionTrace);
319 World->LineTraceMultiByObjectType(Hits, Position, End, ObjectParams, QueryParams);
320 }
321 for (const FHitResult& Hit : Hits)
322 {
323 const UPrimitiveComponent* HitComponent = Hit.GetComponent();
324 if (HitComponent && HitComponent->CastShadow && (HitComponent->ShouldRender() || HitComponent->bCastHiddenShadow))
325 {
326 return false;
327 }
328 }
329 return true;
330}
float DirectionalTraceDistance
Definition ToonLightingComponent.h:67

다음을 참조함 : DirectionalTraceDistance, End.

다음에 의해서 참조됨 : SampleLighting().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsProfilingPaused()

bool UToonLightingComponent::IsProfilingPaused ( )
staticprivate
24{
25 // 성능 비교 중 CPD를 고정하고 계산만 중단한다. 기본 동작에는 영향이 없다.
26 static TAutoConsoleVariable<int32> ProfilePause(
27 TEXT("ck.ToonLighting.ProfilePause"), 0,
28 TEXT("Freeze toon lighting calculations for CPU profiling; preserves current CPD. 0 = normal, 1 = paused."),
29 ECVF_Cheat);
30 return ProfilePause.GetValueOnGameThread() > 0;
31}

다음에 의해서 참조됨 : RefreshTrackedComponents(), SampleLighting(), UpdateShadeAmount().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsUsableLight()

bool UToonLightingComponent::IsUsableLight ( const ULightComponent *  Light) const
private
221{
222 const UMeshComponent* Mesh = CharacterMesh.Get();
223 if (IsValid(Light) == false || Mesh == nullptr || Light->GetWorld() != GetWorld()
224 || Light->IsRegistered() == false || Light->ShouldRender() == false || Light->bAffectsWorld == false)
225 {
226 return false;
227 }
228 // EV에서는 0이나 음수도 유효한 광량이므로 엔진과 같은 활성 조건을 사용한다.
229 const bool bHasIntensity = Light->Intensity > 0.0f || Light->GetLightUnits() == ELightUnits::EV;
230 const bool bSupported = Cast<UDirectionalLightComponent>(Light) || Cast<UPointLightComponent>(Light) || Cast<URectLightComponent>(Light);
231 const float Brightness = Light->ComputeLightBrightness() * Light->GetLightColor().GetLuminance();
232 const FLightingChannels& A = Light->LightingChannels;
233 const FLightingChannels& B = Mesh->LightingChannels;
234 return bSupported && bHasIntensity && FMath::IsFinite(Brightness) && Brightness > 0.0f
235 && ((A.bChannel0 && B.bChannel0) || (A.bChannel1 && B.bChannel1) || (A.bChannel2 && B.bChannel2));
236}
TWeakObjectPtr< UMeshComponent > CharacterMesh
Definition ToonLightingComponent.h:108

다음을 참조함 : CharacterMesh.

다음에 의해서 참조됨 : EstimateContribution(), SampleLighting().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ RefreshTrackedComponents()

void UToonLightingComponent::RefreshTrackedComponents ( )
private
190{
191#if !UE_BUILD_SHIPPING
192 if (IsProfilingPaused())
193 {
194 return;
195 }
196#endif
197 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_Refresh);
199 Lights.Reset();
200 for (TObjectIterator<ULightComponent> It; It; ++It)
201 {
202 if (It->GetWorld() == GetWorld() && It->IsRegistered())
203 {
204 Lights.Add(*It);
205 }
206 }
207 Meshes.Reset();
208 if (AActor* Owner = GetOwner())
209 {
210 TArray<UMeshComponent*> OwnerMeshes;
211 Owner->GetComponents(OwnerMeshes);
212 for (UMeshComponent* Mesh : OwnerMeshes)
213 {
214 Meshes.Add(Mesh);
215 }
216 }
218}
static bool IsProfilingPaused()
Definition ToonLightingComponent.cpp:23
bool ResolveSamplingReference()
Definition ToonLightingComponent.cpp:157

다음을 참조함 : ApplyShadeAmount(), CurrentShadeAmount, IsProfilingPaused(), Lights, Meshes, ResolveSamplingReference().

다음에 의해서 참조됨 : BeginPlay().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ResolveSamplingReference()

bool UToonLightingComponent::ResolveSamplingReference ( )
private
158{
159 Capsule.Reset();
160 CharacterMesh.Reset();
161 if (const ACharacter* Character = Cast<ACharacter>(GetOwner()))
162 {
163 if (Character->GetCapsuleComponent() == nullptr || Character->GetMesh() == nullptr
164 || Character->GetCapsuleComponent()->IsRegistered() == false || Character->GetMesh()->IsRegistered() == false)
165 {
166 return false;
167 }
168 Capsule = Character->GetCapsuleComponent();
169 CharacterMesh = Character->GetMesh();
170 return true;
171 }
172 if (AActor* Owner = GetOwner())
173 {
174 TArray<UMeshComponent*> OwnerMeshes;
175 Owner->GetComponents(OwnerMeshes);
176 for (UMeshComponent* Mesh : OwnerMeshes)
177 {
178 // 일반 액터는 본체로 명시한 메시만 사용한다. 장식/외곽선으로 대체하지 않는다.
179 if (Mesh && Mesh->IsRegistered() && Mesh->ComponentHasTag(TEXT("ToonLightingReference")))
180 {
181 CharacterMesh = Mesh;
182 return true;
183 }
184 }
185 }
186 return false;
187}
TWeakObjectPtr< UCapsuleComponent > Capsule
Definition ToonLightingComponent.h:107

다음을 참조함 : Capsule, CharacterMesh.

다음에 의해서 참조됨 : RefreshTrackedComponents().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ SampleLighting()

void UToonLightingComponent::SampleLighting ( )
private
333{
334#if !UE_BUILD_SHIPPING
335 if (IsProfilingPaused())
336 {
337 return;
338 }
339#endif
340 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_Sample);
341 // 풀에 반환된 접지 전용 컴포넌트는 불필요한 광원 추적을 하지 않는다.
342 if (bApplyToonShadeToMeshes == false && (GetOwner() == nullptr || GetOwner()->IsHidden()))
343 {
344 TargetShadeAmount = 0.0f;
345 return;
346 }
347 const UCapsuleComponent* SampleCapsule = Capsule.Get();
348 FVector Center;
349 FVector Offset;
350 if (SampleCapsule)
351 {
352 Center = SampleCapsule->GetComponentLocation();
353 Offset = SampleCapsule->GetUpVector() * SampleCapsule->GetScaledCapsuleHalfHeight() * 0.6f;
354 }
355 else
356 {
357 const UMeshComponent* SampleMesh = CharacterMesh.Get();
358 if (SampleMesh == nullptr || SampleMesh->IsRegistered() == false || Cast<ACharacter>(GetOwner()))
359 {
360 TargetShadeAmount = 0.0f;
361 return;
362 }
363 // 월드 bounds 중심을 기준으로 일반 액터의 상하 3점을 샘플링한다.
364 Center = SampleMesh->GetBounds().Origin;
365 Offset = FVector::UpVector * SampleMesh->GetBounds().BoxExtent.Z * 0.6f;
366 }
367 const FVector Samples[] = { Center - Offset, Center, Center + Offset };
368 const int32 SampleCount = bApplyToonShadeToMeshes ? 3 : 1;
369 ULightComponent* Directional = nullptr;
370 float DirectionalContribution = 0.0f;
371 TArray<FLocalLightCandidate> LocalCandidates;
372 for (const TWeakObjectPtr<ULightComponent>& LightPtr : Lights)
373 {
374 ULightComponent* Light = LightPtr.Get();
375 if (IsUsableLight(Light) == false)
376 {
377 continue;
378 }
379 bFoundLight = true;
380 if (Cast<UDirectionalLightComponent>(Light))
381 {
382 const float Contribution = EstimateContribution(Light, Center);
383 if (Contribution > DirectionalContribution)
384 {
385 Directional = Light;
386 DirectionalContribution = Contribution;
387 }
388 continue;
389 }
390 float Contribution = 0.0f;
391 for (int32 SampleIndex = 0; SampleIndex < SampleCount; ++SampleIndex)
392 {
393 const FVector& Position = Samples[SampleIndex];
394 Contribution = FMath::Max(Contribution, EstimateContribution(Light, Position));
395 }
396 if (Contribution > 0.0f)
397 {
398 LocalCandidates.Add({ Light, Contribution });
399 }
400 }
401 LocalCandidates.Sort([](const FLocalLightCandidate& A, const FLocalLightCandidate& B)
402 {
403 return A.Contribution > B.Contribution;
404 });
405 const float Reference = FMath::Max(ReferenceIlluminance, 0.001f);
406 const float LocalLightWeight = FMath::Clamp(LocalLightInfluence, 0.0f, 1.0f);
407 float Exposure = 0.0f;
408 for (int32 SampleIndex = 0; SampleIndex < SampleCount; ++SampleIndex)
409 {
410 const FVector& Position = Samples[SampleIndex];
411 float VisibleContribution = 0.0f;
412 if (Directional && IsLightVisible(Directional, Position))
413 {
414 VisibleContribution = DirectionalContribution;
415 }
416 for (int32 Index = 0; Index < FMath::Min(LocalCandidates.Num(), 3) && VisibleContribution < Reference; ++Index)
417 {
418 ULightComponent* Light = LocalCandidates[Index].Light.Get();
419 const float Contribution = EstimateContribution(Light, Position) * LocalLightWeight;
420 if (Contribution > 0.0f && IsLightVisible(Light, Position))
421 {
422 VisibleContribution += Contribution;
423 }
424 }
425 Exposure += FMath::Clamp(VisibleContribution / Reference, 0.0f, 1.0f);
426 }
427 // 직접광을 한 번도 찾지 못한 Skylight/Lumen 전용 구성은 기존 밝기를 유지한다.
428 TargetShadeAmount = bFoundLight ? 1.0f - Exposure / SampleCount : 0.0f;
429}
bool IsLightVisible(const ULightComponent *Light, const FVector &Position) const
Definition ToonLightingComponent.cpp:290
bool bFoundLight
Definition ToonLightingComponent.h:116
float EstimateContribution(const ULightComponent *Light, const FVector &Position) const
Definition ToonLightingComponent.cpp:238
float LocalLightInfluence
Definition ToonLightingComponent.h:64
float ReferenceIlluminance
Definition ToonLightingComponent.h:60

다음을 참조함 : bApplyToonShadeToMeshes, bFoundLight, Capsule, CharacterMesh, UToonLightingComponent::FLocalLightCandidate::Contribution, EstimateContribution(), IsLightVisible(), IsProfilingPaused(), IsUsableLight(), Lights, LocalLightInfluence, ReferenceIlluminance, TargetShadeAmount.

다음에 의해서 참조됨 : BeginPlay().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ SmoothShadeAmount()

void UToonLightingComponent::SmoothShadeAmount ( float  DeltaSeconds)
private
452{
453 const float Alpha = 1.0f - FMath::Exp(-FMath::Loge(10.0f) * FMath::Max(DeltaSeconds, 0.0f) / FMath::Max(TransitionSeconds, 0.01f));
454 CurrentShadeAmount = FMath::Clamp(FMath::Lerp(CurrentShadeAmount, TargetShadeAmount, Alpha), 0.0f, 1.0f);
456}
float TransitionSeconds
Definition ToonLightingComponent.h:71

다음을 참조함 : ApplyShadeAmount(), CurrentShadeAmount, TargetShadeAmount, TransitionSeconds.

다음에 의해서 참조됨 : UpdateShadeAmount().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ UpdateGroundShadow()

void UToonLightingComponent::UpdateGroundShadow ( float  ShadeAmount)
private

기존 20Hz 평활 갱신을 재사용하여 바닥 위치와 접지 음영을 갱신한다.

488{
489 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_GroundShadow);
490 UWorld* World = GetWorld();
491 const ACharacter* Character = Cast<ACharacter>(GetOwner());
492 if (bEnableGroundShadow == false || GroundShadowMaterial == nullptr || Character == nullptr
493 || World == nullptr || World->GetNetMode() == NM_DedicatedServer)
494 {
496 return;
497 }
498
499 const UCapsuleComponent* CharacterCapsule = Character->GetCapsuleComponent();
500 if (Character->IsHidden() || CharacterCapsule == nullptr || Character->GetMesh() == nullptr
501 || Character->GetMesh()->IsVisible() == false)
502 {
504 {
505 GroundShadowDecal->SetVisibility(false);
506 }
507 return;
508 }
509
510 const FVector Center = CharacterCapsule->GetComponentLocation();
511 const FVector Feet = Center - FVector::UpVector * CharacterCapsule->GetScaledCapsuleHalfHeight();
512 const float FadeHeight = FMath::Max(GroundShadowFadeHeight, 10.0f);
513 FCollisionQueryParams Query(SCENE_QUERY_STAT(GroundContactShadow), true, Character);
514 TArray<AActor*> AttachedActors;
515 Character->GetAttachedActors(AttachedActors, true, true);
516 Query.AddIgnoredActors(AttachedActors);
517 FCollisionObjectQueryParams Objects;
518 Objects.AddObjectTypesToQuery(ECC_WorldStatic);
519 Objects.AddObjectTypesToQuery(ECC_WorldDynamic);
520 Objects.AddObjectTypesToQuery(ECC_PhysicsBody);
521 TArray<FHitResult> Hits;
522 World->LineTraceMultiByObjectType(Hits, Center, Feet - FVector::UpVector * FadeHeight, Objects, Query);
523 const FHitResult* Floor = nullptr;
524 for (const FHitResult& Hit : Hits)
525 {
526 const UPrimitiveComponent* Surface = Hit.GetComponent();
527 // 캐릭터나 무기 위에 투영하지 않고, 밟을 수 있는 위쪽 면만 받는다.
528 if (Hit.bStartPenetrating == false && Hit.ImpactNormal.Z > 0.5f && Surface
529 && Surface->ShouldRender() && Surface->bReceivesDecals
530 && Surface->GetCollisionResponseToChannel(ECC_Pawn) == ECR_Block
531 && Cast<APawn>(Hit.GetActor()) == nullptr && Cast<APawn>(Surface->GetAttachmentRootActor()) == nullptr)
532 {
533 Floor = &Hit;
534 break;
535 }
536 }
537
538 if (Floor == nullptr)
539 {
541 {
542 GroundShadowDecal->SetVisibility(false);
543 }
544 return;
545 }
546
547 if (GroundShadowDecal == nullptr)
548 {
549 // 액터 저장 데이터에 포함하지 않는 시각 효과. 기존 조명 타이머와 생명주기를 공유한다.
550 GroundShadowDecal = NewObject<UDecalComponent>(GetOwner(), NAME_None, RF_Transient);
551 GroundShadowDecal->ComponentTags.Add(TEXT("GroundContactShadow"));
552 GroundShadowDecal->SetupAttachment(GetOwner()->GetRootComponent());
553 GroundShadowDecal->SetAbsolute(true, true, true);
554 GroundShadowDecal->DecalSize = FVector::OneVector;
555 GroundShadowDecal->SetVisibility(false);
556 GroundShadowDecal->SetDecalMaterial(GroundShadowMaterial);
557 GroundShadowDecal->SetSortOrder(-20);
558 GroundShadowDecal->SetFadeScreenSize(0.001f);
559 GroundShadowDecal->RegisterComponentWithWorld(World);
560 GroundShadowMID = GroundShadowDecal->CreateDynamicMaterialInstance();
561 }
562
563 if (GroundShadowMID == nullptr)
564 {
565 return;
566 }
567
568 const float Height = FMath::Max(Feet.Z - Floor->ImpactPoint.Z - 4.0f, 0.0f);
569 const float HeightRatio = FMath::Clamp(Height / FadeHeight, 0.0f, 1.0f);
570 const float Radius = FMath::Clamp(CharacterCapsule->GetScaledCapsuleRadius() * GroundShadowRadiusScale, 20.0f, 160.0f)
571 * FMath::Lerp(1.0f, 1.65f, HeightRatio);
572 const float Opacity = FMath::Clamp(FMath::Lerp(GroundShadowLitOpacity, GroundShadowShadeOpacity,
573 FMath::Clamp(ShadeAmount, 0.0f, 1.0f)), 0.0f, 0.5f) * FMath::Square(1.0f - HeightRatio);
574 GroundShadowMID->SetScalarParameterValue(TEXT("Darkness"), Opacity);
575 // 얕은 투영 범위와 재질의 수직면 마스크로 벽/아랫층에 번지는 것을 억제한다.
576 GroundShadowDecal->SetWorldScale3D(FVector(12.0f, Radius, Radius));
577 GroundShadowDecal->SetWorldLocationAndRotation(Floor->ImpactPoint + Floor->ImpactNormal * 2.0f,
578 FRotationMatrix::MakeFromX(-Floor->ImpactNormal).Rotator());
579 GroundShadowDecal->SetVisibility(Opacity > KINDA_SMALL_NUMBER);
580}
TObjectPtr< UMaterialInterface > GroundShadowMaterial
Definition ToonLightingComponent.h:43
float GroundShadowFadeHeight
Definition ToonLightingComponent.h:57
float GroundShadowRadiusScale
Definition ToonLightingComponent.h:47
float GroundShadowLitOpacity
Definition ToonLightingComponent.h:50
float GroundShadowShadeOpacity
Definition ToonLightingComponent.h:53
bool bEnableGroundShadow
Definition ToonLightingComponent.h:40

다음을 참조함 : bEnableGroundShadow, DestroyGroundShadow(), GroundShadowDecal, GroundShadowFadeHeight, GroundShadowLitOpacity, GroundShadowMaterial, GroundShadowMID, GroundShadowRadiusScale, GroundShadowShadeOpacity.

다음에 의해서 참조됨 : ApplyShadeAmount().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ UpdateShadeAmount()

void UToonLightingComponent::UpdateShadeAmount ( )
private
432{
433#if !UE_BUILD_SHIPPING
434 if (IsProfilingPaused())
435 {
436 return;
437 }
438#endif
439 TRACE_CPUPROFILER_EVENT_SCOPE(ToonLighting_Update);
440 UWorld* World = GetWorld();
441 if (World == nullptr)
442 {
443 return;
444 }
445 const double Now = World->GetTimeSeconds();
446 const float DeltaSeconds = FMath::Max(static_cast<float>(Now - LastUpdateTime), 0.0f);
447 LastUpdateTime = Now;
448 SmoothShadeAmount(DeltaSeconds);
449}
void SmoothShadeAmount(float DeltaSeconds)
Definition ToonLightingComponent.cpp:451

다음을 참조함 : IsProfilingPaused(), LastUpdateTime, SmoothShadeAmount().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ bApplyToonShadeToMeshes

bool UToonLightingComponent::bApplyToonShadeToMeshes = true
protected

기존 캐릭터 셰이딩을 유지하며 접지 그림자만 계산할 때 끈다.

다음에 의해서 참조됨 : ApplyShadeAmount(), SampleLighting().

◆ bEnableGroundShadow

bool UToonLightingComponent::bEnableGroundShadow = false
protected

발밑 보조 그림자. 거대 보스와 일반 액터는 기본적으로 사용하지 않는다.

다음에 의해서 참조됨 : UpdateGroundShadow().

◆ bFoundLight

bool UToonLightingComponent::bFoundLight = false
private

다음에 의해서 참조됨 : SampleLighting().

◆ Capsule

TWeakObjectPtr<UCapsuleComponent> UToonLightingComponent::Capsule
private

다음에 의해서 참조됨 : ResolveSamplingReference(), SampleLighting().

◆ CharacterMesh

TWeakObjectPtr<UMeshComponent> UToonLightingComponent::CharacterMesh
private

다음에 의해서 참조됨 : IsUsableLight(), ResolveSamplingReference(), SampleLighting().

◆ CurrentShadeAmount

float UToonLightingComponent::CurrentShadeAmount = 0.0f
protected

다음에 의해서 참조됨 : BeginPlay(), RefreshTrackedComponents(), SmoothShadeAmount().

◆ DirectionalTraceDistance

float UToonLightingComponent::DirectionalTraceDistance = 20000.0f
protected

다음에 의해서 참조됨 : IsLightVisible().

◆ GroundShadowDecal

TObjectPtr<UDecalComponent> UToonLightingComponent::GroundShadowDecal
private

다음에 의해서 참조됨 : DestroyGroundShadow(), UpdateGroundShadow().

◆ GroundShadowFadeHeight

float UToonLightingComponent::GroundShadowFadeHeight = 220.0f
protected

이 높이까지 점프할 때 그림자가 넓어지며 사라진다.

다음에 의해서 참조됨 : UpdateGroundShadow().

◆ GroundShadowLitOpacity

float UToonLightingComponent::GroundShadowLitOpacity = 0.055f
protected

다음에 의해서 참조됨 : UpdateGroundShadow().

◆ GroundShadowMaterial

TObjectPtr<UMaterialInterface> UToonLightingComponent::GroundShadowMaterial
protected

다음에 의해서 참조됨 : UpdateGroundShadow().

◆ GroundShadowMID

TObjectPtr<UMaterialInstanceDynamic> UToonLightingComponent::GroundShadowMID
private

다음에 의해서 참조됨 : DestroyGroundShadow(), UpdateGroundShadow().

◆ GroundShadowRadiusScale

float UToonLightingComponent::GroundShadowRadiusScale = 1.5f
protected

충돌 캡슐 반경에 대한 그림자 반경 배율.

다음에 의해서 참조됨 : UpdateGroundShadow().

◆ GroundShadowShadeOpacity

float UToonLightingComponent::GroundShadowShadeOpacity = 0.2f
protected

다음에 의해서 참조됨 : UpdateGroundShadow().

◆ LastUpdateTime

double UToonLightingComponent::LastUpdateTime = 0.0
private

다음에 의해서 참조됨 : BeginPlay(), UpdateShadeAmount().

◆ Lights

TArray<TWeakObjectPtr<ULightComponent> > UToonLightingComponent::Lights
private

다음에 의해서 참조됨 : EndPlay(), RefreshTrackedComponents(), SampleLighting().

◆ LocalLightInfluence

float UToonLightingComponent::LocalLightInfluence = 0.125f
protected

다음에 의해서 참조됨 : SampleLighting().

◆ Meshes

TArray<TWeakObjectPtr<UMeshComponent> > UToonLightingComponent::Meshes
private

다음에 의해서 참조됨 : ApplyShadeAmount(), EndPlay(), RefreshTrackedComponents().

◆ ReferenceIlluminance

float UToonLightingComponent::ReferenceIlluminance = 0.5f
protected

다음에 의해서 참조됨 : SampleLighting().

◆ RefreshTimer

FTimerHandle UToonLightingComponent::RefreshTimer
private

다음에 의해서 참조됨 : BeginPlay(), EndPlay().

◆ SampleTimer

FTimerHandle UToonLightingComponent::SampleTimer
private

다음에 의해서 참조됨 : BeginPlay(), EndPlay().

◆ SmoothingTimer

FTimerHandle UToonLightingComponent::SmoothingTimer
private

다음에 의해서 참조됨 : BeginPlay(), EndPlay().

◆ TargetShadeAmount

float UToonLightingComponent::TargetShadeAmount = 0.0f
private

다음에 의해서 참조됨 : BeginPlay(), SampleLighting(), SmoothShadeAmount().

◆ TransitionSeconds

float UToonLightingComponent::TransitionSeconds = 0.4f
protected

다음에 의해서 참조됨 : SmoothShadeAmount().


이 클래스에 대한 문서화 페이지는 다음의 파일들로부터 생성되었습니다.: