[VisionOS] Can't import RealitKit/RealityKit.h for custom shader materials

Version details:

  • Xcode Version 15.3 beta (15E5178i)
  • visionOS 1.0 (21N301) SDK + visionOS 1.0 (21N305) Simulator (Installed)

I'm trying to make a ModelEntity with a CustomMaterial.GeometryModifier for which I also created a metal shader file. The said shader file is extremely simple at this time:

#include <metal_stdlib>
#include <RealityKit/RealityKit.h>

using namespace metal;


[[visible]]
void ExpandGeometryModifier(realitykit::geometry_parameters params)
{
   // Nothing.
}

When trying to compile my project, I get the following error:

  • 'RealityKit/RealityKit.h' file not found

Is this not supported on VisionOS?

visionOS doesn't currently support custom materials setup through shaders. You have to use Reality Composer Pro, and built a custom material using a node graph.

This video may help: https://developer.apple.com/wwdc23/10083

I'm also having this issue when compiling a target that has both iOS and visionOS as supported platforms. My iOS renderer uses CustomMaterial and my visionOS renderer uses ShaderGraphMaterial. I was hoping I could use a compiler flag per platform, but the Metal compiler doesn't seem to like that.

#if !os(visionOS)
#include <RealityKit/RealityKit.h>
#endif

Gives error Token is not a valid binary operator in a preprocessor subexpression.

[VisionOS] Can't import RealitKit/RealityKit.h for custom shader materials
 
 
Q