diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md index c64343f..069c092 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/GBuffer&Material&BasePass.md @@ -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 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.cpp:FMaterialAttributeDefinitionMap::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++