2

I am looking for a tool that can convert cg/hlsl hybrid shaders to glsl es shaders. I have tried hlsl2glsl which doesnt understand the keyword 'extern' although it is a viable hlsl keyword and have looked to cgc but have found no documentation on how to compile for glsl es.

Thanks

aerlfredith
  • 1,123
  • 4
  • 12
  • 18

2 Answers2

3

Old question, I know, but I'll offer this answer, anyway.

I came across this while [legally] wanting to appropriate some fine Unity-targeted CG shader code ;-)

Take a look at the CG-shader-to-GLSL-shader Python conversion script 'cg2glsl.py' on Github (it requires the cgc command found within the nvidia-cg-toolkit package, supported on most OSes.

Its usage is, briefly, outlined in 'converting from cg shaders'

Quoting from Tomaka17's CG-to-GLSL-related blog post 'Turning Cg into GLSL, and then using the code'

Cg is a shading language developed by nVidia. Basically you write all your shaders in Cg....Cg will in fact compile your code into the API-specific language.

In Tomaka17's example, he intercept's nVidia CG-library calls using C++ to extract the compiled GLSL code, which I would suggest is conceptually the same as what cg2glsl.py would be doing (although without having to compile the code by way of its Python usage).

Big Rich
  • 5,864
  • 1
  • 40
  • 64
2

cgc filename -profile glslv/glslf

But you have to add presecion for glsl es, cg compiler doesn't this