x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I get subsurface color in a custom shader?

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?

Product Version: UE 4.16
Tags:
more ▼

asked Jun 12 '17 at 11:39 PM in C++ Programming

avatar image

Zero-Night
86 8 11 18

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Jun 13 '17 at 08:05 AM

avatar image

Deathrey
7.8k 130 30 292

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jun 13 '17 at 08:32 AM

avatar image

Zero-Night
86 8 11 18

avatar image Deathrey Jun 13 '17 at 09:01 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question