itchio / capsule

🎬 Cross-platform hotkey short video capture for games
GNU General Public License v2.0
177 stars 14 forks source link

Use a shader compiler to support various OpenGL / Direct3D versions with a single source #52

Open fasterthanlime opened 7 years ago

fasterthanlime commented 7 years ago

See https://github.com/itchio/capsule/issues/49#issuecomment-309251813

There's mostly hlsl-to-glsl compilers out there. Apparently Vulkan has its own thing, but it's always meant to be transpiled too? Input welcome.

quyse commented 7 years ago

I use an C++ EDSL for shaders in my Inanity engine: I write a shader once in C++, and then it gets transformed at runtime to HLSL or GLSL text, taking into account whether various language features supported or not supported by graphics backend, including uniform buffers, attribute/draw instancing and so on. As an added benefit shaders can be constructed dynamically from pieces at runtime (i.e. ubershaders). See text rendering shaders for a simple example: link . This system worked very well so far for us in the Insatia game on Windows, Linux, macOS and even web (using OpenGL ES 2.0 aka WebGL with Emscripten).

Not sure if you'd really want to dive into my code though, but if you will I can help :) it's rather radical approach, the tech is quite experimental and there's no support for DX9 and Vulkan yet. Mentioning it here because as far as I know the majority of all serious engines use CG/HLSL->GLSL compiler or don't use any compiler at all, so I don't know any other widely used alternative to that.