10

I've noticed that if you have an empty scene and then load a 3D model in it with physically based lighting, there is a small bit of jank as the object appears. If I then add a different object in after that, that stuttering does not occur.

Looking at the profiler, it appears that the default PBR shaders are compiling during that first slow frame. Is it possible to precompile these shaders so that it doesn't happen when I go to render the model for the first time?

Similar issues have been brought up in other frameworks, like Three.js. Seems like a smart thing to prevent.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
pushmatrix
  • 726
  • 1
  • 9
  • 23
  • I don't know SceneKit, but is there an option to render off-screen? Can you just render such a model off-screen during "loading" and before starting the game or whatever? – Ken Thomases Sep 27 '17 at 04:18
  • @KenThomases That's what I've been doing, but it's been hacky and I'm wondering if there's a better way. – pushmatrix Oct 03 '17 at 17:18
  • Since the shaders are typically platform-dependent (i.e. compiled on the hardware card at hand) pre-compiling it for one specific platform will yield problems on other hardware, so like @KenThomases says, off-screen rendering is your best shot. – StarShine Oct 03 '17 at 21:45
  • any luck on this? I've just put in a `delay` function to wait 1 second before displaying, which i hate. – jfisk Apr 04 '18 at 03:44

1 Answers1

0

If you want to precompile a Physically Based Rendering (PBR) or any other regular SceneKit's shader you must use a SCNProgram class that is a complete Metal shader program that replaces SceneKit's rendering of a geometry or material.

Here's a page with code snippets and useful links showing you how you could work with a vertex or fragment precompiled Metal shaders.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220