Files
UShaderLab/Shaders/Private/Surface_Legacy.ush
2026-07-05 19:37:06 +08:00

56 lines
2.4 KiB
Plaintext

// Copyright UShaderLab. All Rights Reserved.
// Legacy (non-Substrate) surface output struct. Included by ShaderLabCommon.ush only when
// SHADERLAB_SUBSTRATE == 0 (i.e. the project runs with r.Substrate=0). The Substrate counterpart is
// Surface_Substrate.ush. This whole file — plus ShaderLabSurfaceEmitter_Legacy.* and the legacy branch
// in ShaderLabGraphBuilder — is the deletable "old scheme" slice: once UE removes the non-Substrate
// path, delete these and the #else in ShaderLabCommon.ush.
//
// SL_SURFACE stays the same concept across both modes, but the shading parameterization differs: Substrate
// uses DiffuseAlbedo/F0/F90/... while legacy uses the classic Metallic/Roughness workflow (BaseColor/
// Metallic/Specular). Common fields (Normal/Roughness/Anisotropy/Tangent/EmissiveColor and the material-
// level outputs) carry the same names in both, so a body that only touches those needs no `#if`. A body
// that touches the mode-specific shading fields guards them with `#if SHADERLAB_SUBSTRATE ... #else ...`.
#pragma once
// Single-entry surface, filled by the SL_SURFACE(...) body. Legacy = classic Metallic/Roughness workflow
// mapped to a MSM_DefaultLit material: shading fields feed MP_BaseColor/Metallic/Specular/Roughness/
// Anisotropy/Normal/Tangent/EmissiveColor, and the material-level outputs feed the matching main pins.
// (Substrate-only fields — F0/F90/SSSMFP/Fuzz/Glint/SurfaceThickness — do not exist here.)
struct FShaderLabSurface
{
float3 BaseColor;
float Metallic;
float Specular;
float Roughness;
float Anisotropy;
float3 Normal;
float3 Tangent;
float3 EmissiveColor;
// Material-level outputs. See the graph builder's activeness contract (Domain/BlendMode).
float Opacity; // translucency coverage -> MP_Opacity (legacy wires it directly)
float OpacityMask; // Masked blend cutout -> MP_OpacityMask
float Refraction; // scalar IOR -> MP_Refraction
float PixelDepthOffset; // world-unit depth push -> MP_PixelDepthOffset
float AmbientOcclusion; // -> MP_AmbientOcclusion
};
FShaderLabSurface ShaderLabDefaultSurface()
{
FShaderLabSurface S;
S.BaseColor = float3(0.18, 0.18, 0.18);
S.Metallic = 0;
S.Specular = 0.5;
S.Roughness = 0.5;
S.Anisotropy = 0;
S.Normal = float3(0, 0, 1);
S.Tangent = float3(1, 0, 0);
S.EmissiveColor = float3(0, 0, 0);
S.Opacity = 1;
S.OpacityMask = 1;
S.Refraction = 1.0;
S.PixelDepthOffset = 0.0;
S.AmbientOcclusion = 1;
return S;
}