Download

[shadingModel]** New Custom ShadingModel Don’t Work[4-26]

[shadingModel] New Custom ShadingModel Don’t Work


Hi~ I Need For Help ~ Thank You !

A.When I add my new shadingModel Toon ,I found that after I modify its BxDF function , it don’t work(Step 14)


Lighting.Diffuse = AreaLight.FalloffColor * Falloff * step(0.5f,NoL) * Diffuse_Lambert(GBuffer.DiffuseColor);

//Lighting.Diffuse = AreaLight.FalloffColor * (Falloff * NoL) * Diffuse_Lambert( GBuffer.DiffuseColor );

B.But when I modify same codes to the DefaultLitBxDF, the default material and the new Toon material both changed to with what I need(Step 15)


Lighting.Diffuse = AreaLight.FalloffColor * Falloff * step(0.5f,NoL) * Diffuse_Lambert(GBuffer.DiffuseColor);

//Lighting.Diffuse = AreaLight.FalloffColor * (Falloff * NoL) * Diffuse_Lambert( GBuffer.DiffuseColor );

Q:Why I modify the default ShadingModel changed the custom ShadingModel, but only modify costom ShadingModel don’t work ?

How can I just modify custom BxDF to let custom ShadingModel running!


Here Are All My Modifications On UE Source with 4.26 and 4.27

  1. Engine\Source\Runtime\Engine\Classes\Engine\EngineTypes.h

Add a new ShadingModel

MSM_Toon01 UMETA(DisplayName="Toon01"),

  1. Engine\Source\Runtime\Engine\Private\Materials\MaterialShader.cpp

Add detail name

case MSM_Toon01: ShadingModelName = TEXT("MSM_Toon01"); break;

  1. Engine\Source\Runtime\Engine\Private\Materials\HLSLMaterialTranslator.cpp

Define MATERIAL_SHADINGMODEL_TOON01


if (ShadingModels.HasShadingModel(MSM_Toon01))

{

OutEnvironment.SetDefine(TEXT("MATERIAL_SHADINGMODEL_TOON01"), TEXT("1"));

NumSetMaterials++;

}

  1. Engine\Source\Runtime\Engine\Private\Materials\Material.cpp

Materail customData0 active

| for default shading model actived but still black on materail


case MP_CustomData0:

Active = ShadingModels.HasAnyShadingModel({ MSM_DefaultLit,MSM_ClearCoat, MSM_Hair, MSM_Cloth, MSM_Eye ,MSM_Toon01 });

break;

  1. Engine\Source\Editor\PixelInspector\Private\PixelInspectorResult.h

Define PIXEL_INSPECTOR_SHADINGMODELID_TOON01

#define PIXEL_INSPECTOR_SHADINGMODELID_TOON01 12

  1. Engine\Source\Editor\PixelInspector\Private\PixelInspectorResult.cpp

Return MSH_Toon01


case PIXEL_INSPECTOR_SHADINGMODELID_TOON01:

return EMaterialShadingModel::MSM_Toon01;

7.Engine\Source\Editor\PixelInspector\Private\PixelInspectorDetailsCustomization.cpp

Close some


case MSM_Toon01:

{

//

}

break;

  1. Engine\Shaders\Private\ShadingCommon.ush

Define SHADINGMODELID_TOON01


#define SHADINGMODELID_TOON01 12

#define SHADINGMODELID_NUM 13

Give color in shadingModel ViewPort


else if (ShadingModelID == SHADINGMODELID_TOON01) return float3(0.7f, 0.2f, 0.2f);


case SHADINGMODELID_TOON01:return float3(0.7f, 0.2f, 0.2f);

  1. Engine\Shaders\Private\BasePassCommon.ush

Write to GBuffer

#define WRITES_CUSTOMDATA_TO_GBUFFER (USES_GBUFFER && (MATERIAL_SHADINGMODEL_SUBSURFACE || MATERIAL_SHADINGMODEL_PREINTEGRATED_SKIN || MATERIAL_SHADINGMODEL_SUBSURFACE_PROFILE || MATERIAL_SHADINGMODEL_CLEAR_COAT || MATERIAL_SHADINGMODEL_TWOSIDED_FOLIAGE || MATERIAL_SHADINGMODEL_HAIR || MATERIAL_SHADINGMODEL_CLOTH || MATERIAL_SHADINGMODEL_EYE || MATERIAL_SHADINGMODEL_TOON01 || MATERIAL_SHADINGMODEL_DEFAULT_LIT)

  1. Engine\Shaders\Private\ShadingModelsMaterial.ush

