Vision OS and coloring entities using Metal Shaders

I'm experimenting with Vision OS and Apple Vision Pro using the Xcode Beta. I'm using Xcode 15.1 Beta and visionOS 1.0 beta 4.

I'm currently doing a project where I draw a polygon using a mesh generated from MeshDescriptor/MeshResource and present it in an ImmersiveView.

I want to change the color of parts, i.e. not all of, my 3D rendered polygon and I want to do it dynamically. For example when the user presses a button.

I have gotten into Shaders and the CustomMaterial from RealityKit, only to find out that CustomMaterial is not supported on Vision OS!

Does anyone know how I can color portions/parts of a mesh that is generated from MeshDescriptor and MeshResource?

Replies

Hello,

You are correct, CustomMaterial is not supported on visionOS.

It's not clear to me what your exact requirements are for your shader, but I encourage you to explore ShaderGraphMaterial to see if it fits your needs: https://developer.apple.com/videos/play/wwdc2023/10202/

Hi gchiste,

Thank you for your reply - I will look more into ShaderGraphMaterial.

Meanwhile here is what I'm trying to achieve:

I want to create 3D entity using a MeshDescriptor and MeshResource, for example a triangle, and have the ability to change the color of the mesh dynamically without making the entire entity the same color.

For example, how would I go about creating this triangle below in Vision OS? And how would I dynamically change the color of the triangle when the app is running? Imagine there are 4 buttons labelled red, green, blue and mix. Pressing a button should change the color of the triangle.

The image is from this guide on CustomMaterial: https://developer.apple.com/documentation/realitykit/modifying-realitykit-rendering-using-custom-materials