Example #1
0
void UMaterialInterface::UpdateMaterialRenderProxy(FMaterialRenderProxy& Proxy)
{
	// no 0 pointer
	check(&Proxy);

	EMaterialShadingModel MaterialShadingModel = GetShadingModel(true);

	// for better performance we only update SubsurfaceProfileRT if the feature is used
	if (MaterialShadingModel == MSM_SubsurfaceProfile)
	{
		FSubsurfaceProfileStruct Settings;

		USubsurfaceProfile* LocalSubsurfaceProfile = GetSubsurfaceProfile_Internal();
		
		if (LocalSubsurfaceProfile)
		{
			Settings = LocalSubsurfaceProfile->Settings;
		}

		ENQUEUE_UNIQUE_RENDER_COMMAND_THREEPARAMETER(
			UpdateMaterialRenderProxySubsurface,
			const FSubsurfaceProfileStruct, Settings, Settings,
			USubsurfaceProfile*, LocalSubsurfaceProfile, LocalSubsurfaceProfile,
			FMaterialRenderProxy&, Proxy, Proxy,
		{
			uint32 AllocationId = 0;

			if (LocalSubsurfaceProfile)
			{
				AllocationId = GSubsufaceProfileTextureObject.AddOrUpdateProfile(Settings, LocalSubsurfaceProfile);

				check(AllocationId >= 0 && AllocationId <= 255);
			}
			Proxy.SetSubsurfaceProfileRT(LocalSubsurfaceProfile);
		});
Example #2
0
FMaterialRelevance UMaterialInterface::GetRelevance_Internal(const UMaterial* Material, ERHIFeatureLevel::Type InFeatureLevel) const
{
	if(Material)
	{
		const FMaterialResource* MaterialResource = Material->GetMaterialResource(InFeatureLevel);
		const bool bIsTranslucent = IsTranslucentBlendMode((EBlendMode)GetBlendMode());

		EMaterialShadingModel ShadingModel = GetShadingModel();

		const bool bIsLit =  ShadingModel != MSM_Unlit;
		// Determine the material's view relevance.
		FMaterialRelevance MaterialRelevance;
		MaterialRelevance.bOpaque = !bIsTranslucent;
		MaterialRelevance.bMasked = IsMasked();
		MaterialRelevance.bDistortion = Material->bUsesDistortion && bIsTranslucent;
		MaterialRelevance.bSeparateTranslucency = bIsTranslucent && Material->bEnableSeparateTranslucency;
		MaterialRelevance.bNormalTranslucency = bIsTranslucent && !Material->bEnableSeparateTranslucency;
		MaterialRelevance.bDisableDepthTest = bIsTranslucent && Material->bDisableDepthTest;
		MaterialRelevance.bSubsurfaceProfile = (Material->MaterialDomain == MD_Surface) && !bIsTranslucent && (ShadingModel == MSM_SubsurfaceProfile);
		MaterialRelevance.bOutputsVelocityInBasePass = Material->bOutputVelocityOnBasePass;

		return MaterialRelevance;
	}
	else
	{
		return FMaterialRelevance();
	}
}
void UMaterialInterface::UpdateMaterialRenderProxy(FMaterialRenderProxy& Proxy)
{
	// no 0 pointer
	check(&Proxy);

	EMaterialShadingModel MaterialShadingModel = GetShadingModel(true);

	// for better performance we only update SubsurfaceProfileRT if the feature is used
	if (MaterialShadingModel == MSM_SubsurfaceProfile)
	{
		FSubsurfaceProfileStruct Settings;

		USubsurfaceProfile* LocalSubsurfaceProfile = GetSubsurfaceProfile_Internal();
		
		if (LocalSubsurfaceProfile)
		{
			Settings = LocalSubsurfaceProfile->Settings;
		}

		// this can be improved, it doesn't support Renderer hot reload
		{
			static bool bFirst = true;

			if (bFirst)
			{
				bFirst = false;

				static const FName RendererModuleName("Renderer");
				IRendererModule& RendererModule = FModuleManager::GetModuleChecked<IRendererModule>(RendererModuleName);

				ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
					UpdateMaterialRenderProxySubsurfaceSetup,
					IRendererModule&, RendererModule, RendererModule,
					{
					GSubsufaceProfileTextureObject.SetRendererModule(&RendererModule);
				});
			}
		}