Porting HLSL/FX files into Unreal Engine (Single Pass Vertex/Pixel Shaders)

Now, I’m not so much interested in porting this example (in link), but some directions on how to do this effectively.
Example Maya Shader File

Underneath the covers, materials are HLSL files…
So I was interested in trying to port examples into Unreal, just to test out how to do it, and to see if the results were good…

Now, most examples out there, are in *.fx formats, what few Shader editors there are mostly export to *.fx formats. But in general *.fx formats are just variations of HLSL files.
They usually have a vertex shader portion…
And then there is a pixel shader portion.

So, I just created an Unreal *.usf, and copy pasted some examples, and was very surprised that for the most part, I got no HLSL compiler errors. For some examples I did get errors, that were mostly from missing functions. That’s another matter.

  1. My first question is this, does Unreal use any vertex shaders at all? Or are the materials exclusively pixel shaders? Early shaders always had a vertex shader part, and a pixel shader part,
    I am not sure, are modern shaders exclusively pixel shaders?

For those that compiled with minimal or no errors, I thought, it should be straight forward to convert into a usable Unreal custom HLSL based material.

My two main issues

  1. vertex shaders, I don’t know if Unreal handles those at all?
  2. the inputs into the shader, were the real hard part. How and from where do I source those input values from?

Most require just inputs, but just for the vertex shader, and the results from the vertex shader are then passed to the pixel shader, so that I only need to supply the inputs to the vertex shader, but I don’t know if Unreal deals with vertex shaders?

(continued in next post)

From the MayaShader fx example, it looks like there is not a lot of input that is needed.
There are what look like a couple of global values that need to be assigned.
The ViewProjection matrix…
And the World matrix…
I am not sure how to assign these two matrices…
There is the vertex shader, all the inputs it needs are
float3 Position : POSITION; the vertex position
float3 Normal : NORMAL; the vertex normal
These two seem to be easy to deal with, but I am not sure the correct blueprint material functions to call and use to do this part…
The results are then passed to pixel shader, and the output is the pixel color…
This is easy, I can just connect this output value to the input diffuse color setting of the material.

float4x4 viewPrj : ViewProjection < string UIWidget = "None"; >;
float4x4 world : World < string UIWidget = "None"; >;

struct APPDATA
{
	float3 Position : POSITION;
	float3 Normal : NORMAL;
};

struct SHADERDATA
{
	float4 Position : POSITION;
	float4 Normal : TEXCOORD0;
	float4 WorldPosition : TEXCOORD1;
	half3 FogFactor : TEXCOORD2;
};

SHADERDATA ShaderVertex(APPDATA IN)
{
	SHADERDATA OUT;
	....code......
	return OUT;
}

struct PIXELDATA
{
	float4 Color : COLOR0;
};

PIXELDATA ShaderPixel(SHADERDATA IN, bool FrontFace : VFACE)
{
	PIXELDATA OUT;
	....code......
	OUT.Color = VectorConstruct;
	return OUT;
}

Would assigning the correct input values (previous post), be easy?

The pixel color outputted from pixel shader is straight forward I just need to pipe that result into the final material node.