Top > エンジン改造-エディター改造-MaterialInstance-Override

MaterialInstance_override01.jpg

参考

Translucency Lighting Modeを追加してみた

  1. Editor\MaterialEditor\Private\MaterialEditorInstanceDetailCustomization.cpp
    • FMaterialInstanceParameterDetails::CreateBasePropertyOverrideWidgets
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
       
       
       
       
       
       
      
          TAttribute<bool> IsOverrideOpacityClipMaskValueEnabled = TAttribute<bool>::Create(TAttribute<bool>::FGetter::CreateSP(this, &FMaterialInstanceParameterDetails::OverrideOpacityClipMaskValueEnabled));
          TAttribute<bool> IsOverrideBlendModeEnabled = TAttribute<bool>::Create(TAttribute<bool>::FGetter::CreateSP(this, &FMaterialInstanceParameterDetails::OverrideBlendModeEnabled));
          TAttribute<bool> IsOverrideShadingModelEnabled = TAttribute<bool>::Create(TAttribute<bool>::FGetter::CreateSP(this, &FMaterialInstanceParameterDetails::OverrideShadingModelEnabled));
      // start -------
          TAttribute<bool> IsOverrideTranslucencyLightingModeEnabled = TAttribute<bool>::Create(TAttribute<bool>::FGetter::CreateSP(this, &FMaterialInstanceParameterDetails::OverrideTranslucencyLightingModeEnabled));
      // end ---------
          TAttribute<bool> IsOverrideTwoSidedEnabled = TAttribute<bool>::Create(TAttribute<bool>::FGetter::CreateSP(this, &FMaterialInstanceParameterDetails::OverrideTwoSidedEnabled));
          TAttribute<bool> IsOverrideDitheredLODTransitionEnabled = TAttribute<bool>::Create(TAttribute<bool>::FGetter::CreateSP(this, &FMaterialInstanceParameterDetails::OverrideDitheredLODTransitionEnabled));
        1
        2
        3
        4
        5
        6
        7
        8
        9
      
       
       
       
       
       
       
       
       
       
      
          TSharedRef<IPropertyHandle> BasePropertyOverridePropery = DetailLayout.GetProperty("BasePropertyOverrides");
          TSharedPtr<IPropertyHandle> OpacityClipMaskValueProperty = BasePropertyOverridePropery->GetChildHandle("OpacityMaskClipValue");
          TSharedPtr<IPropertyHandle> BlendModeProperty = BasePropertyOverridePropery->GetChildHandle("BlendMode");
          TSharedPtr<IPropertyHandle> ShadingModelProperty = BasePropertyOverridePropery->GetChildHandle("ShadingModel");
      // start -------
          TSharedPtr<IPropertyHandle> TranslucencyLightingModeProperty = BasePropertyOverridePropery->GetChildHandle("TranslucencyLightingMode");
      // end ---------
          TSharedPtr<IPropertyHandle> TwoSidedProperty = BasePropertyOverridePropery->GetChildHandle("TwoSided");
          TSharedPtr<IPropertyHandle> DitheredLODTransitionProperty = BasePropertyOverridePropery->GetChildHandle("DitheredLODTransition");
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
       11
       12
       13
      
       
       
       
       
       
       
       
       
       
       
       
       
       
      
          IDetailPropertyRow& ShadingModelPropertyRow = BasePropertyOverrideGroup.AddPropertyRow(ShadingModelProperty.ToSharedRef());
          ShadingModelPropertyRow
              .DisplayName(ShadingModelProperty->GetPropertyDisplayName())
              .ToolTip(ShadingModelProperty->GetToolTipText())
              .EditCondition(IsOverrideShadingModelEnabled, FOnBooleanValueChanged::CreateSP(this, &FMaterialInstanceParameterDetails::OnOverrideShadingModelChanged));
       
      // start -------
          IDetailPropertyRow& TranslucencyLightingModePropertyRow = BasePropertyOverrideGroup.AddPropertyRow(TranslucencyLightingModeProperty.ToSharedRef());
          TranslucencyLightingModePropertyRow
              .DisplayName(TranslucencyLightingModeProperty->GetPropertyDisplayName())
              .ToolTip(TranslucencyLightingModeProperty->GetToolTipText())
              .EditCondition(IsOverrideTranslucencyLightingModeEnabled, FOnBooleanValueChanged::CreateSP(this, &FMaterialInstanceParameterDetails::OnOverrideTranslucencyLightingModeChanged));
      // end ---------
      
    • メソッド追加
        1
        2
        3
        4
        5
        6
      
       
       
      -
      |
      !
       
      
      // start -------
      bool FMaterialInstanceParameterDetails::OverrideTranslucencyLightingModeEnabled() const
      {
          return MaterialEditorInstance->BasePropertyOverrides.bOverride_TranslucencyLightingMode;
      }
      // end ---------
      
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
      -
      |
      |
      |
      !
       
      
      // start -------
      void FMaterialInstanceParameterDetails::OnOverrideTranslucencyLightingModeChanged(bool NewValue)
      {
          MaterialEditorInstance->BasePropertyOverrides.bOverride_TranslucencyLightingMode = NewValue;
          MaterialEditorInstance->PostEditChange();
          FEditorSupportDelegates::RedrawAllViewports.Broadcast();
      }
      // end ---------
      
  2. Editor\MaterialEditor\Private\MaterialEditorInstanceDetailCustomization.h
    • FMaterialInstanceParameterDetails
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
       
       
       
       
       
       
      
          bool OverrideOpacityClipMaskValueEnabled() const;
          bool OverrideBlendModeEnabled() const;
          bool OverrideShadingModelEnabled() const;
      // start -------
          bool OverrideTranslucencyLightingModeEnabled() const;
      // end ---------
          bool OverrideTwoSidedEnabled() const;
          bool OverrideDitheredLODTransitionEnabled() const;
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
       
       
       
       
       
       
      
          void OnOverrideOpacityClipMaskValueChanged(bool NewValue);
          void OnOverrideBlendModeChanged(bool NewValue);
          void OnOverrideShadingModelChanged(bool NewValue);
      // start -------
          void OnOverrideTranslucencyLightingModeChanged(bool NewValue);
      // end ---------
          void OnOverrideTwoSidedChanged(bool NewValue);
          void OnOverrideDitheredLODTransitionChanged(bool NewValue);
  3. Runtime\Engine\Classes\Materials\Material.h
    • UMaterial
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
       
       
       
       
       
       
      
          ENGINE_API virtual float GetOpacityMaskClipValue() const override;
          ENGINE_API virtual EBlendMode GetBlendMode() const override;
          ENGINE_API virtual EMaterialShadingModel GetShadingModel() const override;
      // start -------
          ENGINE_API virtual enum ETranslucencyLightingMode GetTranslucencyLightingMode() const override;
      // end ---------
          ENGINE_API virtual bool IsTwoSided() const override;
          ENGINE_API virtual bool IsDitheredLODTransition() const override;
  4. Runtime\Engine\Classes\Materials\MaterialInstance.h
    • UMaterialInstance
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
       
       
       
       
       
       
      
          float OpacityMaskClipValue;
          TEnumAsByte<EBlendMode> BlendMode;
          TEnumAsByte<EMaterialShadingModel> ShadingModel;
      // start -------
          TEnumAsByte<enum ETranslucencyLightingMode> TranslucencyLightingMode;
      // end ---------
          uint32 TwoSided : 1;
          uint32 DitheredLODTransition : 1;
        1
        2
        3
        4
        5
        6
        7
        8
        9
      
       
       
       
       
       
       
       
       
       
      
          ENGINE_API virtual float GetOpacityMaskClipValue() const override;
          ENGINE_API virtual EBlendMode GetBlendMode() const override;
          ENGINE_API virtual EMaterialShadingModel GetShadingModel() const override;
      // start -------
          ENGINE_API virtual enum ETranslucencyLightingMode GetTranslucencyLightingMode() const override;
      // end ---------
          ENGINE_API virtual bool IsTwoSided() const override;
          ENGINE_API virtual bool IsDitheredLODTransition() const override;
          ENGINE_API virtual bool IsMasked() const override;;
  5. Runtime\Engine\Classes\Materials\MaterialInstanceBasePropertyOverrides.h
    • FMaterialInstanceBasePropertyOverrides
        1
        2
        3
        4
        5
        6
        7
        8
        9
      
       
       
       
       
       
       
       
       
       
      
          /** Enables override of the two sided property. */
          UPROPERTY(EditAnywhere, Category = Material)
          bool bOverride_TwoSided;
       
      // start -------
          /** Enables override of the two sided property. */
          UPROPERTY(EditAnywhere, Category = Material)
          bool bOverride_TranslucencyLightingMode;
      // end ---------
      
        1
        2
        3
        4
        5
        6
        7
        8
        9
      
       
       
       
       
       
       
       
       
       
      
          /** The shading model */
          UPROPERTY(EditAnywhere, Category = Material, meta = (editcondition = "bOverride_ShadingModel"))
          TEnumAsByte<EMaterialShadingModel> ShadingModel;
       
      // start -------
          /** The shading model */
          UPROPERTY(EditAnywhere, Category = Material, meta = (editcondition = "bOverride_TranslucencyLightingMode"))
          TEnumAsByte<enum ETranslucencyLightingMode> TranslucencyLightingMode;
      // end ---------
      
  6. Runtime\Engine\Classes\Materials\MaterialInstanceDynamic.h
    • UMaterialInstanceDynamic
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
      
       
       
       
       
       
       
       
       
       
       
      
          //Material base property overrides. MIDs cannot override these so they just grab from their parent.
          virtual float GetOpacityMaskClipValue() const override;
          virtual EBlendMode GetBlendMode() const override;
          virtual EMaterialShadingModel GetShadingModel() const override;
      // start -------
          virtual enum ETranslucencyLightingMode GetTranslucencyLightingMode() const override;
      // end ---------
          virtual bool IsTwoSided() const override;
          virtual bool IsDitheredLODTransition() const override;
          virtual bool IsMasked() const override;
  7. Runtime\Engine\Classes\Materials\MaterialInterface.h
    • UMaterialInterface
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
       11
      
       
       
       
       
       
       
       
       
       
       
       
      
          ENGINE_API virtual float GetOpacityMaskClipValue() const;
          ENGINE_API virtual EBlendMode GetBlendMode() const;
          ENGINE_API virtual EMaterialShadingModel GetShadingModel() const;
      // start -------
          ENGINE_API virtual enum ETranslucencyLightingMode GetTranslucencyLightingMode() const;
      // end ---------
          ENGINE_API virtual bool IsTwoSided() const;
          ENGINE_API virtual bool IsDitheredLODTransition() const;
          ENGINE_API virtual bool IsTranslucencyWritingCustomDepth() const;
          ENGINE_API virtual bool IsMasked() const;
          ENGINE_API virtual bool IsDeferredDecal() const;
  8. Runtime\Engine\Private\Materials\Material.cpp
    • メソッド追加
        1
        2
        3
        4
        5
        6
      
       
       
      -
      |
      !
       
      
      // start -------
      ETranslucencyLightingMode UMaterial::GetTranslucencyLightingMode() const
      {
          return TranslucencyLightingMode;
      }
      // end ---------
      
  9. Runtime\Engine\Private\Materials\MaterialInstance.cpp
    • メソッド追加
        1
        2
        3
        4
        5
        6
      
       
       
      -
      |
      !
       
      
      // start -------
      ETranslucencyLightingMode UMaterialInstanceDynamic::GetTranslucencyLightingMode() const
      {
          return Parent ? Parent->GetTranslucencyLightingMode() : TLM_VolumetricNonDirectional;
      }
      // end ---------
      
        1
        2
        3
        4
        5
        6
      
       
       
      -
      |
      !
       
      
      // start -------
      ETranslucencyLightingMode UMaterialInstance::GetTranslucencyLightingMode() const
      {
          return TranslucencyLightingMode;
      }
      // end ---------
      
    • UMaterialInstance::UpdateOverridableBaseProperties
        1
        2
        3
        4
        5
        6
        7
        8
      
       
       
       
       
       
       
       
       
      
              OpacityMaskClipValue = 0.0f;
              BlendMode = BLEND_Opaque;
              ShadingModel = MSM_DefaultLit;
      // start -------
              TranslucencyLightingMode = TLM_VolumetricNonDirectional;
      // end ---------
              TwoSided = 0;
              DitheredLODTransition = 0;
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
       11
       12
       13
       14
       15
       16
       17
       18
       19
      
       
      -
      |
      !
       
      -
      |
      !
       
       
       
      -
      |
      !
       
      -
      |
      !
       
      
          if (BasePropertyOverrides.bOverride_ShadingModel)
          {
              ShadingModel = BasePropertyOverrides.ShadingModel;
          }
          else
          {
              ShadingModel = Parent->GetShadingModel();
          }
       
      // start -------
          if (BasePropertyOverrides.bOverride_TranslucencyLightingMode)
          {
              TranslucencyLightingMode = BasePropertyOverrides.TranslucencyLightingMode;
          }
          else
          {
              TranslucencyLightingMode = Parent->GetTranslucencyLightingMode();
          }
      // end ---------
      
    • UMaterialInstance::Serialize
      • 「VER_LIC_COM04_VER01」は自分の改造バージョンを記述する→エンジン改造-アセットのエンジンバージョン管理
          1
          2
          3
          4
          5
          6
          7
          8
          9
         10
         11
         12
         13
         14
         15
        
         
         
        -
        |
        |
        -
        |
        |
        !
        !
         
        -
        |
        !
         
        
                            // unrelated but closest change to bug
                            if( Ar.UE4Ver() < VER_UE4_STATIC_SHADOW_DEPTH_MAPS )
                            {
                                // switched enum order
                                switch( BasePropertyOverrides.ShadingModel )
                                {
                                    case MSM_Unlit:            BasePropertyOverrides.ShadingModel = MSM_DefaultLit; break;
                                    case MSM_DefaultLit:    BasePropertyOverrides.ShadingModel = MSM_Unlit; break;
                                }
                            }
        // start -------
                            if( Ar.LicenseeUE4Ver() >= VER_LIC_COM04_VER01) {
                                Ar << BasePropertyOverrides.bOverride_TranslucencyLightingMode << BasePropertyOverrides.TranslucencyLightingMode;
                            }
        // end ---------
        
    • UMaterialInstance::GetBasePropertyOverridesHash
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
       11
       12
       13
       14
       15
       16
       17
       18
       19
      
       
       
      -
      |
      |
      |
      |
      !
       
       
       
       
      -
      |
      |
      |
      |
      !
       
      
          EMaterialShadingModel UsedShadingModel = GetShadingModel();
           if (UsedShadingModel != Mat->GetShadingModel())
           {
              const FString HashString = TEXT("bOverride_ShadingModel");
              Hash.UpdateWithString(*HashString, HashString.Len());
              Hash.Update((const uint8*)&UsedShadingModel, sizeof(UsedShadingModel));
              bHasOverrides = true;
          }
       
      // start -------
          ETranslucencyLightingMode UsedTranslucencyLightingMode = GetTranslucencyLightingMode();
           if (UsedTranslucencyLightingMode != Mat->GetTranslucencyLightingMode())
           {
              const FString HashString = TEXT("bOverride_TranslucencyLightingMode");
              Hash.UpdateWithString(*HashString, HashString.Len());
              Hash.Update((const uint8*)&UsedTranslucencyLightingMode, sizeof(UsedTranslucencyLightingMode));
              bHasOverrides = true;
          }
      // end ---------
      
    • UMaterialInstance::HasOverridenBaseProperties
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
      
       
       
       
       
       
       
       
       
       
       
      
          if (Parent && Material && Material->bUsedAsSpecialEngineMaterial == false &&
              ((FMath::Abs(GetOpacityMaskClipValue() - Parent->GetOpacityMaskClipValue()) > SMALL_NUMBER) ||
              (GetBlendMode() != Parent->GetBlendMode()) ||
              (GetShadingModel() != Parent->GetShadingModel()) ||
      // start -------
              (GetTranslucencyLightingMode() != Parent->GetTranslucencyLightingMode()) ||
      // end ---------
              (IsTwoSided() != Parent->IsTwoSided()) ||
              (IsDitheredLODTransition() != Parent->IsDitheredLODTransition()))
              )
  10. Runtime\Engine\Private\Materials\MaterialInterface.cpp
    • メソッド追加
        1
        2
        3
        4
        5
        6
      
       
       
      -
      |
      !
       
      
      // start -------
      ETranslucencyLightingMode UMaterialInterface::GetTranslucencyLightingMode() const
      {
          return TLM_VolumetricNonDirectional;
      }
      // end ---------
      
  11. Runtime\Engine\Private\Materials\MaterialShared.cpp
    • FMaterialResource::GetTranslucencyLightingMode
        1
        2
        3
        4
        5
        6
      
       
      -
      |
      |
      |
      !
      
      ETranslucencyLightingMode FMaterialResource::GetTranslucencyLightingMode() const
      {
      // start -------
          return (ETranslucencyLightingMode)(MaterialInstance ? MaterialInstance->GetTranslucencyLightingMode() : Material->GetTranslucencyLightingMode());
      // end ---------
      }
    • FMaterialInstanceBasePropertyOverrides::FMaterialInstanceBasePropertyOverrides
        1
        2
        3
        4
        5
        6
        7
      
       
       
       
       
       
       
       
      
          ,bOverride_ShadingModel(false)
          ,bOverride_DitheredLODTransition(false)
          ,bOverride_TwoSided(false)
      // start -------
          ,bOverride_TranslucencyLightingMode(false)
      // end ---------
          ,OpacityMaskClipValue(.333333f)
    • FMaterialInstanceBasePropertyOverrides::operator==
        1
        2
        3
        4
        5
        6
        7
      
       
       
       
       
       
       
       
      
                  bOverride_ShadingModel == Other.bOverride_ShadingModel &&
                  bOverride_TwoSided == Other.bOverride_TwoSided &&
                  bOverride_DitheredLODTransition == Other.bOverride_DitheredLODTransition &&
      // start -------
                  bOverride_TranslucencyLightingMode == Other.bOverride_TranslucencyLightingMode &&
      // end ---------
                  OpacityMaskClipValue == Other.OpacityMaskClipValue &&

添付ファイル: fileMaterialInstance_override01.jpg 141件 [詳細]

リロード   新規 編集 凍結 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2017-05-04 (木) 14:17:48 (1164d)