diff --git a/03-UnrealEngine/Rendering/RenderFeature/深度相关.md b/03-UnrealEngine/Rendering/RenderFeature/深度相关.md new file mode 100644 index 0000000..f0cf2ac --- /dev/null +++ b/03-UnrealEngine/Rendering/RenderFeature/深度相关.md @@ -0,0 +1,45 @@ +--- +title: 深度相关 +date: 2024-09-09 16:49:08 +excerpt: +tags: +rating: ⭐ +--- +# 相关代码 +位于common.ush +```c++ +#define NearDepthValue (HAS_INVERTED_Z_BUFFER ? 1.0f : 0.0f) +#define FarDepthValue (HAS_INVERTED_Z_BUFFER ? 0.0f : 1.0f) +``` + +可以通过**DeviceZ == FarDepthValue**来判断是否处于最远端。 +```c++ + float DeviceZ = DepthReadDisabled ? FarDepthValue : LookupDeviceZ(UvBuffer); +#endif + + if (DeviceZ == FarDepthValue) + { + // Get the light disk luminance to draw + LuminanceScale = SkyAtmosphere.SkyLuminanceFactor; +#if SOURCE_DISK_ENABLED + if (SourceDiskEnabled > 0) + { + PreExposedL += GetLightDiskLuminance(WorldPos, WorldDir, 0); + #if SECOND_ATMOSPHERE_LIGHT_ENABLED + PreExposedL += GetLightDiskLuminance(WorldPos, WorldDir, 1); + #endif + } +#endif + +#if RENDERSKY_ENABLED==0 + // We should not render the sky and the current pixels are at far depth, so simply early exit. + // We enable depth bound when supported to not have to even process those pixels. + OutLuminance = PrepareOutput(float3(0.0f, 0.0f, 0.0f), float3(1.0f, 1.0f, 1.0f)); + + //Now the sky pass can ignore the pixel with depth == far but it will need to alpha clip because not all RHI backend support depthbound tests. + // And the depthtest is already setup to avoid writing all the pixel closer than to the camera than the start distance (very good optimisation). + // Since this shader does not write to depth or stencil it should still benefit from EArlyZ even with the clip (See AMD depth-in-depth documentation) + clip(-1.0f); + return; +#endif +``` \ No newline at end of file diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md index 256c553..840c1c1 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md @@ -134,4 +134,7 @@ FORCEINLINE FSceneTextures& GetActiveSceneTextures() { return ViewFamily.GetScen | 2000cm | | | | 5000cm | | | | 10000cm | | | - +# 问题记录 +## 处于FarDepthValue的Outline被裁剪的问题 +- SkyAtmosphere.usf中,会将天空球渲染在深度为FarDepthValue的像素上,这样会将一些Outline覆盖掉。 +- HeightFogPixelShader.usf中,会通过判断**DeviceZ != 0.0** 来调整渲染结果,绘制方式PSO.BlendState = TStaticBlendState::GetRHI(); \ No newline at end of file