HLSL to GLSL

Users who are viewing this thread

_Sebastian_

Punkbuster 2.0
Baron
Heyho folks!
Since Warband finaly supports Linux and Mac OS, it now contains GLSL shader files.

So mods with unique or customized shaders also need to provide those GLSL shaders files in order to run on Linux or Mac OS.
Unfortunately I haven't found any working tool to translate/convert HLSL into GLSL...
...and even Taleworlds dont offer the tool they used for it.

Is there anyone who successfully converted the HLSL shaders into GLSL, or atleast has any clue how to do it?
I'm not going to write such a tool on my own, if there's already a working tool for that.

Cheers!
 
_Sebastian_ said:
Heyho folks!
Since Warband finaly supports Linux and Mac OS, it now contains GLSL shader files.

So mods with unique or customized shaders also need to provide those GLSL shaders files in order to run on Linux or Mac OC.
Unfortunately I haven't found any working tool to translate/convert HLSL into GLSL...
...and even Taleworlds dont offer the tool they used for it.

Is there anyone who successfully converted the HLSL shaders into GLSL, or atleast has any clue how to do it?
I'm not going to write such a tool on my own, if there's already a working tool for that.

Cheers!

I've been doing it manually for The Last Days.

It's not extremely fun, but the gist of it is creating a GLShaders folder copying the
Code:
techniques.xml
file from the common shaders folder, and appending your own technique file mappings at the end. I track the progress here:

Code:
https://trello.com/c/NKXjx9Nj/73-glitches-bugs-and-shader-incompatibilities-in-the-linux-version-of-warband-mac-too-i-guess


Another thing to keep in mind is that the game crashes if the GLSL shaders don't get perfectly compiled. That's why I use
Code:
http://shdr.bkcore.com/
to catch any (practically inevitable) problem. Specially keeping in mind that the startup time for my Linux Warband is outrageously high. I tend to wait from tweaking to testing more than five minutes with a frozen UI building shaders in the background, after that the performance is pretty snappy, tho. This is with the open source radeon/Gallium/MESA drivers, maybe with the proprietary blobs the situation changes.

It's also important to now that every
Code:
*.glsl
file mapped in
Code:
techniques.xml
gets automatically prefixed by the defines contained inside
Code:
shared_common.glsl
plus
Code:
shared_vs / ps / postfx.glsl
, depending on its type.

So is important to paste those in your shader workbench / environment to get them to compile.
Looks like they have aliased (
Code:
vec4 => float4
and so on) lots of types to their HLSL counterparts to make the process much easier.

--

Edit: For automated conversion there's things like MojoShader, hlsl2glslfork, and as an additional step, glsl-optimizer. I haven't tested them, even if I should.
 
Are there any extra rules for naming?

I'am adding new technique using already defined vertex & fragment programs (so there is no error in my shader for sure) and all I get is warband crash :sad:
Any idea why?

For example this code appended to the end of techinques.xml:
Code:
<technique name="new_techinque">
    <vertex_shader name="vs_main_bump_billboards.glsl"/>
   <fragment_shader name="ps_main_bump_simple.glsl"/>
</technique>

gives my a crash during start.
 
Arsakes said:
Are there any extra rules for naming?

I'am adding new technique using already defined vertex & fragment programs (so there is no error in my shader for sure) and all I get is warband crash :sad:
Any idea why?

For example this code appended to the end of techinques.xml:
Code:
<technique name="new_techinque">
    <vertex_shader name="vs_main_bump_billboards.glsl"/>
   <fragment_shader name="ps_main_bump_simple.glsl"/>
</technique>

gives my a crash during start.


Are you using Mac OS X or Linux?

At first, when they introduced OpenGL shaders in their early Android and Linux ports there was just a
Code:
GLShaders
folder with a pair of vertex and fragment shaders per HLSL technique and those XML mapping files within.

Then they found out that loading unprocessed GLSL was too laggy (If you take a look you'll see that depending of the shader there are common files that are prefixed/combined on loading with uniforms and matrices and
Code:
float3
to
Code:
vec3
macros) and that made the start-up time almost ridiculously high, so they added another folder called
Code:
GLShadersOptimized
, with the same shaders but preprocessed for every material and machine-optimized.

So, to make is short and sweet; now only the XML mapping files are used by the engine, the actual shaders that picked up are chosen by material in
Code:
GLShadersOptimized
instead, leaving
Code:
GLShaders
as a much more readable reference with actual variable names and defines with conditionals.


Hope that helps! You'd be the first person in doing actual GLSL shader work, I have been meaning to use MojoShader to convert my mod's HLSL shaders into GLSL automagically, but never got around and finishing it.
 
Back
Top Bottom