Mutable Propagate bVisibleInRayTracing

Is it possible to propagate the bVisibleInRayTracing flag in Mutable? We want to exclude a section from ray tracing, but when we bake out the instance, the section ignores the input value of bVisibleInRayTracing. We can set it manually after the bake, but ideally it would just preserve the settings.

Steps to Reproduce

  1. Uncheck bVisibleInRayTracing on a SkeletalMesh LOD section
  2. Add the mesh to a CustomizableObject and bake out the mesh.
  3. Baked out mesh will have bVisibleInRayTracing checked.

Hey there,

This isn’t supported yet, but you can add it relatively easily. I’ll walk through the files and additions here. I’ll also be pushing to get this into the next engine release. There are 4 files to modify with minimal changes. I denote the file, function and then edit with a comment below. (and this is related to the 5.7 version of the engine in case of reference.)

CustomizableObjectInstance.cpp - UCustomizableInstancePrivate::RegenerateImportedModels

FSkelMeshSourceSectionUserData& SectionUserData = LODModel.UserSectionsData.FindOrAdd(ImportedSection.OriginalDataSectionIndex);
SectionUserData.bCastShadow = RenderSection.bCastShadow;
SectionUserData.bVisibleInRayTracing = RenderSection.bVisibleInRayTracing; //Add this line.
SectionUserData.bDisabled = RenderSection.bDisabled;

UnrealConverstionUtils.cpp - SetupRenderSections

if (SurfacesMetadata[SurfaceIndex])
{
    Section.bCastShadow = SurfacesMetadata[SurfaceIndex]->bCastShadow;
    Section.bVisibleInRayTracing = SurfacesMetadata[SurfaceIndex]->bVisibleInRayTracing; //Add this line here
}

UnrealConverstionUtils.cpp - CopySkeletalMeshLODRenderData

if (!DestSection->bDisabled)
{
	 DestSection->BaseIndex = SrcSection.BaseIndex;
	 DestSection->NumTriangles = SrcSection.NumTriangles;
	 DestSection->BaseVertexIndex = SrcSection.BaseVertexIndex;
	 DestSection->MaxBoneInfluences = SrcSection.MaxBoneInfluences;
	 DestSection->NumVertices = SrcSection.NumVertices;
	 DestSection->BoneMap = SrcSection.BoneMap;
	 DestSection->bCastShadow = SrcSection.bCastShadow;
	 DestSection->bVisibleInRayTracing = SrcSection.bVisibleInRayTracing; //Add this line here
 }

CustomIzableObjectPrivate.h - FMutableSurfaceMetadata

//Add this property
UPROPERTY()
bool bVisibleInRayTracing = true;
	
friend FArchive& operator<<(FArchive& Ar, FMutableSurfaceMetadata& Elem)
	{
		Ar << Elem.MaterialSlotName;
		Ar << Elem.bCastShadow;
		Ar << Elem.bVisibleInRayTracing; //Add this line
 
		return Ar;
	}

GenerateMutableSource.cpp - AddUniqueSurfaceMetadata

TArray<uint8, TInlineAllocator<256>> DataToHash;
 
DataToHash.Add(static_cast<uint8>(Data.bCastShadow));
DataToHash.Add(static_cast<uint8>(Data.bVisibleInRayTracing));  //Add this line here
DataToHash.Append(NameDataView);
 
//////// - Further down the file.
auto CompareSurfaceMetadataFunc = [](const FMutableSurfaceMetadata& A, const FMutableSurfaceMetadata& B)
{
	return A.bCastShadow == B.bCastShadow && A.bVisibleInRayTracing == B.bVisibleInRayTracing && A.MaterialSlotName == B.MaterialSlotName; //Modify this line to include the VisibleInRayTracing check.
};
 
//////// Further down the file.
if (const FSkelMeshSection* MeshSection = GetMeshSectionFunc(MetadataBaseMesh, SourceMetadata.LODIndex, SourceMetadata.SectionIndex))
{
	SurfaceMetadata.bCastShadow = MeshSection->bCastShadow;
	SurfaceMetadata.bVisibleInRayTracing = MeshSection->bVisibleInRayTracing;  //Add this line here
}

Hope this helps,

Dustin

This is great, thank you!