From b404ef4847f1acc7b037224ae02abf2fd11148fc Mon Sep 17 00:00:00 2001 From: BlueRose <378100977@qq.com> Date: Mon, 16 Dec 2024 22:25:20 +0800 Subject: [PATCH 1/2] vault backup: 2024-12-16 22:25:20 --- .../various-complements/histories.json | 2 +- .../渲染功能/阴影控制/ToonShadow.md | 104 +++++------------- 2 files changed, 26 insertions(+), 80 deletions(-) diff --git a/.obsidian/plugins/various-complements/histories.json b/.obsidian/plugins/various-complements/histories.json index c0721db..fc040fe 100644 --- a/.obsidian/plugins/various-complements/histories.json +++ b/.obsidian/plugins/various-complements/histories.json @@ -1 +1 @@ -{"AI动捕优化思路:":{"AI动捕优化思路:":{"currentFile":{"count":1,"lastUpdated":1731243010285}}},"TODO清单":{"TODO清单":{"internalLink":{"count":1,"lastUpdated":1731553316709}}},"CustomThunk":{"CustomThunk":{"internalLink":{"count":1,"lastUpdated":1731555464503}}},"MobileTAA只做两帧混合":{"MobileTAA只做两帧混合":{"currentFile":{"count":1,"lastUpdated":1731557419798}}},"UMG组件作用笔记":{"UMG组件作用笔记":{"internalLink":{"count":1,"lastUpdated":1731557505574}}},"SequoiaCamShotEvalTemplate":{"SequoiaCamShotEvalTemplate":{"currentFile":{"count":1,"lastUpdated":1732609264076}}},"c++内存泄漏分析工具":{"c++内存泄漏分析工具":{"internalLink":{"count":1,"lastUpdated":1733137754779}}},"Lights":{"Lights":{"currentFile":{"count":1,"lastUpdated":1733637911876}}}} \ No newline at end of file +{"SequoiaCamShotEvalTemplate":{"SequoiaCamShotEvalTemplate":{"currentFile":{"count":1,"lastUpdated":1732609264076}}},"c++内存泄漏分析工具":{"c++内存泄漏分析工具":{"internalLink":{"count":1,"lastUpdated":1733137754779}}},"Lights":{"Lights":{"currentFile":{"count":1,"lastUpdated":1733637911876}}},"渲染屏幕空间阴影遮罩,并用于光照计算。":{"渲染屏幕空间阴影遮罩,并用于光照计算。":{"currentFile":{"count":1,"lastUpdated":1734354537396}}}} \ No newline at end of file diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md index 810abe0..0ae3548 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md @@ -210,13 +210,17 @@ void FSceneRenderer::InitDynamicShadows(FRHICommandListImmediate& RHICmdList, FG 1. UnbatchedLights 1. ShadowProjectionOnOpaque # ShadowDepths +渲染阴影深度贴图与图集。 + - FSceneRenderer::RenderShadowDepthMaps():位于CustomDepth之前。 - - **RenderVirtualShadowMaps()** - - RenderShadowDepthMapAtlases() + - RenderVirtualShadowMaps() + - ***RenderShadowDepthMapAtlases()*** - SortedShadowsForShadowDepthPass.ShadowMapCubemaps循环。渲染点光源阴影立方体图 - **FProjectedShadowInfo::RenderDepth()** - **FProjectedShadowInfo::RenderTranslucencyDepths** +RenderShadowDepthMapAtlases() 渲染的图集位于***FSceneRenderer::SortedShadowsForShadowDepthPass.ShadowMapAtlases*** + ## RenderDepth MeshDrawProcessor为***FShadowDepthPassMeshProcessor***。渲染的Shader为***ShadowDepthPixelShader.usf*** ```c++ @@ -753,84 +757,10 @@ void Main( #endif } ``` -# Lights -### Shader -ShadowProjectionPixelShader.usf -- TShadowProjectionPS: -- TDirectionalPercentageCloserShadowProjectionPS:方向光投影 -- TSpotPercentageCloserShadowProjectionPS:SpotLight -- FOnePassPointShadowProjectionPS(Moible?) - -### 相关函数 -- FDeferredShadingSceneRenderer::RenderLights() - - FDeferredShadingSceneRenderer::RenderDeferredShadowProjections() - - FSceneRenderer::RenderShadowProjections() - - FProjectedShadowInfo::SetupFrustumForProjection():构建阴影投影4棱椎平面信息。 - - FProjectedShadowInfo::SetupProjectionStencilMask(): - -## 其他 -顺序: -RenderCustomDepthPass - -FSceneRenderer::CreateDynamicShadows -=> -FSceneRenderer::CreatePerObjectProjectedShadow - -```c++ -if (!IsForwardShadingEnabled(ShaderPlatform)) -{ - // Dynamic shadows are synced later when using the deferred path to make more headroom for tasks. - FinishInitDynamicShadows(GraphBuilder, InitViewTaskDatas.DynamicShadows, InstanceCullingManager, ExternalAccessQueue); -} -``` - -```c++ -if (RendererOutput == ERendererOutput::DepthPrepassOnly) - { - RenderOcclusionLambda(); - - if (bUpdateNaniteStreaming) - { - Nanite::GStreamingManager.SubmitFrameStreamingRequests(GraphBuilder); - } - - CopySceneCaptureComponentToTarget(GraphBuilder, SceneTextures, ViewFamilyTexture, ViewFamily, Views); - } - else - { - GVRSImageManager.PrepareImageBasedVRS(GraphBuilder, ViewFamily, SceneTextures); - - if (!IsForwardShadingEnabled(ShaderPlatform)) - { - // Dynamic shadows are synced later when using the deferred path to make more headroom for tasks. - FinishInitDynamicShadows(GraphBuilder, InitViewTaskDatas.DynamicShadows, InstanceCullingManager, ExternalAccessQueue); - } - - // Update groom only visible in shadow - if (IsHairStrandsEnabled(EHairStrandsShaderType::All, Scene->GetShaderPlatform()) && RendererOutput == ERendererOutput::FinalSceneColor) - { - UpdateHairStrandsBookmarkParameters(Scene, Views, HairStrandsBookmarkParameters); - - // Interpolation for cards/meshes only visible in shadow needs to happen after the shadow jobs are completed - const bool bRunHairStrands = HairStrandsBookmarkParameters.HasInstances() && (Views.Num() > 0); - if (bRunHairStrands) - { - RunHairStrandsBookmark(GraphBuilder, EHairStrandsBookmark::ProcessCardsAndMeshesInterpolation_ShadowView, HairStrandsBookmarkParameters); - } - } - - // NOTE: The ordering of the lights is used to select sub-sets for different purposes, e.g., those that support clustered deferred. - FSortedLightSetSceneInfo& SortedLightSet = *GraphBuilder.AllocObject(); - { - RDG_CSV_STAT_EXCLUSIVE_SCOPE(GraphBuilder, SortLights); - RDG_GPU_STAT_SCOPE(GraphBuilder, SortLights); - ComputeLightGridOutput = GatherLightsAndComputeLightGrid(GraphBuilder, bComputeLightGrid, SortedLightSet); - } -``` - - # RenderLights +渲染ScreenShadowMask,并用于光照计算。 + FDeferredShadingSceneRenderer::RenderLights() => RDG_EVENT_SCOPE(GraphBuilder, "UnbatchedLights");//batchedLights为没有LightFunction与没有阴影的灯光。 @@ -901,6 +831,20 @@ void FDeferredShadingSceneRenderer::RenderDeferredShadowProjections( RenderShadowProjections(): 1. 取得当前FVisibleLightInfo、FLightSceneProxy;创建FProjectedShadowInfoArray DistanceFieldShadows、NormalShadows。 2. 遍历VisibleLightInfo.ShadowsToProject,按照阴影特征将每个FProjectedShadowInfo加入DistanceFieldShadows、NormalShadows。 +3. 调用FSceneRenderer::RenderShadowProjections()渲染ScreenShadowMask。 + +FSceneRenderer::RenderShadowProjections() +1. 初始化UniformStruct变量。 +2. 遍历传入的FProjectedShadowInfo数组,并调用**ProjectedShadowInfo->RenderProjection()** 将所有灯光的阴影Mask绘制到一张ScreenShadowMask上。 + 1. 在TShadowProjectionPS中通过SetParameters() => ProjectionParameters.Set(),来设置ShadowDepthTextureValue。`ShadowDepthTextureValue = ShadowInfo->RenderTargets.DepthTarget->GetRHI();` + +### Shader +ShadowProjectionPixelShader.usf + + +- ShadowProjectionCommon.ush + - ShadowDepthTexture + - ShadowDepthCubeTexture # 半程阴影 由晨风&Neverwind提出: @@ -947,9 +891,11 @@ PS.很有可能需要创建2个Atlas。Atlas的创建位于***FSceneRenderer::Al //此阶段需要屏蔽角色投射到自己的非半程阴影 //和角色投射到场景中会跟随视角移动的阴影 ```c++ -if(Toon材质,且没有程阴影Flag的阴影 +if(Toon材质,且没有半程阴影Flag的阴影 &&非Toon材质但有半程阴影Flag的阴影) { 屏蔽此阴影 } ``` + +PS.很有可能在FProjectedShadowInfo::RenderProjection()阶段进行判断以此保证合成正确的**ScreenShadowMask**。 \ No newline at end of file From 4b8434099a9ce760d37b888b99af18488cedad6b Mon Sep 17 00:00:00 2001 From: BlueRose <378100977@qq.com> Date: Tue, 17 Dec 2024 00:14:17 +0800 Subject: [PATCH 2/2] vault backup: 2024-12-17 00:14:17 --- .../渲染功能/阴影控制/ToonShadow.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md index 0ae3548..f815533 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md @@ -219,7 +219,7 @@ void FSceneRenderer::InitDynamicShadows(FRHICommandListImmediate& RHICmdList, FG - **FProjectedShadowInfo::RenderDepth()** - **FProjectedShadowInfo::RenderTranslucencyDepths** -RenderShadowDepthMapAtlases() 渲染的图集位于***FSceneRenderer::SortedShadowsForShadowDepthPass.ShadowMapAtlases*** +RenderShadowDepthMapAtlases() 渲染的图集位于***FSceneRenderer::SortedShadowsForShadowDepthPass.ShadowMapAtlases*** (ShadowMapAtlases.RenderTargets.DepthTarget为深度,ShadowMapAtlases.Shadows 为FProjectedShadowInfo) ## RenderDepth MeshDrawProcessor为***FShadowDepthPassMeshProcessor***。渲染的Shader为***ShadowDepthPixelShader.usf*** @@ -841,11 +841,25 @@ FSceneRenderer::RenderShadowProjections() ### Shader ShadowProjectionPixelShader.usf - - ShadowProjectionCommon.ush - ShadowDepthTexture - ShadowDepthCubeTexture +主要步骤: +1. 将SceneDepth(ScreenSpace) => (ShadowSpace) +2. 根据过滤方式调用: + 1. 不过滤:`Shadow = LightSpacePixelDepthForOpaque < Texture2DSampleLevel(ShadowDepthTexture, ShadowDepthTextureSampler, ShadowPosition.xy, 0).r;` + 2. PCSS:初始化FPCSSSamplerSettings之后调用DirectionalPCSS() + 3. PCF:初始化FPCFSamplerSettings之后调用ManualPCF() +3. 调整阴影数值。钳制、模糊、过滤。 +4. `OutColor = EncodeLightAttenuation(half4(FadedShadow, FadedSSSShadow, FadedShadow, FadedSSSShadow));`LinearSpace => sRGB 本质为sqrt(input),比pow(x, 1/2.2) 节约性能。 + +## 总结 +1. RenderDepth()渲染完深度贴图之后,经过GatherAndSortLights()、ComputeLightGrid()获取到经过剪裁的FSortedLightSetSceneInfo &SortedLightSet,之后传递给RenderLights()。 +2. BindShadowProjectionShaders() => BindShaderShaders() => +3. TShadowProjectionPS => ProjectionParameters.Bind(Initializer); => ShadowDepthTexture.Bind(ParameterMap,TEXT("ShadowDepthTexture")); + + # 半程阴影 由晨风&Neverwind提出: - 【[UFSH2024]用虚幻引擎5为《幻塔》定制高品质动画流程风格化渲染管线 | 晨风 Neverwind 完美世界游戏】 【精准空降到 07:27】 https://www.bilibili.com/video/BV1rW2LYvEox/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e&t=447