General

Development

recompileshaders, such as recompileshaders changed

In ShaderCompiler.cpp in GlobalBeginCompileShader, following speeds up compilation of shaders by reducing optimization level:

Input.Environment.CompilerFlags.Add(CFLAG_StandardOptimization);

(don’t use in shipping because it reduces performance)

Basic shading model setup

These steps are always needed for custom shading models

1. Update EngineTypes.h

Add value into materia shading model enum:

enum EMaterialShadingModel
{
	MSM_Unlit					UMETA(DisplayName="Unlit"),
	MSM_DefaultLit				UMETA(DisplayName="Default Lit"),
 

2. Update HLSLMaterialTranslator.cpp

Find the material environment function which defines values as below:

if (ShadingModels.HasShadingModel(MSM_SingleLayerWater))
{
	OutEnvironment.SetDefine(TEXT("MATERIAL_SHADINGMODEL_SINGLELAYERWATER"), TEXT("1"));
	NumSetMaterials++;
}

Add your own similar definition.

3. Update ShadingCommon.ush

Find the shadingmodel ID defines, and add yours into the list. Update the NUM define with the new number of values

#define SHADINGMODELID_SINGLELAYERWATER		10
#define SHADINGMODELID_THIN_TRANSLUCENT		11
//add yours:
#define SHADINGMODELID_RETRO_LIT            12
 
//Update value:
#define SHADINGMODELID_NUM					13

To support showing shading model coloring debug view mode, add custom color for the shading model into the GetShadingModelColor function

case SHADINGMODELID_THIN_TRANSLUCENT: return float3(1.0f, 0.8f, 0.3f);

Additional features

Enabling additional material pins

Note that the value range on CustomData pins is from 0.0 to 1.0

Edit IsPropertyActive_Internal in Material.cpp

case MP_CustomData0:
	Active = ShadingModels.HasAnyShadingModel({ MSM_ClearCoat, MSM_Hair, MSM_Cloth, MSM_Eye });
	break;
 

Configure pin name by editing MaterialShared.cpp, GetAttributeOverrideForMaterial

case MP_CustomData0:	
	CustomPinNames.Add({ MSM_ClearCoat, "Clear Coat" });
	CustomPinNames.Add({MSM_Hair, "Backlit"});
	CustomPinNames.Add({MSM_Cloth, "Cloth"});
	CustomPinNames.Add({MSM_Eye, "Iris Mask"});
	return FText::FromString(GetPinNameFromShadingModelField(Material->GetShadingModels(), CustomPinNames, "Custom Data 0"));
 

Find #define WRITES_CUSTOMDATA_TO_GBUFFER, and include the shadingmodel define which is added in step 2 above into the condition.

In DeferredShadingCommon.ush, add your shading model to HasCustomGBufferData

bool HasCustomGBufferData(int ShadingModelID)
{
	return ShadingModelID == SHADINGMODELID_SUBSURFACE
		|| 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_RETRO_LIT;
}

Finally, update SetGBUfferForShadingModel in ShadingModelsMaterial.ush to fill in the CustomData values in the GBuffer. Otherwise no data will be available.