Material with custom code and tesselation does not compile

The material editor does not correctly compile some expressions with a legal ‘custom’ node.

To recreate:
Create a material with Tesselation (in my case, PN triangles, adaptive, crack free), connect a node with custom code to it (in my case, atan2(x.r, x.g) where x is an input) to “world displacement”:

the material will not compile:

Error [SM5]  error X3017: 'CustomExpression0': cannot implicitly convert from 'struct FMaterialTessellationParameters' to 'struct FMaterialPixelParameters'

evidently, the generated HLSL translation unit does indeed accept only FMaterialPixelParameters, not FMaterialTesselationParameters:

// Uniform material expressions.
MaterialFloat CustomExpression0(FMaterialPixelParameters Parameters,MaterialFloat4 x)
return atan2(x.r, x.g);;

Same problem here… any solution yet?

Hello -

After some investigation, I was able to reproduce this issue and it does appear to be an issue. I have entered a bug report as UE-23906. I will keep you informed as we investigate a solution to this issue.

Thank You

Eric Ketchum

Sorry to bump this again but is there an update (looks like the prob. remains in 4.11)?
Is this going to be fixed? is there a workaround perhaps?

It would be really nice to be able to use the custom node with displacement.


Right now, it’s marked as “To-Do” but it doesn’t have a fix version set and it’s marked as Minor so it may be a while before it’s fixed.

Hi guys,

Is there a way to do the same thing ? I mean, I am trying to compute my own normal maps and I try to alter the mesh in order to do procedural environments but always blocked by this bug. Can I do something to have the same result and that will work ?

Thank you in advance,


Bumping it up. Would be useful to have custom node in tessellation parameters occasionally.

Currently you could use tricky hack with code injection :slight_smile:

Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_129"
   Begin Object Class=MaterialExpressionCustom Name="MaterialExpressionCustom_3"
   End Object
   Begin Object Name="MaterialExpressionCustom_3"
      Code="if (IsShadowDepthShader()) {\r\n\treturn 0.0;\r\n} else {\r\n\treturn M;\r\n}}\r\nMaterialFloat CustomExpression2(FMaterialTessellationParameters Parameters,MaterialFloat3 M)\r\n{\r\nif (IsShadowDepthShader()) {\r\n\treturn 0.0;\r\n} else {\r\n\treturn M;\r\n}"
   End Object
   ErrorMsg="Custom material IsShadowDepthShader() missing input 1 (M)"
   CustomProperties Pin (PinId=A6F555E540DD2E1A7EED2993C0233787,PinName="M",PinType.PinCategory="required",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.bIsMap=False,PinType.bIsSet=False,PinType.bIsArray=False,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,LinkedTo=(MaterialGraphNode_84 25A57DD744249C2C16B5E4B556B11570,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,)
   CustomProperties Pin (PinId=71DB5BE24985833D886585970B2CC603,PinName="Output",PinFriendlyName=" ",Direction="EGPD_Output",PinType.PinCategory="",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.bIsMap=False,PinType.bIsSet=False,PinType.bIsArray=False,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,LinkedTo=(MaterialGraphNode_0 8BA4621040920AD6BC2EF0A2000B9339,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,)
End Object

Seems like this an older problem …

And I have same issue ;(

Then I’m trying to debug engine and found place where my CustomExpression collect parameters and write MaterialPixelParameters… At this place compiler based on ShaderFrequency select shader type to write block.
Crash will appear when ShaderFrequency == SF_Hull and shader type set Pixel but Hull is Tesselation part

I was created simple patch on Compile() CustomExpression:

From ceb393df3f2cb91799d0845d7eaf678fe958b2b8 Mon Sep 17 00:00:00 2001
From: imbaFireFenix <>
Date: Wed, 4 Oct 2017 16:00:44 +0300
Subject: [PATCH] ~Material: fix ShaderFrequency determination for
 CustomNodeExpression when shader compile to hull shader;

 Engine/Source/Runtime/Engine/Private/Materials/HLSLMaterialTranslator.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Engine/Source/Runtime/Engine/Private/Materials/HLSLMaterialTranslator.h b/Engine/Source/Runtime/Engine/Private/Materials/HLSLMaterialTranslator.h
index 20343ad..67bfca4 100644
--- a/Engine/Source/Runtime/Engine/Private/Materials/HLSLMaterialTranslator.h
+++ b/Engine/Source/Runtime/Engine/Private/Materials/HLSLMaterialTranslator.h
@@ -5091,7 +5091,7 @@ protected:
 		Code.ReplaceInline(TEXT("\n"),TEXT("\r\n"), ESearchCase::CaseSensitive);
-		FString ParametersType = ShaderFrequency == SF_Vertex ? TEXT("Vertex") : (ShaderFrequency == SF_Domain ? TEXT("Tessellation") : TEXT("Pixel"));
+		FString ParametersType = ShaderFrequency == SF_Vertex ? TEXT("Vertex") : ((ShaderFrequency == SF_Domain || ShaderFrequency == SF_Hull) ? TEXT("Tessellation") : TEXT("Pixel"));
 		FString ImplementationCode = FString::Printf(TEXT("%s CustomExpression%d(FMaterial%sParameters Parameters%s)\r\n{\r\n%s\r\n}\r\n"), *OutputTypeString, CustomExpressionIndex, *ParametersType, *InputParamDecl, *Code);
 		CustomExpressionImplementations.Add( ImplementationCode );

And then all works for now :slight_smile:

FireFenix, can you make this patch work for Unreal 4.9.2 ?