diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md index 209c72f..77a55fa 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md @@ -41,17 +41,36 @@ if(PrimitiveSceneinfo->Proxy->IsToonDisableSelfShadow()) { const FViewInfo& View = Views[ViewIndex]; const FMatrix& ViewMatrix = View.ShadowViewMatrices.GetViewMatrix() - FVector LightDirection = Lightsceneinfo->Proxy- GetDirection(); - const FVector CameraDirection = ViewMatrix.GetColumn(2).GetSafeNonmal() + FVector LightDirection = Lightsceneinfo->Proxy->GetDirection(); + const FVector CameraDirection = ViewMatrix.GetColumn(2).GetSafeNormal() float LightViewBlendFactor = PrimitiveSceneinfo->Proxy->GetToonHalfVienShadowFactor(); Fvector HalfViewLightDir = (LightDirection + ( 1 - LightViewBlendFactor) + CameraDirection * LightViewBlendFactor).GetSafeNormal(); - FMatrix FinalCombineMatrix = FNnverseRotationMatrix(HalfViewLightDir.Rotation()) - ShadowInitializer.WorldTolight = FinalCombineMatrix; + FMatrix FinalCombineMatrix = FInverseRotationMatrix(HalfViewLightDir.Rotation()) + ShadowInitializer.WorldToLight = FinalCombineMatrix; } ... } ``` +相关代码位于`FDirectionalLightSceneProxy::GetPerObjectProjectedShadowInitializer()`,在在FSceneRenderer::CreatePerObjectProjectedShadow()被调用。 +```c++ +virtual bool GetPerObjectProjectedShadowInitializer(const FBoxSphereBounds& SubjectBounds,FPerObjectProjectedShadowInitializer& OutInitializer) const override + { + OutInitializer.PreShadowTranslation = -SubjectBounds.Origin; + OutInitializer.WorldToLight = FInverseRotationMatrix(FVector(WorldToLight.M[0][0],WorldToLight.M[1][0],WorldToLight.M[2][0]).GetSafeNormal().Rotation()); + OutInitializer.Scales = FVector2D(1.0f / SubjectBounds.SphereRadius,1.0f / SubjectBounds.SphereRadius); + OutInitializer.SubjectBounds = FBoxSphereBounds(FVector::ZeroVector,SubjectBounds.BoxExtent,SubjectBounds.SphereRadius); + OutInitializer.WAxis = FVector4(0,0,0,1); + OutInitializer.MinLightW = -UE_OLD_HALF_WORLD_MAX; + // Reduce casting distance on a directional light + // This is necessary to improve floating point precision in several places, especially when deriving frustum verts from InvReceiverMatrix + // This takes the object size into account to ensure that large objects get an extended distance + OutInitializer.MaxDistanceToCastInLightW = FMath::Clamp(SubjectBounds.SphereRadius * CVarPerObjectCastDistanceRadiusScale.GetValueOnRenderThread(), CVarPerObjectCastDistanceMin.GetValueOnRenderThread(), (float)WORLD_MAX); + + return true; + } +``` + PS.很有可能需要创建2个Atlas。Atlas的创建位于***FSceneRenderer::AllocateCachedShadowDepthTargets()***。数据存储在***SortedShadowsForShadowDepthPass.ShadowMapAtlases***中。大致由FSceneRenderer::FinishInitDynamicShadows()调用。 **阴影Projection阶段**: