2023-01-10 03:44:12 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2023-08-31 04:48:07 -04:00
# include "SMaterialEditorSubstrateWidget.h"
2023-01-10 03:44:12 -05:00
# include "EditorWidgetsModule.h"
# include "AssetRegistry/AssetRegistryModule.h"
# include "MaterialEditor.h"
2023-08-31 04:47:50 -04:00
# include "SubstrateDefinitions.h"
2023-04-26 06:16:31 -04:00
# include <functional>
2023-01-10 03:44:12 -05:00
# include "Widgets/Input/SButton.h"
# include "Widgets/Input/SCheckBox.h"
# include "Widgets/Layout/SWrapBox.h"
2023-04-26 06:16:31 -04:00
# include "Widgets/Layout/SScrollBox.h"
2023-06-15 05:23:02 -04:00
# include "Widgets/Layout/SBorder.h"
2023-04-26 06:16:31 -04:00
# include "Widgets/SNullWidget.h"
# include "Widgets/Notifications/SErrorText.h"
2023-06-15 05:22:00 -04:00
# include "SGraphSubstrateMaterial.h"
2023-06-15 05:23:17 -04:00
# include "RHIShaderPlatform.h"
2023-01-10 03:44:12 -05:00
2023-09-01 15:06:19 -04:00
# define LOCTEXT_NAMESPACE "SMaterialEditorSubstrateWidget"
2023-01-10 03:44:12 -05:00
2023-09-01 15:06:19 -04:00
DEFINE_LOG_CATEGORY_STATIC ( LogMaterialEditorSubstrateWidget , Log , All ) ;
2023-01-10 03:44:12 -05:00
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : Construct ( const FArguments & InArgs , TWeakPtr < FMaterialEditor > InMaterialEditorPtr )
2023-01-10 03:44:12 -05:00
{
MaterialEditorPtr = InMaterialEditorPtr ;
ButtonApplyToPreview = SNew ( SButton )
. HAlign ( HAlign_Center )
2023-09-01 15:06:19 -04:00
. OnClicked ( this , & SMaterialEditorSubstrateWidget : : OnButtonApplyToPreview )
2023-01-10 03:44:12 -05:00
. Text ( LOCTEXT ( " ButtonApplyToPreview " , " Apply to preview " ) ) ;
CheckBoxForceFullSimplification = SNew ( SCheckBox )
. Padding ( 5.0f )
2023-06-15 05:22:32 -04:00
. ToolTipText ( LOCTEXT ( " CheckBoxForceFullSimplificationToolTip " , " This will force full simplification of the material. " ) ) ;
2023-01-10 03:44:12 -05:00
2024-08-07 06:06:30 -04:00
MaterialBudgetTextBlock = SNew ( STextBlock )
. TextStyle ( FAppStyle : : Get ( ) , " Log.Normal " )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
. Text ( LOCTEXT ( " DescriptionTextBlock_Default " , " Shader is compiling " ) ) ;
2023-04-26 06:16:31 -04:00
DescriptionTextBlock = SNew ( STextBlock )
. TextStyle ( FAppStyle : : Get ( ) , " Log.Normal " )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
. Text ( LOCTEXT ( " DescriptionTextBlock_Default " , " Shader is compiling " ) ) ;
2023-09-01 15:06:19 -04:00
BytesPerPixelOverride = Substrate : : GetBytePerPixel ( SP_PCD3D_SM5 ) ;
2023-06-15 05:22:32 -04:00
BytesPerPixelOverrideInput = SNew ( SNumericEntryBox < uint32 > )
2023-06-15 05:23:02 -04:00
. MinDesiredValueWidth ( 150.0f )
2023-06-15 05:22:32 -04:00
. MinValue ( 12 )
. MaxValue ( BytesPerPixelOverride )
. MinSliderValue ( 12 )
. MaxSliderValue ( BytesPerPixelOverride )
2023-09-01 15:06:19 -04:00
. OnBeginSliderMovement ( this , & SMaterialEditorSubstrateWidget : : OnBeginBytesPerPixelSliderMovement )
. OnEndSliderMovement ( this , & SMaterialEditorSubstrateWidget : : OnEndBytesPerPixelSliderMovement )
2023-06-15 05:22:32 -04:00
. AllowSpin ( true )
2023-09-01 15:06:19 -04:00
. OnValueChanged ( this , & SMaterialEditorSubstrateWidget : : OnBytesPerPixelChanged )
. OnValueCommitted ( this , & SMaterialEditorSubstrateWidget : : OnBytesPerPixelCommitted )
. Value ( this , & SMaterialEditorSubstrateWidget : : GetBytesPerPixelValue )
2023-06-15 05:22:32 -04:00
. IsEnabled ( false ) ;
CheckBoxBytesPerPixelOverride = SNew ( SCheckBox )
. Padding ( 5.0f )
. ToolTipText ( LOCTEXT ( " CheckBoxBytesPerPixelOverride " , " This will force the byte per pixel count for the preview material. It cannot go higher than the current project setting. " ) )
2023-09-01 15:06:19 -04:00
. OnCheckStateChanged ( this , & SMaterialEditorSubstrateWidget : : OnCheckBoxBytesPerPixelChanged ) ;
2023-06-15 05:22:32 -04:00
2023-09-13 10:37:47 -04:00
ClosuresPerPixelOverride = Substrate : : GetClosurePerPixel ( SP_PCD3D_SM5 ) ;
ClosuresPerPixelOverrideInput = SNew ( SNumericEntryBox < uint32 > )
. MinDesiredValueWidth ( 150.0f )
. MinValue ( 1 )
. MaxValue ( ClosuresPerPixelOverride )
. MinSliderValue ( 1 )
. MaxSliderValue ( ClosuresPerPixelOverride )
. OnBeginSliderMovement ( this , & SMaterialEditorSubstrateWidget : : OnBeginClosuresPerPixelSliderMovement )
. OnEndSliderMovement ( this , & SMaterialEditorSubstrateWidget : : OnEndClosuresPerPixelSliderMovement )
. AllowSpin ( true )
. OnValueChanged ( this , & SMaterialEditorSubstrateWidget : : OnClosuresPerPixelChanged )
. OnValueCommitted ( this , & SMaterialEditorSubstrateWidget : : OnClosuresPerPixelCommitted )
. Value ( this , & SMaterialEditorSubstrateWidget : : GetClosuresPerPixelValue )
. IsEnabled ( false ) ;
CheckBoxClosuresPerPixelOverride = SNew ( SCheckBox )
. Padding ( 5.0f )
. ToolTipText ( LOCTEXT ( " CheckBoxClosuresPerPixelOverride " , " This will force the byte per pixel count for the preview material. It cannot go higher than the current project setting. " ) )
. OnCheckStateChanged ( this , & SMaterialEditorSubstrateWidget : : OnCheckBoxClosuresPerPixelChanged ) ;
2023-09-01 15:06:19 -04:00
if ( Substrate : : IsSubstrateEnabled ( ) )
2023-01-10 03:44:12 -05:00
{
this - > ChildSlot
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
2023-04-26 06:16:31 -04:00
//.AutoHeight() // Cannot use that otherwise scrollbars disapear.
2023-06-15 05:23:02 -04:00
. Padding ( 0.0f , 0.0f , 0.0f , 0.0f )
2023-01-10 03:44:12 -05:00
[
2023-04-26 06:16:31 -04:00
SNew ( SScrollBox )
. Orientation ( Orient_Vertical )
. ScrollBarAlwaysVisible ( false )
+ SScrollBox : : Slot ( )
2023-01-10 03:44:12 -05:00
[
2023-04-26 06:16:31 -04:00
SNew ( SVerticalBox )
2023-06-15 05:23:02 -04:00
+ SVerticalBox : : Slot ( )
2023-04-26 06:16:31 -04:00
. AutoHeight ( )
. Padding ( 0.0f , 5.0f , 0.0f , 0.0f )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
2023-06-15 05:23:02 -04:00
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
2023-04-26 06:16:31 -04:00
. VAlign ( VAlign_Center )
[
2023-06-15 05:23:02 -04:00
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
2024-08-07 06:06:30 -04:00
. Text ( LOCTEXT ( " MaterialSimplificationPreview " , " Material Simplification Preview " ) )
2023-04-26 06:16:31 -04:00
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
2023-06-15 05:23:02 -04:00
[
SNew ( SBorder )
//.BorderImage(FAppStyle::GetBrush("DetailsView.CategoryTop"))
//.BorderBackgroundColor(FLinearColor(0.9f, 0.6f, 0.6f, 1.0f))
. Padding ( FMargin ( 5.0f , 5.0f , 5.0f , 5.0f ) )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 20.0 , 0.0 , 0.0 , 0.0 ) // Padding(float Left, float Top, float Right, float Bottom)
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
CheckBoxForceFullSimplification - > AsShared ( )
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
. Text ( LOCTEXT ( " FullsimplificationLabel " , " Full simplification " ) )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( 20.0 , 0.0 , 0.0 , 0.0 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 5.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
CheckBoxBytesPerPixelOverride - > AsShared ( )
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
. Text ( LOCTEXT ( " OverrideBytesPerPixel " , " Override bytes per pixel " ) )
]
+ SHorizontalBox : : Slot ( )
. MaxWidth ( 200 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 0.0 , 0.0 , 0.0 , 0.0 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
BytesPerPixelOverrideInput - > AsShared ( )
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
2023-09-13 10:37:47 -04:00
. Padding ( 20.0 , 0.0 , 0.0 , 0.0 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 5.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
CheckBoxClosuresPerPixelOverride - > AsShared ( )
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
. Text ( LOCTEXT ( " OverrideClosuresPerPixel " , " Override closures per pixel " ) )
]
+ SHorizontalBox : : Slot ( )
. MaxWidth ( 200 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 0.0 , 0.0 , 0.0 , 0.0 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
ClosuresPerPixelOverrideInput - > AsShared ( )
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
2023-06-15 05:23:02 -04:00
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( SWrapBox )
//.UseAllottedSize(true)
+ SWrapBox : : Slot ( )
. Padding ( 20.0 , 0.0 , 0.0 , 0.0 )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
ButtonApplyToPreview - > AsShared ( )
]
]
] // Border
] // VerticalBox
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 15.0f , 0.0f , 0.0f )
2023-04-26 06:16:31 -04:00
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
2023-06-15 05:23:02 -04:00
+ SWrapBox : : Slot ( )
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
2023-04-26 06:16:31 -04:00
. VAlign ( VAlign_Center )
[
2023-06-15 05:23:02 -04:00
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
2024-08-07 06:06:30 -04:00
. Text ( LOCTEXT ( " MaterialTopologyPreview " , " Material Topology Preview " ) )
2023-06-15 05:23:02 -04:00
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 0.0f , 0.0f , 0.0f )
[
SNew ( SBorder )
//.BorderImage(FAppStyle::GetBrush("DetailsView.CategoryTop"))
//.BorderBackgroundColor(FLinearColor(0.9f, 0.6f, 0.6f, 1.0f))
. Padding ( FMargin ( 5.0f , 5.0f , 5.0f , 5.0f ) )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 10.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
[
SAssignNew ( MaterialBox , SBox )
]
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 15.0f , 0.0f , 0.0f )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
2024-08-07 06:06:30 -04:00
. Text ( LOCTEXT ( " MaterialBudgetTextBlock " , " Material Budget " ) )
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 0.0f , 0.0f , 0.0f )
[
SNew ( SBorder )
. Padding ( FMargin ( 5.0f , 5.0f , 5.0f , 5.0f ) )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 5.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
[
MaterialBudgetTextBlock - > AsShared ( )
]
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 15.0f , 0.0f , 0.0f )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 0.0f )
. HAlign ( HAlign_Left )
. VAlign ( VAlign_Center )
[
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : White )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
. Text ( LOCTEXT ( " MaterialAdvancedDetails " , " Material Advanced Details " ) )
2023-06-15 05:23:02 -04:00
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 0.0f , 0.0f , 0.0f )
[
SNew ( SBorder )
//.BorderImage(FAppStyle::GetBrush("DetailsView.CategoryTop"))
//.BorderBackgroundColor(FLinearColor(0.9f, 0.6f, 0.6f, 1.0f))
. Padding ( FMargin ( 5.0f , 5.0f , 5.0f , 5.0f ) )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 5.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
[
DescriptionTextBlock - > AsShared ( )
]
2023-04-26 06:16:31 -04:00
]
2023-01-10 04:22:18 -05:00
]
2023-01-10 03:44:12 -05:00
]
]
] ;
}
else
{
this - > ChildSlot
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 5.0f , 0.0f , 0.0f )
[
SNew ( SWrapBox )
. UseAllottedSize ( true )
+ SWrapBox : : Slot ( )
. Padding ( 5.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
[
SNew ( STextBlock )
. ColorAndOpacity ( FLinearColor : : Yellow )
. ShadowColorAndOpacity ( FLinearColor : : Black )
. ShadowOffset ( FVector2D : : UnitVector )
2024-10-01 19:28:46 -04:00
. Text ( LOCTEXT ( " SubstrateWidgetNotEnable " , " Details cannot be shown: Substrate (Beta) is not enabled for this project (See the project settings window, rendering settings section). " ) )
2023-01-10 03:44:12 -05:00
]
]
] ;
}
}
2023-09-01 15:06:19 -04:00
TSharedRef < SWidget > SMaterialEditorSubstrateWidget : : GetContent ( )
2023-01-10 03:44:12 -05:00
{
return SharedThis ( this ) ;
}
2023-09-01 15:06:19 -04:00
SMaterialEditorSubstrateWidget : : ~ SMaterialEditorSubstrateWidget ( )
2023-01-10 03:44:12 -05:00
{
}
2023-10-05 08:25:08 -04:00
static FString SubstrateMaterialTypeToString ( uint8 InMaterialType )
{
switch ( InMaterialType )
{
case SUBSTRATE_MATERIAL_TYPE_SIMPLE : return FString : : Printf ( TEXT ( " SIMPLE (Diffuse, albedo, roughness) \r \n " ) ) ;
case SUBSTRATE_MATERIAL_TYPE_SINGLE : return FString : : Printf ( TEXT ( " SINGLE (BSDF all features except anisotropy) \r \n " ) ) ;
case SUBSTRATE_MATERIAL_TYPE_COMPLEX : return FString : : Printf ( TEXT ( " COMPLEX (Anisotropy, multi-slabs) \r \n " ) ) ;
case SUBSTRATE_MATERIAL_TYPE_COMPLEX_SPECIAL : return FString : : Printf ( TEXT ( " COMPLEX SPECIAL (Glints, specular profile) \r \n " ) ) ;
default : return FString : : Printf ( TEXT ( " UNKOWN => ERROR! \r \n " ) ) ;
}
}
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : Tick ( const FGeometry & AllottedGeometry , const double InCurrentTime , const float InDeltaTime )
2023-01-10 03:44:12 -05:00
{
2023-09-01 15:06:19 -04:00
if ( ! bUpdateRequested | | ! Substrate : : IsSubstrateEnabled ( ) )
2023-04-26 06:16:31 -04:00
{
return ;
}
bUpdateRequested = false ;
2023-09-01 15:06:19 -04:00
FText SubstrateMaterialDescription ;
2023-04-26 06:16:31 -04:00
if ( MaterialEditorPtr . IsValid ( ) )
{
auto MaterialEditor = MaterialEditorPtr . Pin ( ) ;
UMaterial * MaterialForStats = MaterialEditor - > bStatsFromPreviewMaterial ? MaterialEditor - > Material : MaterialEditor - > OriginalMaterial ;
2023-09-01 15:06:19 -04:00
SubstrateMaterialDescription = FText : : FromString ( FString ( TEXT ( " SubstrateMaterialDescription " ) ) ) ;
2023-04-26 06:16:31 -04:00
const FMaterialResource * MaterialResource = MaterialForStats - > GetMaterialResource ( GMaxRHIFeatureLevel ) ;
if ( MaterialResource )
{
FString MaterialDescription ;
2024-08-07 06:06:30 -04:00
FString MaterialBudget ;
2023-04-26 06:16:31 -04:00
2024-08-07 06:06:30 -04:00
bool bMaterialOutOfBudgetHasBeenSimplified = false ;
2023-04-26 06:16:31 -04:00
FMaterialShaderMap * ShaderMap = MaterialResource - > GetGameThreadShaderMap ( ) ;
if ( ShaderMap )
{
2023-09-01 15:06:19 -04:00
const FSubstrateMaterialCompilationOutput & CompilationOutput = ShaderMap - > GetSubstrateMaterialCompilationOutput ( ) ;
const uint32 FinalPixelByteCount = CompilationOutput . SubstrateUintPerPixel * sizeof ( uint32 ) ;
2024-08-07 06:06:30 -04:00
const uint32 FinalPixelClosureCount = CompilationOutput . SubstrateClosureCount ;
bMaterialOutOfBudgetHasBeenSimplified = CompilationOutput . bMaterialOutOfBudgetHasBeenSimplified > 0 ;
2023-04-26 06:16:31 -04:00
2024-08-07 06:06:30 -04:00
if ( bMaterialOutOfBudgetHasBeenSimplified )
2023-04-26 06:16:31 -04:00
{
2024-08-07 06:06:30 -04:00
MaterialBudget + = FString : : Printf ( TEXT ( " The material was OUT-OF-BUDGET so it has been simplified: Requested bytes = %i / budget = %i - Requested Closures = %i / budget = %i \r \n " ) ,
2023-09-13 10:53:08 -04:00
CompilationOutput . RequestedBytePerPixel , CompilationOutput . PlatformBytePerPixel ,
2023-09-13 10:37:47 -04:00
CompilationOutput . RequestedClosurePerPixel , CompilationOutput . PlatformClosurePixel ) ;
2024-08-07 06:06:30 -04:00
MaterialBudget + = FString : : Printf ( TEXT ( " Final per pixel byte count = %i \r \n " ) , FinalPixelByteCount ) ;
MaterialBudget + = FString : : Printf ( TEXT ( " Final per pixel closure count = %i \r \n " ) , FinalPixelClosureCount ) ;
2023-04-26 06:16:31 -04:00
}
else
{
2024-08-07 06:06:30 -04:00
MaterialBudget + = FString : : Printf ( TEXT ( " Material per pixel byte count = %i / budget = %i \r \n " ) ,
2023-09-13 10:53:08 -04:00
FinalPixelByteCount , CompilationOutput . PlatformBytePerPixel ) ;
2024-08-07 06:06:30 -04:00
MaterialBudget + = FString : : Printf ( TEXT ( " Material per pixel closure count = %i / budget = %i \r \n " ) ,
FinalPixelClosureCount , CompilationOutput . PlatformClosurePixel ) ;
2023-04-26 06:16:31 -04:00
}
2024-08-07 06:06:30 -04:00
MaterialDescription + = FString : : Printf ( TEXT ( " Closures Count = %i \r \n " ) , CompilationOutput . SubstrateClosureCount ) ;
2023-04-26 06:16:31 -04:00
MaterialDescription + = FString : : Printf ( TEXT ( " Local bases Count = %i \r \n " ) , CompilationOutput . SharedLocalBasesCount ) ;
2023-10-05 08:25:08 -04:00
MaterialDescription + = FString : : Printf ( TEXT ( " Material complexity = %s \r \n " ) , * SubstrateMaterialTypeToString ( CompilationOutput . SubstrateMaterialType ) ) ;
2023-05-19 11:36:49 -04:00
MaterialDescription + = FString : : Printf ( TEXT ( " Root Node Is Thin = %i \r \n " ) , CompilationOutput . bIsThin ) ;
2023-09-01 15:06:19 -04:00
//if (CompilationOutput.SubstrateBSDFCount == 1)
2023-05-19 11:36:49 -04:00
//{
2023-09-01 15:06:19 -04:00
// auto GetSingleOperatorBSDF = [&](const FSubstrateOperator& Op)
2023-05-19 11:36:49 -04:00
// {
// switch (Op.OperatorType)
// {
2023-09-01 15:06:19 -04:00
// case SUBSTRATE_OPERATOR_WEIGHT:
2023-05-19 11:36:49 -04:00
// {
// return ProcessOperator(CompilationOutput.Operators[Op.LeftIndex]); // Continue walking the tree
// break;
// }
2023-09-01 15:06:19 -04:00
// case SUBSTRATE_OPERATOR_VERTICAL:
// case SUBSTRATE_OPERATOR_HORIZONTAL:
// case SUBSTRATE_OPERATOR_ADD:
2023-05-19 11:36:49 -04:00
// {
2023-09-01 15:06:19 -04:00
// return nullptr; // A operator with multiple entries must use slabs and so should be a Substrate material made of slabs
2023-05-19 11:36:49 -04:00
// break;
// }
2023-09-01 15:06:19 -04:00
// case SUBSTRATE_OPERATOR_BSDF_LEGACY:
// case SUBSTRATE_OPERATOR_BSDF:
2023-05-19 11:36:49 -04:00
// {
// return Op;
// break;
// }
// }
// return nullptr;
// };
2023-09-01 15:06:19 -04:00
// const FSubstrateOperator& RootOperator = CompilationOutput.Operators[CompilationOutput.RootOperatorIndex];
// const FSubstrateOperator* OpBSDF = GetSingleOperatorBSDF(RootOperator);
2023-05-19 11:36:49 -04:00
//
// if (OpBSDF)
// {
2023-09-01 15:06:19 -04:00
// // SUBSTRATE_TODO gather information about SSSPRofile, subsurface, two sided, etc?
2023-05-19 11:36:49 -04:00
// }
//}
FString MaterialType ;
switch ( CompilationOutput . MaterialType )
{
case SUBSTRATE_MATERIAL_TYPE_SINGLESLAB : MaterialType = TEXT ( " Single Slab " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_MULTIPLESLABS : MaterialType = TEXT ( " Multiple Slabs " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_VOLUMETRICFOGCLOUD : MaterialType = TEXT ( " Volumetric (Fog or Cloud) " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_UNLIT : MaterialType = TEXT ( " Unlit " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_HAIR : MaterialType = TEXT ( " Hair " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_SINGLELAYERWATER : MaterialType = TEXT ( " SingleLayerWater " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_EYE : MaterialType = TEXT ( " Eye " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_LIGHTFUNCTION : MaterialType = TEXT ( " LightFunction " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_POSTPROCESS : MaterialType = TEXT ( " PostProcess " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_UI : MaterialType = TEXT ( " UI " ) ; break ;
case SUBSTRATE_MATERIAL_TYPE_DECAL : MaterialType = TEXT ( " Decal " ) ; break ;
}
FString MaterialTypeDetail ;
if ( ( CompilationOutput . MaterialType = = SUBSTRATE_MATERIAL_TYPE_SINGLESLAB | | CompilationOutput . MaterialType = = SUBSTRATE_MATERIAL_TYPE_MULTIPLESLABS ) & & CompilationOutput . bIsThin )
{
MaterialTypeDetail = TEXT ( " (Thin Surface / Two-Sided Lighting) " ) ;
}
MaterialDescription + = FString : : Printf ( TEXT ( " Material Type = %s %s \r \n " ) , * MaterialType , * MaterialTypeDetail ) ;
2023-05-19 09:18:23 -04:00
2023-04-26 06:16:31 -04:00
MaterialDescription + = FString : : Printf ( TEXT ( " \r \n " ) ) ;
MaterialDescription + = FString : : Printf ( TEXT ( " \r \n " ) ) ;
MaterialDescription + = FString : : Printf ( TEXT ( " ================================================================================ \r \n " ) ) ;
MaterialDescription + = FString : : Printf ( TEXT ( " ================================Detailed Output================================= \r \n " ) ) ;
MaterialDescription + = FString : : Printf ( TEXT ( " ================================================================================ \r \n " ) ) ;
2023-09-01 15:06:19 -04:00
MaterialDescription + = CompilationOutput . SubstrateMaterialDescription ;
2023-04-26 06:16:31 -04:00
// Now generate a visual representation of the material from the topology tree of operators.
2023-11-13 13:21:33 -05:00
if ( CompilationOutput . RootOperatorIndex > = 0 )
{
MaterialBox - > SetContent ( FSubstrateWidget : : ProcessOperator ( CompilationOutput ) ) ;
}
else
{
// The tree does not looks sane so generate a visual error without crashing.
auto TreeError = SNew ( SErrorText )
. ErrorText ( LOCTEXT ( " TreeError " , " Tree Error " ) )
. BackgroundColor ( FSlateColor ( EStyleColor : : AccentRed ) ) ;
const TSharedRef < SWidget > & TreeErrorAsShared = TreeError - > AsShared ( ) ;
MaterialBox - > SetContent ( TreeErrorAsShared ) ;
}
2023-04-26 06:16:31 -04:00
}
else
{
MaterialDescription = TEXT ( " Shader map not found. " ) ;
MaterialBox - > SetContent ( SNullWidget : : NullWidget ) ;
}
2024-08-07 06:06:30 -04:00
if ( bMaterialOutOfBudgetHasBeenSimplified )
{
MaterialBudgetTextBlock - > SetColorAndOpacity ( FLinearColor ( 0.8 , 0.5f , 0.07f , 1.0f ) ) ; // Same color as Graph.WarningText
}
else
{
MaterialBudgetTextBlock - > SetColorAndOpacity ( FLinearColor : : White ) ;
}
MaterialBudgetTextBlock - > SetText ( FText : : FromString ( MaterialBudget ) ) ;
2023-04-26 06:16:31 -04:00
DescriptionTextBlock - > SetText ( FText : : FromString ( MaterialDescription ) ) ;
}
}
2023-01-10 03:44:12 -05:00
}
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : OnBytesPerPixelChanged ( uint32 NewValue )
2023-06-15 05:23:02 -04:00
{
BytesPerPixelOverride = NewValue ;
}
2023-06-15 05:22:32 -04:00
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : OnBytesPerPixelCommitted ( uint32 NewValue , ETextCommit : : Type InCommitType )
2023-06-15 05:22:32 -04:00
{
if ( InCommitType = = ETextCommit : : OnEnter )
{
BytesPerPixelOverride = NewValue ;
}
}
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : OnBeginBytesPerPixelSliderMovement ( )
2023-06-15 05:22:32 -04:00
{
if ( bBytesPerPixelStartedTransaction = = false )
{
bBytesPerPixelStartedTransaction = true ;
GEditor - > BeginTransaction ( LOCTEXT ( " PastePoseTransation " , " Paste Pose " ) ) ;
}
}
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : OnEndBytesPerPixelSliderMovement ( uint32 NewValue )
2023-06-15 05:22:32 -04:00
{
if ( bBytesPerPixelStartedTransaction )
{
GEditor - > EndTransaction ( ) ;
bBytesPerPixelStartedTransaction = false ;
BytesPerPixelOverride = NewValue ;
}
}
2023-09-01 15:06:19 -04:00
TOptional < uint32 > SMaterialEditorSubstrateWidget : : GetBytesPerPixelValue ( ) const
2023-06-15 05:22:32 -04:00
{
return BytesPerPixelOverride ;
}
2023-09-01 15:06:19 -04:00
void SMaterialEditorSubstrateWidget : : OnCheckBoxBytesPerPixelChanged ( ECheckBoxState InCheckBoxState )
2023-06-15 05:22:32 -04:00
{
BytesPerPixelOverrideInput - > SetEnabled ( InCheckBoxState = = ECheckBoxState : : Checked ) ;
}
2023-09-13 10:37:47 -04:00
void SMaterialEditorSubstrateWidget : : OnClosuresPerPixelChanged ( uint32 NewValue )
{
ClosuresPerPixelOverride = NewValue ;
}
void SMaterialEditorSubstrateWidget : : OnClosuresPerPixelCommitted ( uint32 NewValue , ETextCommit : : Type InCommitType )
{
if ( InCommitType = = ETextCommit : : OnEnter )
{
ClosuresPerPixelOverride = NewValue ;
}
}
void SMaterialEditorSubstrateWidget : : OnBeginClosuresPerPixelSliderMovement ( )
{
if ( bClosuresPerPixelStartedTransaction = = false )
{
bClosuresPerPixelStartedTransaction = true ;
GEditor - > BeginTransaction ( LOCTEXT ( " PastePoseTransation " , " Paste Pose " ) ) ;
}
}
void SMaterialEditorSubstrateWidget : : OnEndClosuresPerPixelSliderMovement ( uint32 NewValue )
{
if ( bClosuresPerPixelStartedTransaction )
{
GEditor - > EndTransaction ( ) ;
bClosuresPerPixelStartedTransaction = false ;
ClosuresPerPixelOverride = NewValue ;
}
}
TOptional < uint32 > SMaterialEditorSubstrateWidget : : GetClosuresPerPixelValue ( ) const
{
return ClosuresPerPixelOverride ;
}
void SMaterialEditorSubstrateWidget : : OnCheckBoxClosuresPerPixelChanged ( ECheckBoxState InCheckBoxState )
{
ClosuresPerPixelOverrideInput - > SetEnabled ( InCheckBoxState = = ECheckBoxState : : Checked ) ;
}
2023-09-01 15:06:19 -04:00
FReply SMaterialEditorSubstrateWidget : : OnButtonApplyToPreview ( )
2023-01-10 03:44:12 -05:00
{
if ( MaterialEditorPtr . IsValid ( ) )
{
UMaterialInterface * MaterialInterface = MaterialEditorPtr . Pin ( ) - > GetMaterialInterface ( ) ;
2023-09-01 15:06:19 -04:00
FSubstrateCompilationConfig SubstrateCompilationConfig ;
SubstrateCompilationConfig . bFullSimplify = CheckBoxForceFullSimplification - > IsChecked ( ) ;
2023-06-15 05:23:17 -04:00
2023-09-13 10:37:47 -04:00
// Have a look at MaterialStats.cpp when we want to visualize a specific platform.
SubstrateCompilationConfig . BytesPerPixelOverride = CheckBoxBytesPerPixelOverride - > IsChecked ( ) ? FMath : : Clamp ( BytesPerPixelOverride , 12 , Substrate : : GetBytePerPixel ( GMaxRHIShaderPlatform ) ) : - 1 ;
SubstrateCompilationConfig . ClosuresPerPixelOverride = CheckBoxClosuresPerPixelOverride - > IsChecked ( ) ? FMath : : Clamp ( ClosuresPerPixelOverride , 1 , Substrate : : GetClosurePerPixel ( GMaxRHIShaderPlatform ) ) : - 1 ;
2023-06-15 05:23:17 -04:00
2023-09-01 15:06:19 -04:00
MaterialInterface - > SetSubstrateCompilationConfig ( SubstrateCompilationConfig ) ;
2023-01-10 03:44:12 -05:00
MaterialInterface - > ForceRecompileForRendering ( ) ;
}
return FReply : : Handled ( ) ;
}
# undef LOCTEXT_NAMESPACE