red character 'A' without the horizontal bar Achraf Kassioui

RealityKit Texture Tiling

Blog / Apple Dev,

Tile and transform textures in RealityKit using the textureCoordinateTransform property of a Material.

How can we tile a texture on a mesh surface in RealityKit? We can use the textureCoordinateTransform.scale property of a PBR material:

var material = PhysicallyBasedMaterial()

/// Create a texture resource from an image in Xcode Assets
if let texture = try? TextureResource.load(named: "tile_texture") {
    material.baseColor.texture = .init(texture)
    /// Tile the texture 4x4
    material.textureCoordinateTransform.scale = SIMD2<Float>(x: 4, y: 4)
}
RealityKit-TextureTiling-Texture.png
The texture to tile.
RealityKit-TextureTiling-4x4.png
4x4 tiling of the texture.

We can apply other interesting transforms to the texture such as rotation:

material.textureCoordinateTransform.rotation = .pi/4
RealityKit-TextureTiling-Rotation.png
The texture tiled and rotated.

All these properties are animatable. A custom system can update them every frame.

Links