From 410c9ab8e8e35efcfe5bc3997f62c71e7920ff46 Mon Sep 17 00:00:00 2001 From: BlueRose <378100977@qq.com> Date: Wed, 6 Mar 2024 22:21:43 +0800 Subject: [PATCH] vault backup: 2024-03-06 22:21:43 --- .../plugins/various-complements/data.json | 40 +---- .../卡通渲染相关资料/卡通渲染开发总览.md | 3 +- .../渲染功能/ShaderModel/GBuffer&Material&BasePass.md | 159 ++++++++++++++++-- 3 files changed, 157 insertions(+), 45 deletions(-) diff --git a/.obsidian/plugins/various-complements/data.json b/.obsidian/plugins/various-complements/data.json index 5c21be9..aca79ab 100644 --- a/.obsidian/plugins/various-complements/data.json +++ b/.obsidian/plugins/various-complements/data.json @@ -47,38 +47,6 @@ }, "showLogAboutPerformanceInConsole": false, "selectionHistoryTree": { - "UE5中,这些名称有了一定的变化": { - "UE5中,这些名称有了一定的变化": { - "currentFile": { - "count": 1, - "lastUpdated": 1706168576772 - } - } - }, - "MooaToonDataB": { - "MooaToonDataB": { - "currentFile": { - "count": 1, - "lastUpdated": 1706175926016 - } - } - }, - "LightColor": { - "LightColor": { - "currentFile": { - "count": 1, - "lastUpdated": 1706177275907 - } - } - }, - "结构体。具有void": { - "结构体。具有void": { - "currentFile": { - "count": 1, - "lastUpdated": 1707040198653 - } - } - }, "FRDGViewableResource、FRDGTexture、FRDGTextureSRV、FRDGTextureUAV": { "FRDGViewableResource、FRDGTexture、FRDGTextureSRV、FRDGTextureUAV": { "currentFile": { @@ -198,6 +166,14 @@ "lastUpdated": 1708510269638 } } + }, + "Velocity": { + "Velocity": { + "currentFile": { + "count": 1, + "lastUpdated": 1709717543852 + } + } } } } \ No newline at end of file diff --git a/03-UnrealEngine/卡通渲染相关资料/卡通渲染开发总览.md b/03-UnrealEngine/卡通渲染相关资料/卡通渲染开发总览.md index 1acac0e..bda9e1c 100644 --- a/03-UnrealEngine/卡通渲染相关资料/卡通渲染开发总览.md +++ b/03-UnrealEngine/卡通渲染相关资料/卡通渲染开发总览.md @@ -13,7 +13,8 @@ rating: ⭐ - 星穹铁道 - UnityChan - 破晓传说 - - 蓝色协议3 + - 蓝色协议 + - 蓝色反射 - 非人学园2 - 少女前线2 追放 - https://www.bilibili.com/video/BV1pt421H7EH/?buvid=38ddfe416af6e23f1aada0674f307e3e&from_spmid=tm.recommend.0.0&is_story_h5=false&mid=a0AUwJxrG%2FcYg0AorRjOGA%3D%3D&p=1&plat_id=116&share_from=ugc&share_medium=iphone&share_plat=ios&share_session_id=CD0CF499-8DF5-48F5-A03A-7A3AE61FFF3A&share_source=COPY&share_tag=s_i&spmid=united.player-video-detail.0.0×tamp=1706754945&unique_k=44q6hra&up_id=140517136&vd_source=d47c0bb42f9c72fd7d74562185cee290 diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md index 377d0ad..dc6b1c8 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md @@ -14,40 +14,126 @@ rating: ⭐ `Engine\Intermediate\ShaderAutogen\PCD3D_SM5`或者`Engine\Intermediate\ShaderAutogen\PCD3D_ES3_1` 1. ***给FGBufferData添加结构体数据时需要在此添加额外代码逻辑*** -2. GBuffer精度在FetchLegacyGBufferInfo()设置 +2. GBuffer精度在FetchLegacyGBufferInfo()设置。 +3. 是否往GBuffer中写入Velocity,主要靠这个宏**WRITES_VELOCITY_TO_GBUFFER**。具体决定其数值的逻辑位于**FShaderGlobalDefines FetchShaderGlobalDefines**。主要还是靠**r.VelocityOutputPass**进行开启。 + 1. PS. MSAA以及VR绝对不会开启Velocity输出选项。还有就是**r.Velocity.ForceOutput**,但经过测试不开启r.VelocityOutputPass依然无法输出。以及FPrimitiveSceneProxy的bAlwaysHasVelocity与bHasWorldPositionOffsetVelocity。 + 2. 其他相关FSR、TSR? +4. 如何添加GBuffer + 1. https://zhuanlan.zhihu.com/p/568775542 + 2. https://zhuanlan.zhihu.com/p/677772284 - - -UE5 GBuffer内容: +## UE5 GBuffer内容: [[UE GBuffer存储数据]] ```c# -OutGBufferA = WorldNormal/PerObjectGBufferData -OutGBufferB = Metallic/Specular/Roughness/EncodeShadingModelIdAndSelectiveOutputMask(GBuffer.ShadingModelID, GBuffer.SelectiveOutputMask); -OutGBufferC = BaseColor/GBufferAO -OutGBufferD = GBuffer.CustomData; -OutGBufferE = GBuffer.PrecomputedShadowFactors; +OutGBufferA(MRT1) = WorldNormal/PerObjectGBufferData (GBT_Float_16_16_16_16/GBT_Unorm_11_11_10/GBT_Unorm_8_8_8_8) +OutGBufferB(MRT2) = Metallic/Specular/Roughness/EncodeShadingModelIdAndSelectiveOutputMask (GBT_Float_16_16_16_16/GBT_Unorm_8_8_8_8) +OutGBufferC(MRT3) = BaseColor/GBufferAO (GBT_Unorm_8_8_8_8) +OutGBufferD = GBuffer.CustomData (GBT_Unorm_8_8_8_8) +OutGBufferE = GBuffer.PrecomputedShadowFactors (GBT_Unorm_8_8_8_8) +TargetVelocity / OutGBufferF = velocity / tangent (默认不开启 带有深度<开启Lumen与距离场 或者 开启光线追踪> GBC_Raw_Float_16_16_16_16 不带深度 GBC_Raw_Float_16_16) +TargetSeparatedMainDirLight = SingleLayerWater相关 (有SingleLayerWater才会开启 GBC_Raw_Float_11_11_10) // 0..1, 2 bits, use CastContactShadow(GBuffer) or HasDynamicIndirectShadowCasterRepresentation(GBuffer) to extract half PerObjectGBufferData; ``` +GBuffer相关信息(精度、顺序)可以参考FetchLegacyGBufferInfo()。 +- 不存在Velocity与Tangent: + - OutGBufferD(MRT4) + - OutGBufferD(MRT5) + - ~~TargetSeparatedMainDirLight(MRT6)~~ +- 存在Velocity: + - TargetVelocity(MRT4) + - OutGBufferD(MRT5) + - OutGBufferE(MRT6) + - ~~TargetSeparatedMainDirLight(MRT7)~~ +- 存在Tangent: + - OutGBufferF(MRT4) + - OutGBufferD(MRT5) + - OutGBufferE(MRT6) + - ~~TargetSeparatedMainDirLight(MRT7)~~ -ToonGBuffer修改&数据存储: +几个动态MRT的存在条件与Shader判断宏: +***查找IsUsingBasePassVelocity()*** 被使用过的地方。 +class RPGGAMEPLAYABILITY_API USDHCommonSettings : public UDeveloperSettings + + +UCLASS(config=Engine, defaultconfig, meta=(DisplayName="Rendering"), MinimalAPI) +class URendererSettings : public UDeveloperSettings + +UPROPERTY(config, EditAnywhere, Category = VirtualTextures, meta = ( + ConsoleVariable = "r.VirtualTextures", DisplayName = "Enable virtual texture support", + ToolTip = "When enabled, Textures can be streamed using the virtual texture system. Changing this setting requires restarting the editor.", + ConfigRestartRequired = true)) +uint32 bVirtualTextures : 1; + + + +- OutGBufferE(PrecomputedShadowFactors):r.AllowStaticLighting = 1 + - +- TargetVelocity:(IsUsingBasePassVelocity(Platform) || Layout == GBL_ForceVelocity) ? 1 : 0;//r.VelocityOutputPass = 1 + - +- Tangent:false,目前单独使用另一组MRT来存储。 + - + +### ToonGBuffer修改&数据存储 ```c# OutGBufferA:PerObjectGBufferData => 可以存储额外的有关Tonn渲染功能参数。 OutGBufferB:Metallic/Specular/Roughness => - ? / SpcularMask(控制高光形状与Mask) / ? / ? + ? / SpcularPower(控制高光亮度与Mask) / ? / ? //ToonHairMask OffsetShadowMask/SpcularMask/SpecularValue +OutGBufferC:GBufferAO => + OutGBufferD:CustomData.xyzw => ShaderColor.rgb / NoLOffset //ShadowColor这里可以在Material里通过主光向量、ShadowStep、Shadow羽化计算多层阴影效果。 OutGBufferE:GBuffer.PrecomputedShadowFactors.xyzw => ToonDataID/ ToonObjectID(判断是否是一个物体) /OutlineMask 控制Outline绘制以及Outline强度 / ToonAO -OutGBufferF:velocity => +TargetVelocity / OutGBufferF = velocity / tangent //目前先不考虑输出Velocity的情况 ? / ? / ? / ? ``` 蓝色协议的方案 ![[蓝色协议的方案#GBuffer]] +### 是否需要Toon +在材质中: +```c++ +FMaterialRelevance UMaterialInterface::GetRelevance_Internal(const UMaterial* Material, ERHIFeatureLevel::Type InFeatureLevel) const +{ + if(Material) + { + //YivanLee's Modify 这里仅仅针对人物,因为它决定了是否开启ToonGBuffer,但是对于ToonLevel,ToonFoliage,ToonGrass这里并不需要开启 + bool bUseToonData = MaterialResource->GetShadingModels().HasAnyShadingModel({ MSM_ToonStandard, MSM_ToonSkin, MSM_ToonHair, MSM_ToonFace, MSM_ToonEyeBrow }); + } + + ··· + MaterialRelevance.bUsesToonData = bUseToonData; + ··· +} +``` + +在渲染管线中: +```c++ +bool FDeferredShadingSceneRenderer::ShouldRenderToonDataPass() const +{ + if (!SupportsToonDataMaterials(FeatureLevel, ShaderPlatform)) + { + return false; + } + if (IsForwardShadingEnabled(GetFeatureLevelShaderPlatform(FeatureLevel))) + { + return false; + } + for (auto& View : Views) + { + if (View.ShouldRenderView() && View.ParallelMeshDrawCommandPasses[EMeshPass::ToonDataPass].HasAnyDraw()) + { + return true; + } + } + return false; +} +``` + ## Toon PerObjectGBufferData具体功能表 从3开始,0、1、2已被占用。 - ? @@ -59,6 +145,55 @@ OutGBufferF:velocity => - PBR高光(使用Roughness控制是否可行?是否需要传入GBuffer一个Mask贴图) - 自定义高光:高光贴图、高光颜色、参数化高光形状、多层高光 +# BasePassPixelShader +Velocity相关代码段: +```c++ + #if USES_GBUFFER + // -0.5 .. 0.5, could be optimzed as lower quality noise would be sufficient + float QuantizationBias = PseudoRandom( MaterialParameters.SvPosition.xy ) - 0.5f; + + GBuffer.IndirectIrradiance = IndirectIrradiance; + + // this is the new encode, the older encode is the #else, keeping it around briefly until the new version is confirmed stable. + #if 1 + { + // change this so that we can pack everything into the gbuffer, but leave this for now + #if GBUFFER_HAS_DIFFUSE_SAMPLE_OCCLUSION + GBuffer.GenericAO = float(GBuffer.DiffuseIndirectSampleOcclusion) * (1.0f / 255.0f); + #elif ALLOW_STATIC_LIGHTING + // No space for AO. Multiply IndirectIrradiance by AO instead of storing. + GBuffer.GenericAO = EncodeIndirectIrradiance(GBuffer.IndirectIrradiance * GBuffer.GBufferAO) + QuantizationBias * (1.0 / 255.0); // Stationary sky light path + #else + GBuffer.GenericAO = GBuffer.GBufferAO; // Movable sky light path + #endif + + EncodeGBufferToMRT(Out, GBuffer, QuantizationBias); + + if (GBuffer.ShadingModelID == SHADINGMODELID_UNLIT && !STRATA_ENABLED) // Do not touch what strata outputs + { + Out.MRT[1] = 0; + SetGBufferForUnlit(Out.MRT[2]); + Out.MRT[3] = 0; + Out.MRT[GBUFFER_HAS_VELOCITY ? 5 : 4] = 0; + Out.MRT[GBUFFER_HAS_VELOCITY ? 6 : 5] = 0; + } + + #if SINGLE_LAYER_WATER_SEPARATED_MAIN_LIGHT + // In deferred, we always output the directional light in a separated buffer. + // This is used to apply distance field shadows or light function to the main directional light. + // Strata also writes it through MRT because this is faster than through UAV. + #if STRATA_ENABLED && STRATA_INLINE_SINGLELAYERWATER + Out.MRT[(GBUFFER_HAS_VELOCITY ? 2 : 1) + (GBUFFER_HAS_PRECSHADOWFACTOR ? 1 : 0)] = float4(SeparatedWaterMainDirLightLuminance * View.PreExposure, 1.0f); + #else + if (GBuffer.ShadingModelID == SHADINGMODELID_SINGLELAYERWATER) + { + Out.MRT[(GBUFFER_HAS_VELOCITY ? 6 : 5) + (GBUFFER_HAS_PRECSHADOWFACTOR ? 1 : 0)] = float4(SeparatedWaterMainDirLightLuminance * View.PreExposure, 1.0f); + } + #endif + #endif + } +``` + # 顶点色 ## 蓝色协议 用于存储一些低精度数据,插值即可