GBuffer.CustomData.xy


#if MATERIAL_SHADINGMODEL_TOON01

else if (ShadingModel == SHADINGMODELID_TOON01)

{

GBuffer.ShadingModelID = SHADINGMODELID_TOON01;

GBuffer.CustomData.x = GetMaterialCustomData0(MaterialParameters);

GBuffer.CustomData.y = GetMaterialCustomData1(MaterialParameters);

}

#endif

For default add too, but still don’t show customeData on default materail


#if MATERIAL_SHADINGMODEL_DEFAULT_LIT

else if (ShadingModel == SHADINGMODELID_DEFAULT_LIT)

{

GBuffer.CustomData.x = GetMaterialCustomData0(MaterialParameters);

GBuffer.CustomData.y = GetMaterialCustomData1(MaterialParameters);

}

#endif

  1. Engine\Shaders\Private\DeferredShadingCommon.ush

bool HasCustomGBufferData(int ShadingModelID)

{

return ShadingModelID == SHADINGMODELID_SUBSURFACE

|| ShadingModelID == SHADINGMODELID_DEFAULT_LIT

|| ShadingModelID == SHADINGMODELID_PREINTEGRATED_SKIN

|| ShadingModelID == SHADINGMODELID_CLEAR_COAT

|| ShadingModelID == SHADINGMODELID_SUBSURFACE_PROFILE

|| ShadingModelID == SHADINGMODELID_TWOSIDED_FOLIAGE

|| ShadingModelID == SHADINGMODELID_HAIR

|| ShadingModelID == SHADINGMODELID_CLOTH

|| ShadingModelID == SHADINGMODELID_EYE

|| ShadingModelID == SHADINGMODELID_TOON01;

}

  1. Engine\Shaders\Private\ClusteredDeferredShadingPixelShader.usf

GET_LIGHT_GRID_LOCAL_LIGHTING_SINGLE_SM(SHADINGMODELID_TOON01, PixelShadingModelID, CompositedLighting, ScreenUV, CulledLightGridData, Dither, FirstNonSimpleLightIndex);

  1. Engine\Shaders\Private\TiledDeferredLightShaders.usf

EXECUTE_SHADING_LOOPS_SINGLE_SM(SHADINGMODELID_TOON01, PixelShadingModelID, CompositedLighting, PixelPos, NumLightsAffectingTile, NumSimpleLightsAffectingTile, CameraVector, WorldPosition);

  1. Engine\Shaders\Private\ShadingModels.ush

BxDF


FDirectLighting Toon01BxDF(FGBufferData GBuffer, half3 N, half3 V, half3 L, float Falloff, float NoL, FAreaLight AreaLight, FShadowTerms Shadow)

{

FDirectLighting Lighting;

float customValue = GBuffer.CustomData.x * 0.5f;

Lighting.Diffuse = AreaLight.FalloffColor * Falloff * step(0.5f, NoL) * Diffuse_Lambert(GBuffer.DiffuseColor);

//Lighting.Diffuse = AreaLight.FalloffColor * (Falloff * NoL) * Diffuse_Lambert( GBuffer.DiffuseColor );

Lighting.Specular = 0;

Lighting.Transmission = 0;

return Lighting;

}

IntegrateBxDF


case SHADINGMODELID_TOON01:

return Toon01BxDF(GBuffer, N, V, L, Falloff, NoL, AreaLight, Shadow);

  1. Engine\Shaders\Private\ShadingModels.ush

Fuction DefaultLitBxDF


Lighting.Diffuse = AreaLight.FalloffColor * Falloff * step(0.5f,NoL) * Diffuse_Lambert(GBuffer.DiffuseColor);

//Lighting.Diffuse = AreaLight.FalloffColor * (Falloff * NoL) * Diffuse_Lambert( GBuffer.DiffuseColor );


Lighting.Specular = 0;

Lighting.Transmission = 0;

return Lighting;

This question should really be asked in the graphics portion of the forum

thank you , i’ll try to move there