vault backup: 2024-03-13 14:29:41

This commit is contained in:
BlueRose 2024-03-13 14:29:41 +08:00
parent 93450080eb
commit ce8ba3b378

View File

@ -222,6 +222,23 @@ else if (Mat.IS_BASE_PASS)
### MaterialTemplate.ush
MaterialTemplate.ush中定义许多模版函数里面的具体内容会在HLSLMaterialTranslator.h中的**GetMaterialShaderCode()** 中添加。最后这些函数会在BassPassPixelShader.usf中调用。
bool bEnableExecutionFlow的作用为是否使用新的材质HLSL生成器默认为0。
```c++
static TAutoConsoleVariable<int32> CVarMaterialEnableNewHLSLGenerator(
TEXT("r.MaterialEnableNewHLSLGenerator"),
0,
TEXT("Enables the new (WIP) material HLSL generator.\n")
TEXT("0 - Don't allow\n")
TEXT("1 - Allow if enabled by material\n")
TEXT("2 - Force all materials to use new generator\n"),
ECVF_RenderThreadSafe | ECVF_ReadOnly);
```
bCompileForComputeShader = Material->IsLightFunction();
GetPerInstanceCustomDataX分为Vertex与Pixel版本。
#### FMaterialAttributes
MaterialTemplate.ush有一处`/** Material declarations */`之后会生成对应FMaterialAttributes结构体可以在材质编辑器的HLSL中查看生成结果。这与
- MaterialAttributeDefinitionMap.cppFMaterialAttributeDefinitionMap::InitializeAttributeMap()中定义属性。
@ -237,6 +254,39 @@ MaterialTemplate.ush有一处`/** Material declarations */`之后会生成对应
}
```
#### GetMaterialEmissiveForCS()以及其他函数
```c++
if (bCompileForComputeShader)
{
LazyPrintf.PushParam(*GenerateFunctionCode(CompiledMP_EmissiveColorCS, BaseDerivativeVariation));
}
else
{
LazyPrintf.PushParam(TEXT("return 0"));
}
{
FLinearColor Extinction = Material->GetTranslucentMultipleScatteringExtinction();
LazyPrintf.PushParam(*FString::Printf(TEXT("return MaterialFloat3(%.5f, %.5f, %.5f)"), Extinction.R, Extinction.G, Extinction.B));
}
LazyPrintf.PushParam(*FString::Printf(TEXT("return %.5f"), Material->GetOpacityMaskClipValue()));
{
const FDisplacementScaling DisplacementScaling = Material->GetDisplacementScaling();
LazyPrintf.PushParam(*FString::Printf(TEXT("return %.5f"), FMath::Max(0.0f, DisplacementScaling.Magnitude)));
LazyPrintf.PushParam(*FString::Printf(TEXT("return %.5f"), FMath::Clamp(DisplacementScaling.Center, 0.0f, 1.0f)));
}
LazyPrintf.PushParam(!bEnableExecutionFlow ? *GenerateFunctionCode(MP_WorldPositionOffset, BaseDerivativeVariation) : TEXT("return Parameters.MaterialAttributes.WorldPositionOffset"));
LazyPrintf.PushParam(!bEnableExecutionFlow ? *GenerateFunctionCode(CompiledMP_PrevWorldPositionOffset, BaseDerivativeVariation) : TEXT("return 0.0f"));
LazyPrintf.PushParam(!bEnableExecutionFlow ? *GenerateFunctionCode(MP_CustomData0, BaseDerivativeVariation) : TEXT("return 0.0f"));
LazyPrintf.PushParam(!bEnableExecutionFlow ? *GenerateFunctionCode(MP_CustomData1, BaseDerivativeVariation) : TEXT("return 0.0f"));
```
%.5f表示按浮点数输出小数点后面取5位其余的舍弃例如5/2 “%.5f”输出为2.50000
#### MaterialCustomizedUVs & CustomInterpolators
- `for (uint32 CustomUVIndex = 0; CustomUVIndex < NumUserTexCoords; CustomUVIndex++)`
- `for (UMaterialExpressionVertexInterpolator* Interpolator : CustomVertexInterpolators`
### 是否需要Toon
在材质中:
```c++