Community Tutorial: Custom shading models directly in your material graphs

A guide to exposing lighting data to the material graph in UEs Forward Renderer, allowing for creation of arbitrary shading models without the need for further Engine modification nor GBuffer restrictions.

https://dev.epicgames.com/community/learning/tutorials/ow0x/unreal-engine-custom-shading-models-directly-in-your-material-graphs

2 Likes

Hi @AbidNaga, that’s a pretty interesting tutorial . Regarding the last part (Volumetric Lightmap and Reflection Capture sampling in the material) : you should ask this guy , he knows an answer .

1 Like

Hi. While following the tutorial, I came across this line in BasePassPixelShader.usf Light Smuggler Base Pass Function Implementation:

include “LightSmuggler/LightSmugglerPixelShader.ush”

However, the file LightSmugglerPixelShader.ush doesn’t seem to be included anywhere in the tutorial files. Am I overlooking something, or is this an error in the tutorial?

I’m asking because even after modifying the engine as shown in the tutorial, switching the shading model to LightSmuggler doesn’t give me access to FSmuggledLight or LightSmugglePack in the custom node.

Has anyone else run into this issue or found a workaround?

Any clarification would be greatly appreciated!

Thanks in advance!

Oh shoot thanks for pointing that out, it’s just an error on my part. What it actually should be is:

#include "LightSmuggler/LightSmugglerCalcMaterial.ush"

The file created in section 3.3.2. Just a mistake on my end sorry about that. Lemme know if everythings working well after that change

I’m getting some errors when trying to create a custom node in this shading model.

Any ideas on what could be causing this? I tried including the files in the custom node as well as in the include file paths within the details panel of the custom node.

I’m using Unreal 5.5, so I’m not sure if MegaLights or something else could have changed the setup slightly.

\Engine\Shaders\Private\MaterialTemplate.ush(3579,1): Shader TBasePassPSFNoLightMapPolicy, Permutation 0, VF FLocalVertexFactory:
/Engine/Generated/Material.ush:3579:1: error: unknown type name ‘FSmuggledLight’
FSmuggledLight DirLight = LightSmugglePack.DirectionalLight;

Depending on where you placed the LightSmugglerCommon.ush file, be sure to add it as an include in your custom node. I had it placed in “/Engine/Private/LightSmuggler/LightSmugglerCommon.ush”, so in my case I added that path to the include file paths of the HLSL node

Lemme know if that fixes it!

Hi, I am getting

/Engine/Private/MaterialTemplate.ush(398): Syntax error in conditional expression of ‘#if’

Could you help me with that?

Thank you so much for this deep dive into adding a custom shading model, I’ve tried it with 5.5.4 and works like a charm! The only thing that I couldn’t do is to make it work on mobile (at least Android Vulkan Preview is showing the usual shading). Do you have any ideas?

Hey no problem! I know with mobile theres a different MobileBasePass that it goes through - so in theory it can work on mobile just fine but I haven’t attempted it. But the concept is essentially the same, which is just sort of doing the exact same as done in the regular BasePass but within the MobileBasePass. So trying to mimick its structure exactly, but then making a call to the same lighting functions (or a different one if mobile goes through a different route - either way its forward rendering so guaranteed to work I think).

Lemme know if you’ve got any other questions, I can take a look at it later at some point to try to get you the exact injection points, but shouldn’t be that hard to translate things to the mobile base pass.

1 Like