16101301(MaterialLOD QualitySwitch)

【目标】

MaterialLOD QualitySwitch

【思路】

QualitySwitch

UE4有三挡



UE3



2 现在UE3需要添加三挡




3

UE3

class UMaterialExpressionQualitySwitch : public UMaterialExpression
{
public:
    //## BEGIN PROPS MaterialExpressionQualitySwitch
    FExpressionInput High;
    FExpressionInput Low;



4









【步骤】

1 修改UMaterialExpressionQualitySwitch 

ue3DevelopmentSrcEngineClassesMaterialExpressionQualitySwitch.uc

var ExpressionInput High;
var ExpressionInput Mid;
var ExpressionInput Low;





2 修改EMaterialShaderQuality 添加中级

enum EMaterialShaderQuality
{
    MSQ_HIGH                =0,
    MSQ_MID                    =1,
    MSQ_LOW                 =2,
    MSQ_MAX                 =3,
    // Terrain only supports high quality
    MSQ_TERRAIN                =MSQ_HIGH,
    // Use an invalid value for default value to functions when not specifying a quality
    MSQ_UNSPECIFIED            =MSQ_MAX,
};



3 修改ue3DevelopmentSrcEngineClassesMaterial.uc

var const native duplicatetransient pointer MaterialResources[3]{FMaterialResource};


修改UMaterial.MaterialResources 相关的



4 UMaterial.Serialize中有序列化的东西


还是要添加个版本号

EUnrealEngineObjectVersion 

    // - Add MaterialShaderQuality Mid
    VER_UNIFORM_EXPRESSIONS_IN_SHADER_CACHE                = 872,


UMaterial.Serialize

            if (
                QualityIndex < 2 ||                    // MaterialResources's old size is 2
                (QualityIndex >=2 && Ar.Ver() >= VER_ADD_EXPRESSIONS_SHADERQUALITY_MID) 
                ) 
            {
                // Serialize the material resource.
                MaterialResources[QualityIndex]->Serialize(Ar);
                if (Ar.Ver() < VER_UNIFORM_EXPRESSIONS_IN_SHADER_CACHE)
                {
                    // If we are loading a material resource saved before texture references were managed by the material resource,
                    // Pass the legacy texture references to the material resource.
                    MaterialResources[QualityIndex]->AddLegacyTextures(ReferencedTextures_DEPRECATED);
                    // Empty legacy texture references on load
                    ReferencedTextures_DEPRECATED.Empty();
                }            
            }


4 修改MSQ_MAX  相关的

UMaterialInstance.StaticPermutationResources 

UMaterialInstance.StaticParameters 

ue3DevelopmentSrcEngineClassesMaterialInstance.uc 改成3个

/**
* The set of static parameters that this instance will be compiled with.
* This is indexed by EMaterialShaderPlatform.
* Only the first entry is ever used now that SM2 is no longer supported,
* But the member is kept as an array to make adding future material platforms easier.
* The second entry is to work around the script compile error from having an array with one element.
*/
var const native duplicatetransient pointer StaticParameters[3]{FStaticParameterSet};
/**
* The material resources for this instance.
* This is indexed by EMaterialShaderPlatform.
* Only the first entry is ever used now that SM2 is no longer supported,
* But the member is kept as an array to make adding future material platforms easier.
* The second entry is to work around the script compile error from having an array with one element.
*/
var const native duplicatetransient pointer StaticPermutationResources[3]{FMaterialResource};


上面直接改uc数组大小的方式 貌似会有问题,序列化会出问题

make报错



手动改h文件 编译exe 再修改uc,make


5 修改FSystemSettings.bAllowHighQualityMaterials 相关

添加一个新的成员

    /** Materials Quality Level    */
    INT        QualityMaterialsLevel;


     /** Materials Quality Level    */
    { SST_INT, SSI_SCALABILITY, TEXT( "QualityMaterialsLevel" ), &GSystemSettings.QualityMaterialsLevel, &VSSMaterilQuality, TEXT( "Materials Quality Level." ) },



FSystemSettings.ApplySettings 

    // Reattach components if world-detail settings have changed.
    if( OldSystemSettings.DetailMode != DetailMode || 
        OldSystemSettings.bAllowHighQualityMaterials != bAllowHighQualityMaterials ||
        OldSystemSettings.QualityMaterialsLevel != QualityMaterialsLevel)
    {


在BaseSystemSettings.ini配置

QualityMaterialsLevel=0


ExampleSystemSettings.ini同理


6 UMaterialInterface.GetDesiredQualityLevel 

        Quality = GSystemSettings.bAllowHighQualityMaterials ? MSQ_HIGH : MSQ_LOW;

改为

         Quality = EMaterialShaderQuality(GSystemSettings.QualityMaterialsLevel);

FMaterial.CacheShaders 

    if (Quality == MSQ_UNSPECIFIED)
    {
        Quality = GSystemSettings.bAllowHighQualityMaterials ? MSQ_HIGH : MSQ_LOW;
    }

改为

     if (Quality == MSQ_UNSPECIFIED)
    {
        Quality = EMaterialShaderQuality(GSystemSettings.QualityMaterialsLevel);
    }


7 修改Material切换按钮响应

void WxEditorFrame::MenuMaterialQualityToggle( wxCommandEvent& In )
{
    // to be safe, we wait until rendering thread is complete
    FlushRenderingCommands();
    // toggle the system setting, mimicing what the console command does - it would be nice
    // if system settings had a function interface instead of console commands
//    GSystemSettings.bAllowHighQualityMaterials ^= 1;
    
    GSystemSettings.QualityMaterialsLevel ++;
    if (GSystemSettings.QualityMaterialsLevel >= EMaterialShaderQuality::MSQ_MAX)
        GSystemSettings.QualityMaterialsLevel = EMaterialShaderQuality::MSQ_HIGH;




8 显示出Quality值到编辑器

WxMaterialEditorBase.DrawMaterialInfoStrings.

        FLinkedObjDrawUtils::DrawShadowedString(
            Canvas,
            5,
            DrawPositionY,
            *FString::Printf(TEXT("Quality[%d] DrawCall: %d Instructions: %d DrawTime:%.6f ms"),
            GSystemSettings.QualityMaterialsLevel,
            PreviewMeshComponent->LastDrawCalls,PreviewMeshComponent->GetUsedMaterialsInstructionCounts(),PreviewMeshComponent->LastDrawTimes),
            FontToUse,
            FLinearColor(0.8,1,1)
            );


9

scale set QualityMaterialsLevel 0-2





【运行】




"/cgi-bin/micromsg-bin/auth";
"/cgi-bin/micromsg-bin/sendmsg";
"/cgi-bin/micromsg-bin/sync";
"/cgi-bin/micromsg-bin/uploadmsgimg";
"/cgi-bin/micromsg-bin/getmsgimg";
"/cgi-bin/micromsg-bin/init";
"/cgi-bin/micromsg-bin/getupdatepack";
"/cgi-bin/micromsg-bin/searchfriend";
"/cgi-bin/micromsg-bin/getinvitefriend";




 

3






原文地址:https://www.cnblogs.com/username/p/6022429.html