RealityKit Materials: Basic Gradient


Hello!

I’m trying to make a material in RealityKit that has a basic gradient. I am making an iPadOS app.

A few thoughts:

  • I cannot use Reality Composer Pro to do this because the Shader Graph tool only works for visionOS.
  • I cannot use a Metal file to create a shader because I am using a .swiftpm (app playgrounds) file targeted for Swift Playgrounds. Metal files don’t seem to work on Swift Playgrounds (it’s a Swift playground, after all).
  • I would prefer to not use image textures for a simple thing like this. That would take up storage. I wish it was as easy as applying a .basecolor with a UIColor, but UIColor does not support gradients.

What are my options? I know my requirements are likely not typical, but I really need to try to not break those.

I looked into CustomMaterial from RealityKit but once again, those take Metal shaders. Amazing tool, but I sadly cannot use them because I’m using a Swift Playground that doesn’t seem to with Metal files, at least it seems.

I’ve briefly done research on MetalKit? Could that help me out?

Let’s say I have a simple box in RealityKit. How would I apply a simple gradient to it given my constraints?

I really appreciate the help.

P.S. This is a SwiftUI project for reference.

EDIT:

Could I create a texture without images, perhaps by making a view into a texture and applying it? How would I do this? What are the pros and cons of this?

Another thought was could I just use MetalKit to create the gradient and apply it using CustomMaterial?

I will say that I'm kind of at a last resort — I am trying to create fairly straightforward materials. The two most important ones would be a gradient type of material with two colors and a transparent water material with a bit of refraction and perhaps maybe a little bit of reflection.

But, these are not meant to be photorealistic at all, not at all. They're meant to be fairly "2D"/simple which makes me wonder if I could just load in a texture. The only issue is that I don't know how I would do the water.

RealityKit Materials: Basic Gradient
 
 
Q