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?
asked Jun 12 '17 at 11:39 PM in C++ Programming
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.
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.
answered Jun 13 '17 at 08:32 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here