Altering RealityKit Rendering with Shader Functions
Altering RealityKit Rendering with Shader Functions
Altering RealityKit Rendering with Shader Functions Create rendering effects by writing surface shaders and geometry modifiers.
Overview
In iOS 15 and later, and macOS 12 and later, you can write Metal functions to alter the way RealityKit renders entities that uses a CustomMaterial. Custom materials require a Metal function called a surface shader, which sets the final rendering attributes for each of the entity’s fragments. A fragment is a pixel that is potentially affected by rendering that entity. Custom materials also support an optional Metal function called a geometry modifier that can move vertices or alter other vertex data, such as vertex colors or UV coordinates.
This sample demonstrates using custom materials with Metal functions to create special rendering effects. In this project, several toy robot entities are placed on a detected horizontal plane. Tapping a robot causes it to rapidly expand and become transparent so it appears to pop like a bubble. This project demonstrates creating a custom material from the PhysicallyBasedMaterial on a loaded model, using the material’s custom texture and vector properties to pass data to shader functions, and writing a surface shader and a geometry modifier to actually implement the rendering effects.
For more information on using custom materials, see Modifying RealityKit rendering using custom materials