How do I get subsurface color in a custom shader?

Have in mind, that GetMaterialSubsurfaceData returns half4, not half3.
Additionally, have a look at
WRITES_CUSTOMDATA_TO_GBUFFER
In particular, its definition on line 23 of BasePassCommon
Under general conditions, custom data is skipped, unless shading model needs it.

Are there any other things that may
trip someone up when getting into all
this?

Aye, well, on the coding side of things, you gotta additionally ensure that:

  1. In Material.cpp IsPropertyActive is
    set on MP_SubsurfaceColor for your
    shading model, and not only for
    subsurface shading model.
  2. In MaterialTranslator.h ensure that
    Chunk for MP_SubsurfaceColor is
    generated for your shading model
    too, and not only for subsurface
    shading model
  3. In BasePassCommon.usf, check that
    WRITES_CUSTOMDATA_TO_GBUFFER is
    defined for your shading model too,
    and not only for subsurface shading
    model.

I believe that is the complete list of things to do.

I’m working on a custom shader and I’ve got maybe 99% of what I want to do working, but the only thing tripping me up is how to read the subsurface color.

Looking at other parts in the shader code, I’ve come across this-
GBuffer.CustomData.rgb = GetMaterialSubsurfaceData(MaterialParameters);

It should, in theory work. However, it’s just coming out pitch black instead.

If I instead use GetMaterialBaseColor(PixelMaterialInputs); then the color comes through just fine, my entire shader works and everything’s great, it’s just the wrong data going into it.

Am I potentially missing something else I need to do in order to get this working? Is there just another command I need to get it?

Yep, I got that part. I actually just managed to solve it on my own, and since the information isn’t -anywhere- on the internet I’m posting it here for the next guy.

In MaterialShared.h there’s a part called “inline bool IsSubsurfaceShadingModel(EMaterialShadingModel ShadingModel)” and then it goes on to list various shading models. Apparently, unless you list the shading model there no matter what you do, even if you give it customdata access, it will -never- use subsurface.

The moment I fixed that, what I had with this:
GBuffer.ShadingModelID = SHADINGMODELID_insertShaderModelHere;
GBuffer.CustomData.rgb = GetMaterialSubsurfaceData(MaterialParameters);
started working perfectly immediately.

Thanks for the tip though Deathrey. Are there any other things that may trip someone up when getting into all this? Information is practically barren when trying to find things out about this, it seems less than maybe 10 people have ever even tried making custom shaders for Unreal.