A 5-step guide to importing shaders from Reality Composer Pro into Xcode:
import SwiftUI
import RealityKit
import RealityKitContent
let shaderGraphMaterial = try await ShaderGraphMaterial(
named: "/Root/YourShaderName",
from: "YourFile.usda",
in: realityKitContentBundle
)
let object = ModelEntity(
mesh: .generateBox(size: 0.4),
materials: [shaderGraphMaterial]
)
content.add(object)
All these steps must be completed correctly for the shader to work properly in your visionOS application. The most common issues arise from incorrect paths or missing exports, so double-check these if you encounter problems.
Full Code: