2024-06-20 16:26:44 +08:00
|
|
|
|
# Common
|
|
|
|
|
## Common.ush
|
|
|
|
|
添加结构体,主要用在材质的CustomNode里。
|
|
|
|
|
```c++
|
|
|
|
|
// Used by toon shading.
|
|
|
|
|
// Define a global custom data structure which can be filled by Custom node in material BP.
|
|
|
|
|
struct FToonShadingPerMaterialCustomData
|
|
|
|
|
{
|
|
|
|
|
// Toon specular
|
|
|
|
|
float3 ToonSpecularColor;
|
|
|
|
|
float ToonSpecularLocation;
|
|
|
|
|
float ToonSpecularSmoothness;
|
|
|
|
|
// Toon shadow
|
|
|
|
|
float3 ToonShadowColor;
|
|
|
|
|
float ToonShadowLocation;
|
|
|
|
|
float ToonShadowSmoothness;
|
|
|
|
|
float ToonForceShadow;
|
|
|
|
|
// Toon secondary shadow
|
|
|
|
|
float3 ToonSecondaryShadowColor;
|
|
|
|
|
float ToonSecondaryShadowLocation;
|
|
|
|
|
float ToonSecondaryShadowSmoothness;
|
|
|
|
|
// custom data, usually not used
|
|
|
|
|
float4 CustomData0;
|
|
|
|
|
float4 CustomData1;
|
|
|
|
|
float4 CustomData2;
|
|
|
|
|
float4 CustomData3;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static FToonShadingPerMaterialCustomData ToonShadingPerMaterialCustomData;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## DeferredShadingCommon.ush
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Lighting
|
|
|
|
|
|
|
|
|
|
## ShadingModels
|
|
|
|
|
### ShadingCommon.ush
|
|
|
|
|
1. 添加ShadingModelID宏:
|
|
|
|
|
- SHADINGMODELID_TOON_BASE 13
|
|
|
|
|
-
|
2024-06-20 12:43:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# PostProcess
|
|
|
|
|
## ToneMapping
|
|
|
|
|
c++部分主要修改了:
|
|
|
|
|
1. PostProcessing.cpp
|
|
|
|
|
2. PostProcessTonemap.cpp
|
|
|
|
|
3. PostProcessTonemap.h
|
|
|
|
|
|
|
|
|
|
***实现向ToneMaper Shader传递 `TRDGUniformBufferRef<FSceneTextureUniformParameters>`的功能***
|
|
|
|
|
|
2024-06-20 16:26:44 +08:00
|
|
|
|
之后再PostProcessTonemap.usf中,对**CustomStencil**进行判断,如果为true,则直接返回之前渲染结果。实际上BufferVisualization里根本看不出来。
|
|
|
|
|
|
|
|
|
|
|
2024-06-20 12:43:43 +08:00
|
|
|
|
```c++
|
|
|
|
|
#include "DeferredShadingCommon.ush"
|
|
|
|
|
|
|
|
|
|
// pixel shader entry point
|
|
|
|
|
void MainPS(
|
|
|
|
|
in noperspective float2 UV : TEXCOORD0,
|
|
|
|
|
in noperspective float2 InVignette : TEXCOORD1,
|
|
|
|
|
in noperspective float4 GrainUV : TEXCOORD2,
|
|
|
|
|
in noperspective float2 ScreenPos : TEXCOORD3,
|
|
|
|
|
in noperspective float2 FullViewUV : TEXCOORD4,
|
|
|
|
|
float4 SvPosition : SV_POSITION, // after all interpolators
|
|
|
|
|
out float4 OutColor : SV_Target0
|
|
|
|
|
#if OUTPUT_LUMINANCE
|
|
|
|
|
, out float OutLuminance: SV_Target1
|
|
|
|
|
#endif
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
float Luminance;
|
|
|
|
|
FGBufferData SamplerBuffer = GetGBufferData(UV * View.ResolutionFractionAndInv.x, false);
|
|
|
|
|
if (SamplerBuffer.CustomStencil > 1.0f && abs(SamplerBuffer.CustomDepth - SamplerBuffer.Depth) < 1)
|
|
|
|
|
{
|
|
|
|
|
OutColor = SampleSceneColor(UV);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OutColor = TonemapCommonPS(UV, InVignette, GrainUV, ScreenPos, FullViewUV, SvPosition, Luminance);
|
|
|
|
|
}
|
|
|
|
|
#if OUTPUT_LUMINANCE
|
|
|
|
|
OutLuminance = Luminance;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Lut
|