Support Legacy shader mode

This commit is contained in:
Eragon-Brisingr
2026-07-05 19:37:06 +08:00
parent 59af77e8f6
commit 3dbdf02f27
7 changed files with 739 additions and 323 deletions

View File

@@ -49,6 +49,7 @@
#include "Misc/FileHelper.h"
#include "ShaderCore.h"
#include "SceneTypes.h"
#include "RenderUtils.h" // Substrate::IsSubstrateEnabled()
#define SHADERLAB_COMMON_INCLUDE TEXT("/Plugin/ShaderLab/Private/ShaderLabCommon.ush")
#define SHADERLAB_FUNCTIONS_INCLUDE TEXT("/Plugin/ShaderLab/Private/ShaderLabUEFunctions.ush")
@@ -2521,6 +2522,10 @@ namespace ShaderLabGraph
return nullptr;
}
}
// Legacy (non-Substrate) pixel-stage emitter. Pulled into this TU (inside namespace ShaderLabGraph) so it
// reuses the helpers above without a shared header. Deletable wholesale with the non-Substrate scheme.
#include "ShaderLabSurfaceEmitter_Legacy.inl"
}
bool FShaderLabGraphBuilder::ResolveVirtualShaderFile(const FString& VirtualPath, FString& OutDiskPath)
@@ -3099,6 +3104,17 @@ bool FShaderLabGraphBuilder::BuildInto(UMaterial& Material, const FShaderLabMode
return false;
}
}
else if (!Substrate::IsSubstrateEnabled())
{
// Legacy (non-Substrate) scheme: PostProcess/UI already handled above (mode-independent). Everything
// else (SL_SURFACE -> DefaultLit, single SL_UNLIT -> Unlit) wires to the standard material pins; the
// rest is rejected with a .usl error. See ShaderLabSurfaceEmitter_Legacy.inl.
if (!EmitLegacyPixelStage(Material, *EditorOnly, Model, Program, Emit, PropertyNodes,
InterpByName, UsedInterps, Samples, SurfaceOutParam, ParamY, OutErrors))
{
return false;
}
}
else if (Model.bHasSurface)
{
// Single-Surface sugar: one slab straight to FrontMaterial, with the FShaderLabSurface material-level
@@ -3526,9 +3542,22 @@ void FShaderLabGraphBuilder::BuildPoisonInto(UMaterial& Material, const TArray<F
*SrcPath, *Combined);
Custom->RebuildOutputs();
UMaterialExpressionSubstrateSlabBSDF* Slab = NewExpr<UMaterialExpressionSubstrateSlabBSDF>(Material, IoY, 0);
Slab->DiffuseAlbedo.Connect(0, Custom);
EditorOnly->FrontMaterial.Connect(0, Slab);
if (Substrate::IsSubstrateEnabled())
{
// Substrate: Custom -> Slab.DiffuseAlbedo -> FrontMaterial (DiffuseAlbedo is a core BSDF pin, always
// translated, so the #error is reached).
UMaterialExpressionSubstrateSlabBSDF* Slab = NewExpr<UMaterialExpressionSubstrateSlabBSDF>(Material, IoY, 0);
Slab->DiffuseAlbedo.Connect(0, Custom);
EditorOnly->FrontMaterial.Connect(0, Slab);
}
else
{
// Legacy (non-Substrate): FrontMaterial is inactive, so the Slab->FrontMaterial poison would be
// dead-stripped and the #error never compiled. Wire the Custom to MP_BaseColor (a core DefaultLit pin
// that is always translated) so the #error still aborts the compile with our diagnostics.
Material.SetShadingModel(MSM_DefaultLit);
EditorOnly->BaseColor.Connect(0, Custom);
}
Material.UpdateCachedExpressionData();
}