2024-09-25 17:05:44 +08:00
|
|
|
|
---
|
|
|
|
|
title: Untitled
|
|
|
|
|
date: 2024-09-25 14:59:32
|
|
|
|
|
excerpt:
|
|
|
|
|
tags:
|
|
|
|
|
rating: ⭐
|
|
|
|
|
---
|
|
|
|
|
# 前言
|
|
|
|
|
可以使用DrawDynamicMeshPass(),实现在插件中使用MeshDraw绘制Pass。
|
|
|
|
|
|
|
|
|
|
参考文章:
|
|
|
|
|
- ***UE5,为HairStrands添加自定义深度与模板***:https://zhuanlan.zhihu.com/p/689578355
|
|
|
|
|
|
|
|
|
|
# NaniteMeshDraw
|
|
|
|
|
`Engine\Source\Runtime\Renderer\Private\Nanite\`NaniteMaterials.h & NaniteMaterials.cpp
|
|
|
|
|
|
|
|
|
|
PS.使用的Shader必须是`FNaniteGlobalShader`的子类。
|
|
|
|
|
|
|
|
|
|
## BasePass
|
|
|
|
|
### DrawBasePass()
|
|
|
|
|
该函数在FDeferredShadingSceneRenderer::RenderBasePassInternal()中调用。
|
|
|
|
|
|
2024-09-25 17:54:03 +08:00
|
|
|
|
DrawNaniteMaterialPass() => SubmitNaniteIndirectMaterial()
|
|
|
|
|
|
2024-09-25 17:05:44 +08:00
|
|
|
|
|
|
|
|
|
## DepthStencil
|
|
|
|
|
### InitCustomDepthStencilContext()
|
|
|
|
|
根据当前平台是否支持使用ComputeShader直接输出结果(bComputeExport)、以及是否写入Stencil缓存,以此来创建不同的资源。最终输出FCustomDepthContext。
|
|
|
|
|
```c++
|
|
|
|
|
struct FCustomDepthContext
|
|
|
|
|
{
|
|
|
|
|
FRDGTextureRef InputDepth = nullptr;
|
|
|
|
|
FRDGTextureSRVRef InputStencilSRV = nullptr;
|
|
|
|
|
FRDGTextureRef DepthTarget = nullptr;
|
|
|
|
|
FRDGTextureRef StencilTarget = nullptr;
|
|
|
|
|
bool bComputeExport = true;
|
|
|
|
|
};
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### EmitCustomDepthStencilTargets()
|
|
|
|
|
根据bComputeExport,分别使用RDG的ComputeShader与PixelShader输出DepthStencil。
|
|
|
|
|
- CS使用FComputeShaderUtils::AddPass()
|
|
|
|
|
- PS使用NaniteExportGBuffer.usf的**EmitCustomDepthStencilPS()**,FPixelShaderUtils::AddFullscreenPass()
|
|
|
|
|
|
|
|
|
|
以**FEmitCustomDepthStencilPS**(NaniteExportGBuffer.usf)为例,额外输入的Nanite相关变量:
|
|
|
|
|
- FSceneUniformParameters Scene
|
|
|
|
|
- StructuredBuffer`<`FPackedView`>` InViews
|
|
|
|
|
- ByteAddressBuffer VisibleClustersSWHW?
|
|
|
|
|
- FIntVector4, PageConstants
|
|
|
|
|
- Texture2D`<`UlongType`>`, VisBuffer64
|
|
|
|
|
- ByteAddressBuffer MaterialSlotTable
|
|
|
|
|
|
|
|
|
|
### FinalizeCustomDepthStencil()
|
|
|
|
|
替换输出的Depth&Stencil。
|