Some technical questions about UE4's renderer

Heya,

So, I’m curious about a few things. In the past week I’ve been doing a crash course on GLSL and aside from following tutorials I’m trying to do some stuff on my own.

Lately I’ve reached the “compile glsl shaders” part and all the resources on the net I see do the same thing - compile the shaders every time, on the main thread. There doesn’t seem to be a way to offload this on a worker thread. More importantly, there doesn’t seem to be a way to cache shaders either.

Knowing that UE4 caches shaders in the derived data cache AND that it compiles them asynchronously, I’d be very interested in hearing how this was achieved. Obviously I know UE4 isn’t exclusively GLSL but the general principle ought to be the same, no?

OpenGL doesn’t have a compile to bytecode step like D3D does (or at least not one that can be built on another machine and distributed). The ‘compile’ that UE4 does for OpenGL shaders is: run preprocessor, run cross compiler (converts HLSL into glsl, with some optimizations). When the game starts up in OpenGL mode, it still has to compile the glsl shaders every time, but at least they have been pre-optimized a bit.

So the “Compiling Shaders” that runs when I save a material isn’t ACTUALLY compiling the shader in the GLSL sense? That’s done at runtime, on the main thread?