3ds Max DirectLink: Physical Material with ClearCoat to UEPbr

- Converted Max Physical Material to Datasmith UEPbr, including Clear coat

- Testcases:
- Opaque
- Simple Transparent Max material exported as simple transparency(no refraction, ior)
- Advanced Transparent Max material exported as refractive material
- ClearCoat(ior, roughness used)
- Added ThinTranslucent variant(when Max material is ThinWalled or IOR it 1.0)
- Reflection converted to Specular

- Additionally: Fixed transparency color map, emission map/color map that was broken

#jira UETOOL-4571 UETOOL-4900
#preflight 61f7d274e55232619f81a549
#rb benoit.deschenes

[CL 18791909 by kerim borchaev in ue5-main branch]
This commit is contained in:
kerim borchaev
2022-01-31 12:14:34 -05:00
parent 8d2edc2a0d
commit 94d7329fdc
8 changed files with 853 additions and 5 deletions

View File

@@ -424,15 +424,15 @@ void FDatasmithMaxMatWriter::ExportPhysicalMaterial(TSharedRef< IDatasmithScene
{
TransparencyMap = ParamBlock2->GetTexmap(ParamDefinition.ID, GetCOREInterface()->GetTime());
}
else if (FCString::Stricmp(ParamDefinition.int_name, TEXT("Transparency_Color_Map")) == 0)
else if (FCString::Stricmp(ParamDefinition.int_name, TEXT("trans_color_map")) == 0)
{
TransparencyColorMap = ParamBlock2->GetTexmap(ParamDefinition.ID, GetCOREInterface()->GetTime());
}
else if (FCString::Stricmp(ParamDefinition.int_name, TEXT("Emittance_Map")) == 0)
else if (FCString::Stricmp(ParamDefinition.int_name, TEXT("Emission_Map")) == 0)
{
EmittanceMap = ParamBlock2->GetTexmap(ParamDefinition.ID, GetCOREInterface()->GetTime());
}
else if (FCString::Stricmp(ParamDefinition.int_name, TEXT("Emittance_Color_Map")) == 0)
else if (FCString::Stricmp(ParamDefinition.int_name, TEXT("Emission_Color_Map")) == 0)
{
EmittanceColorMap = ParamBlock2->GetTexmap(ParamDefinition.ID, GetCOREInterface()->GetTime());
}

View File

@@ -11,7 +11,9 @@
#include "MaxMaterialsToUEPbr/DatasmithMaxCoronaMaterialsToUEPbr.h"
#include "MaxMaterialsToUEPbr/DatasmithMaxScanlineMaterialsToUEPbr.h"
#include "MaxMaterialsToUEPbr/DatasmithMaxVrayMaterialsToUEPbr.h"
#include "MaxMaterialsToUEPbr/DatasmithMaxPhysicalMaterialToUEPbr.h"
#define PHYSICALMATCLASS_UEPbr
FDatasmithMaxMaterialsToUEPbr* FDatasmithMaxMaterialsToUEPbrManager::GetMaterialConverter( Mtl* Material )
{
@@ -63,6 +65,14 @@ FDatasmithMaxMaterialsToUEPbr* FDatasmithMaxMaterialsToUEPbrManager::GetMaterial
static FDatasmithMaxCoronaBlendMaterialToUEPbr CoronaConverter = FDatasmithMaxCoronaBlendMaterialToUEPbr();
MaterialConverter = &CoronaConverter;
}
#ifdef PHYSICALMATCLASS_UEPbr
else if (MaterialClassID == PHYSICALMATCLASS)
{
static FDatasmithMaxPhysicalMaterialToUEPbr PhysicalConverter = FDatasmithMaxPhysicalMaterialToUEPbr();
MaterialConverter = &PhysicalConverter;
}
#endif
if ( MaterialConverter && MaterialConverter->IsSupported( Material ) )
{

View File

@@ -0,0 +1,64 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "DatasmithMaxMaterialsToUEPbr.h"
class IDatasmithMaterialExpression;
class IDatasmithMaterialExpressionScalar;
class IDatasmithMaterialExpressionColor;
class IDatasmithMaterialExpressionGeneric;
class IDatasmithExpressionInput;
class FDatasmithMaxMaterialsToUEPbrExpressions: public FDatasmithMaxMaterialsToUEPbr
{
public:
TSharedPtr<IDatasmithUEPbrMaterialElement> GetMaterialElement();
IDatasmithMaterialExpressionScalar& Scalar(float Value);
IDatasmithMaterialExpressionColor& Color(const FLinearColor& Value);
IDatasmithMaterialExpression* WeightTextureOrScalar(const DatasmithMaxTexmapParser::FMapParameter& TextureWeight, float Weight);
IDatasmithMaterialExpressionGeneric& Add(IDatasmithMaterialExpression& A, IDatasmithMaterialExpression& B);
IDatasmithMaterialExpressionGeneric& Subtract(IDatasmithMaterialExpression& A, IDatasmithMaterialExpression& B);
IDatasmithMaterialExpressionGeneric& Multiply(IDatasmithMaterialExpression& A, IDatasmithMaterialExpression& B);
IDatasmithMaterialExpressionGeneric& Divide(IDatasmithMaterialExpression& A, IDatasmithMaterialExpression& B);
IDatasmithMaterialExpressionGeneric& Desaturate(IDatasmithMaterialExpression& A);
IDatasmithMaterialExpressionGeneric& Power(IDatasmithMaterialExpression& A, IDatasmithMaterialExpression& B);
IDatasmithMaterialExpressionGeneric& Lerp(IDatasmithMaterialExpression& A, IDatasmithMaterialExpression& B, IDatasmithMaterialExpression& Alpha);
IDatasmithMaterialExpressionGeneric& Fresnel(IDatasmithMaterialExpression* Exponent=nullptr, IDatasmithMaterialExpression* BaseReflectFraction=nullptr); // Any input can be null
IDatasmithMaterialExpression* ApplyWeightExpression(IDatasmithMaterialExpression* ValueExpression, IDatasmithMaterialExpression* WeightExpression);
IDatasmithMaterialExpression& CalcIORComplex(double IORn, double IORk, IDatasmithMaterialExpression& ToBeConnected90, IDatasmithMaterialExpression& ToBeConnected0);
void Connect(IDatasmithExpressionInput& Input, IDatasmithMaterialExpression& ValueExpression);
bool Connect(IDatasmithExpressionInput& Input, IDatasmithMaterialExpression* ValueExpression); // Connect if not null
IDatasmithMaterialExpression* TextureOrColor(const TCHAR* Name,
const DatasmithMaxTexmapParser::FMapParameter& Map, FLinearColor Color);
IDatasmithMaterialExpression* TextureOrScalar(const TCHAR* Name,
const DatasmithMaxTexmapParser::FMapParameter& Map, float Value);
IDatasmithMaterialExpressionGeneric& OneMinus(IDatasmithMaterialExpression& Expression);
};
class FDatasmithMaxPhysicalMaterialToUEPbr : public FDatasmithMaxMaterialsToUEPbrExpressions
{
public:
virtual bool IsSupported( Mtl* Material ) override;
virtual void Convert( TSharedRef< IDatasmithScene > DatasmithScene, TSharedPtr< IDatasmithBaseMaterialElement >& MaterialElement, Mtl* Material, const TCHAR* AssetsPath ) override;
};

View File

@@ -76,7 +76,7 @@ namespace DatasmithMaxScanlineMaterialsToUEPbrImpl
ScanlineMaterialProperties.SpecularLevel = Material.GetShinStr();
ScanlineMaterialProperties.Glossiness = Material.GetShininess();
ScanlineMaterialProperties.bUseSelfIllumColor = ( Material.GetSelfIllumColorOn() != 0 );
ScanlineMaterialProperties.SelfIllumColor = FDatasmithMaxMatHelper::MaxColorToFLinearColor( (BMM_Color_fl)Material.GetSelfIllumColor() );
ScanlineMaterialProperties.SelfIllumColor = FDatasmithMaxMatHelper::MaxColorToFLinearColor( (BMM_Color_fl)Material.GetSelfIllumColor() ); // todo: this seems wrong(converting color to gamme space)
const TimeValue CurrentTime = GetCOREInterface()->GetTime();

View File

@@ -1736,6 +1736,10 @@ bool FDatasmithMaxPassthroughToUEPbr::IsSupported( const FDatasmithMaxMaterialsT
{
return true;
}
else if ( InTexmap->ClassID() == COLORMAPCLASS )
{
return true;
}
}
return false;

View File

@@ -36,6 +36,8 @@
#define MRPHYSICALSKYBCLASS Class_ID(0x223349b4, 0x562a7d8b)
#define THIRDPARTYMULTITEXCLASS Class_ID(0x55c6d763, 0xc637bb2e)
#define TILESMAPCLASS Class_ID(0x64035fb9, 0x69664cdc)
#define COLORMAPCLASS Class_ID(0x139f22c6, 0x13f6a914)
#define VRAYNORMALCLASS Class_ID(0x71fa6e51, 0x72057c2f)
#define VRAYCOLORCLASS Class_ID(0x58f82b74, 0x73b75d7f)

View File

@@ -90,7 +90,7 @@ public:
static bool HasNonBakeableSubmap(Texmap* InTexmap);
static FLinearColor MaxColorToFLinearColor(BMM_Color_fl Color, float Multiplier = 1.0f);
static FLinearColor MaxColorToFLinearColor(BMM_Color_fl Color, float Multiplier = 1.0f); // todo: rename, although result type is FLinearColor this function does pow(rgb, 1/gamma), i.e. converting to gamma-space
static FLinearColor MaxLinearColorToFLinearColor(BMM_Color_fl Color, float Multiplier = 1.0f);
static float GetBitmapGamma(BitmapTex* InBitmapTex);
static float GetBitmapGamma(BitmapInfo* InBitmapInfo);