r/iosdev • u/Disastrous-Reach2085 • 1h ago
My RealityKit Feelbits kept getting a white outline. It turned out to have two separate causes
My app shows 3D Feelbits live on SwiftUI screens, and I kept fixing a pale outline around them, only for it to come back. Fixing one cause did nothing for the other.
- See-through RealityView over SwiftUI. RealityKit outputs soft edge pixels in linear light, but they get layered over SwiftUI in sRGB, so the edge ends up lighter than both sides. A small post-process step that corrects those pixels fixed it.
- Solid view with a light background colour inside the scene. For a light colour to show exactly, a material without tone mapping has to be very bright inside the renderer. An edge pixel averages that with the Feelbit, and tone mapping turns the result nearly white. That leaves a one-pixel line of 255,255,248 between a 255,227,201 card and a 246,226,183 Feelbit. The fix is a final PostProcessEffect that darkens any pixel lighter than both neighbours (horizontally or vertically) back down to them. Real lit parts are wider than a pixel, so they stay.
What I learned: put a test on a screenshot that counts pixels lighter than both sides. My eye and my first checker both missed the second cause.
Has anyone found a cleaner way? I made the app; it's Feelbits if you want to see it running: https://apps.apple.com/app/id6820267490?pt=129578935&ct=reddit&mt=8