In another win for open-source the developers behind Natural Selection 2 have opened up the code they use to parse HLSL calls into OpenGL's GLSL.
It has been released under the MIT license, so do with it as you wish as long as the MIT license sticks around.
This is after the developers also opened up the original Natural Selection for nostalgia.
Notes
I hope some other developers find it useful, it is interesting to see more than just Valve doing things like this. Who knows maybe it could even help Valve themselves.
Who knows, maybe some helpful developers can peek at NS2's HLSL->GLSL code on github and improve the OpenGL performance as it is quite the hog.
For those that don't know, Valve also does something similair using their own open-source library called ToGL. Although Valve's Source Engine 2 should be using OpenGL directly rather than some sort of translation layer.
It seems even Unreal Engine also uses something similar (seeing a pattern here!), I am sure it makes things easier, but performance wise it just isn't as good as calling OpenGL directly.
Link: https://github.com/unknownworlds/hlslparser
It has been released under the MIT license, so do with it as you wish as long as the MIT license sticks around.
This is after the developers also opened up the original Natural Selection for nostalgia.
Notes
QuoteHLSL Parser and GLSL code generator
This is the code we used in Natural Selection 2 to convert HLSL shader code to GLSL for use with OpenGL. The code is pulled from a larger codebase and has some dependencies which are not included, so the code will not compile as-is. These dependencies are all very basic though (array classes, memory allocators, etc.) so replacing them should be simple if you want to use this code.
The parser is designed to work with HLSL code written in the legacy Direct3D 9 style (e.g. D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY should be used with D3D11). The parser works with cbuffers for uniforms, so in addition to generating GLSL, there is a class provided for generating D3D9-compatible HLSL which doesn't support cbuffers. The GLSL code requires version 3.1 for support of uniform blocks. The parser is designed to catch all errors and generate "clean" GLSL which can then be compiled without any errors.
The HLSL parsing is done though a basic recursive descent parser coded by hand rather than using a parser generator. We believe makes the code easier to understand and work with.
To get consistent results from Direct3D and OpenGL, our engine renders in OpenGL "upside down". This is automatically added into the generated GLSL vertex shaders.
Although this code was written specifically for our use, we hope that it may be useful as an educational tool or a base for someone who wants to do something similar.
I hope some other developers find it useful, it is interesting to see more than just Valve doing things like this. Who knows maybe it could even help Valve themselves.
Who knows, maybe some helpful developers can peek at NS2's HLSL->GLSL code on github and improve the OpenGL performance as it is quite the hog.
For those that don't know, Valve also does something similair using their own open-source library called ToGL. Although Valve's Source Engine 2 should be using OpenGL directly rather than some sort of translation layer.
It seems even Unreal Engine also uses something similar (seeing a pattern here!), I am sure it makes things easier, but performance wise it just isn't as good as calling OpenGL directly.
Link: https://github.com/unknownworlds/hlslparser
Some you may have missed, popular articles from the last month:
All posts need to follow our rules. For users logged in: please hit the Report Flag icon on any post that breaks the rules or contains illegal / harmful content. Guest readers can email us for any issues.
8 comments
This is a very nice initiative! Great!
0 Likes
some one needs to make a OpenGL>DX for Xbone so developers can no longer fear not being able to develop for Xbone
0 Likes
some one needs to make a OpenGL>DX for Xbone so developers can no longer fear not being able to develop for Xbonewhy would anyone want to develop for overpriced underpowered xbone, a 450$ pc beats it in performance and then you haven't considdered the fact that you need to pay 50-60$ each year just to stay online, games are cheaper on pc, the xbone has no decent exclusive yet that can't be replaced by pc alternatves, and you get mods and stuff on pc, there's only 1 reason people buy that and that is fanboyism
0 Likes
Relatedly, does anybody know of a working ARB shaders (that asm-like shader language) to GLSL converter? :P
0 Likes
Unity has a similar, open-source compiler (derived from mesa): https://github.com/aras-p/hlsl2glslfork . Unreal uses the same codebase, but they aren't publishing their proprietary branch at all.
Here's a good overview of cross-API shaders: http://aras-p.info/blog/2014/03/28/cross-platform-shaders-in-2014/
Here's a good overview of cross-API shaders: http://aras-p.info/blog/2014/03/28/cross-platform-shaders-in-2014/
0 Likes
some one needs to make a OpenGL>DX for Xbone so developers can no longer fear not being able to develop for XboneDoes the Xbone not support opengl?
0 Likes
"Although Valve's Source Engine 2 should be using OpenGL directly rather than some sort of translation layer."Hi Liam, do you have a source for this (or anyone else)?
Ha, M$ has been restricting their XBox platforms to use DX/D3D for quite some time now (like all of them), which is why a lot of developers used DX to start off with - they wanted to go on XBoxes. M$ obviously did this to try and lock people into their own proprietary rendering engine with D3D as opposed to OpenGL (and similarly DX vs SDL).some one needs to make a OpenGL>DX for Xbone so developers can no longer fear not being able to develop for XboneDoes the Xbone not support opengl?
0 Likes
Found it. Thanks! =) Yeah, I remember hearing that somewhere before, a lot of the Steam Dev Days videos are really interesting! I watched quite a few of them.
They say their engine still has D3D centric stuff from its heritage but they'd like to move away from that (see the slide as well).
http://youtu.be/45O7WTc6k2Y?t=6m50s
View video on youtube.com
goto 6m50s.
Video in full playlist:
https://www.youtube.com/watch?v=45O7WTc6k2Y&list=PLckFgM6dUP2hc4iy-IdKFtqR9TeZWMPjm&index=10
They say their engine still has D3D centric stuff from its heritage but they'd like to move away from that (see the slide as well).
http://youtu.be/45O7WTc6k2Y?t=6m50s
View video on youtube.com
goto 6m50s.
Video in full playlist:
https://www.youtube.com/watch?v=45O7WTc6k2Y&list=PLckFgM6dUP2hc4iy-IdKFtqR9TeZWMPjm&index=10
0 Likes
See more from me