2024-05-15 17:25:57 +08:00
|
|
|
|
---
|
|
|
|
|
title: ToonPostProcess
|
|
|
|
|
date: 2024-05-15 16:50:13
|
|
|
|
|
excerpt:
|
|
|
|
|
tags:
|
|
|
|
|
rating: ⭐
|
|
|
|
|
---
|
2024-10-21 14:35:55 +08:00
|
|
|
|
# Bloom
|
|
|
|
|
Bloom主要分
|
|
|
|
|
- Bloom
|
|
|
|
|
- FFTBloom
|
|
|
|
|
- LensFlares
|
|
|
|
|
|
2024-10-21 18:03:20 +08:00
|
|
|
|
## FFTBloom
|
2024-10-22 11:39:07 +08:00
|
|
|
|
***普通Bloom算法只能做到圆形光斑,对于自定义形状的就需要使用FFTBloom。***
|
|
|
|
|
|
|
|
|
|
|
2024-10-21 18:03:20 +08:00
|
|
|
|
**FBloomFindKernelCenterCS**:用于找到Bloom效果的核(Kernel)中心(纹理中找到最亮的像素)。用于在一个,并记录其位置。主要通过计算Luminance来获取到中心区域,而在这里的中心区域可以有多个,这也代表着在最终输出的SceneColor里可以有多个【曝点光晕(Bloom)效果】
|
2024-10-21 14:35:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-15 17:25:57 +08:00
|
|
|
|
# 实用代码
|
|
|
|
|
代码位于DeferredShadingCommon.ush:
|
|
|
|
|
```c++
|
|
|
|
|
// @param UV - UV space in the GBuffer textures (BufferSize resolution)
|
|
|
|
|
FGBufferData GetGBufferData(float2 UV, bool bGetNormalizedNormal = true)
|
|
|
|
|
{
|
|
|
|
|
#if GBUFFER_REFACTOR
|
|
|
|
|
return DecodeGBufferDataUV(UV,bGetNormalizedNormal);
|
|
|
|
|
#else
|
|
|
|
|
float4 GBufferA = Texture2DSampleLevel(SceneTexturesStruct.GBufferATexture, SceneTexturesStruct_GBufferATextureSampler, UV, 0);
|
|
|
|
|
float4 GBufferB = Texture2DSampleLevel(SceneTexturesStruct.GBufferBTexture, SceneTexturesStruct_GBufferBTextureSampler, UV, 0);
|
|
|
|
|
float4 GBufferC = Texture2DSampleLevel(SceneTexturesStruct.GBufferCTexture, SceneTexturesStruct_GBufferCTextureSampler, UV, 0);
|
|
|
|
|
float4 GBufferD = Texture2DSampleLevel(SceneTexturesStruct.GBufferDTexture, SceneTexturesStruct_GBufferDTextureSampler, UV, 0);
|
|
|
|
|
float CustomNativeDepth = Texture2DSampleLevel(SceneTexturesStruct.CustomDepthTexture, SceneTexturesStruct_CustomDepthTextureSampler, UV, 0).r;
|
|
|
|
|
|
|
|
|
|
// BufferToSceneTextureScale is necessary when translucent materials are rendered in a render target
|
|
|
|
|
// that has a different resolution than the scene color textures, e.g. r.SeparateTranslucencyScreenPercentage < 100.
|
|
|
|
|
int2 IntUV = (int2)trunc(UV * View.BufferSizeAndInvSize.xy * View.BufferToSceneTextureScale.xy);
|
|
|
|
|
uint CustomStencil = SceneTexturesStruct.CustomStencilTexture.Load(int3(IntUV, 0)) STENCIL_COMPONENT_SWIZZLE;
|
|
|
|
|
|
|
|
|
|
#if ALLOW_STATIC_LIGHTING
|
|
|
|
|
float4 GBufferE = Texture2DSampleLevel(SceneTexturesStruct.GBufferETexture, SceneTexturesStruct_GBufferETextureSampler, UV, 0);
|
|
|
|
|
#else
|
|
|
|
|
float4 GBufferE = 1;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
float4 GBufferF = Texture2DSampleLevel(SceneTexturesStruct.GBufferFTexture, SceneTexturesStruct_GBufferFTextureSampler, UV, 0);
|
|
|
|
|
|
|
|
|
|
#if WRITES_VELOCITY_TO_GBUFFER
|
|
|
|
|
float4 GBufferVelocity = Texture2DSampleLevel(SceneTexturesStruct.GBufferVelocityTexture, SceneTexturesStruct_GBufferVelocityTextureSampler, UV, 0);
|
|
|
|
|
#else
|
|
|
|
|
float4 GBufferVelocity = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
float SceneDepth = CalcSceneDepth(UV);
|
|
|
|
|
|
|
|
|
|
return DecodeGBufferData(GBufferA, GBufferB, GBufferC, GBufferD, GBufferE, GBufferF, GBufferVelocity, CustomNativeDepth, CustomStencil, SceneDepth, bGetNormalizedNormal, CheckerFromSceneColorUV(UV));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Minimal path for just the lighting model, used to branch around unlit pixels (skybox)
|
|
|
|
|
uint GetShadingModelId(float2 UV)
|
|
|
|
|
{
|
|
|
|
|
return DecodeShadingModelId(Texture2DSampleLevel(SceneTexturesStruct.GBufferBTexture, SceneTexturesStruct_GBufferBTextureSampler, UV, 0).a);
|
|
|
|
|
}
|
|
|
|
|
```
|
2024-05-15 18:08:22 +08:00
|
|
|
|
|
|
|
|
|
## ShadingModel判断
|
|
|
|
|
```c++
|
|
|
|
|
bool IsToonShadingModel(float2 UV)
|
|
|
|
|
{
|
|
|
|
|
uint ShadingModel = DecodeShadingModelId(Texture2DSampleLevel(SceneTexturesStruct.GBufferBTexture, SceneTexturesStruct_GBufferBTextureSampler, UV, 0).a);
|
|
|
|
|
return ShadingModel == SHADINGMODELID_TOONSTANDARD
|
|
|
|
|
|| ShadingModel == SHADINGMODELID_PREINTEGRATED_SKIN;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
PS.需要Shader添加FSceneTextureShaderParameters/FSceneTextureUniformParameters。
|
|
|
|
|
```c++
|
|
|
|
|
IMPLEMENT_STATIC_UNIFORM_BUFFER_STRUCT(FSceneTextureUniformParameters, "SceneTexturesStruct", SceneTextures);
|
|
|
|
|
|
|
|
|
|
BEGIN_SHADER_PARAMETER_STRUCT(FSceneTextureShaderParameters, ENGINE_API)
|
|
|
|
|
SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FSceneTextureUniformParameters, SceneTextures)
|
|
|
|
|
SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FMobileSceneTextureUniformParameters, MobileSceneTextures)
|
|
|
|
|
END_SHADER_PARAMETER_STRUCT()
|
|
|
|
|
```
|