I'm building a simple game engine (or mostly rendering engine) and I would like to separate the "engine" part from the "game" part. So, I've come up with an idea to build "engine" part as a library (static or dynamic) and the "game" part will link to this library. Simple.

However, there is one problem - "engine" part needs to reference some assets i.e. files with source code of builtin shaders (defualt shaders of the rendering engine).

Is there a way to include these shader files into an "engine" library? Or is there any other solution to this problem?

  • \$\begingroup\$ It depends. Tell us which grapical API or renderer you are using. For OpenGL you can have shader source code stored in a string buffer defined at compilation time. \$\endgroup\$ – Ocelot Jun 8 '18 at 20:54
  • \$\begingroup\$ For now I'm using OpenGL, but later I would like to also support Vulkan. I've considered using string buffers for shaders' code but I don't feel that it's a good idea. \$\endgroup\$ – Shot Jun 8 '18 at 21:43
  • \$\begingroup\$ Can you explain what reservations you have with this approach? Knowing what's holding you back can guide what alternatives to offer, or suggest evidence to show if it might not be as big a problem as expected. \$\endgroup\$ – DMGregory Jun 8 '18 at 22:37
  • \$\begingroup\$ Are these shaders that would likely be useful to multiple projects (maybe some general lighting that different games could make use of) or are they specific to the game you're working on with it (such as a pattern generator that wouldn't be useful to another game)? \$\endgroup\$ – user1118321 Jun 9 '18 at 1:44
  • \$\begingroup\$ These shaders are just basic/standard shaders that can be used by any new game. @DMGregory - I think that it's a bad idea because it can't be simply applied to e.g. Vulkan shaders which have to be in binary files stored on disk (according to my knowledge). \$\endgroup\$ – Shot Jun 9 '18 at 15:31

All my engine's core shaders are provided as data files, and we simply expect each game to include those files as part of their game data. We load them exactly the same way we load any other game asset. Creating a new game? First thing you do is copy those default shaders into your game's asset directory. (The engine complains and refuses to start if they're not there)

I felt it was important for individual games to have the ability to modify those default shaders, which is why I wanted them to be included in the game's data, rather than in a separate "engine data" directory. I wanted it to be possible for a particular game to replace the 'default' shaders simply by changing their contents, and without needing to touch the engine itself.

With that said, I do also have a few simple rendering effects (blurs, bloom, etc) which include their own minimal shaders in static string buffers inside the engine, as they're just simple utilities; if somebody wanted something particular, they'd make it themselves rather than use the engine's simple built-in effects.

|improve this answer|||||
  • \$\begingroup\$ It seems reasonable. Do you use any library to pack these "standard" assets and then unpack them at runtime? \$\endgroup\$ – Shot Jun 9 '18 at 15:32
  • 1
    \$\begingroup\$ Nope; they're just plain text files. I just open and read them as text, compile them, and throw away the text. I do use PhysicsFS to handle loading files so that I could theoretically put all my files into a zipfile and load them from there, but for the moment I just leave all the assets loose in a directory. \$\endgroup\$ – Trevor Powell Jun 10 '18 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.