7

I have a project which uses about 2 dozen .vsh and .fsh files to draw 2D tiles using OpenGLES. Since that is deprecated, I want to convert my project to Metal. My head is now swimming with vocabulary and techniques involved in both systems - graphics is not my forte.

Can I use OpenGLES to compile the .vsh/.fsh files, and then save them in a metal-compatible format? The goal would be to then use the saved information in a metal-centric world and remove all the OpenGLES code from the project. I've spent a few days on this already, and yet I don't understand the processes enough to fully attempt the transition to Metal. Any/all help is appreciated.

I saw this: "On devices that support it, the GLSL code you provide to SKShader is automatically converted to Metal shading language and run on a Metal renderer", which leads me to believe there is a way to get this done. I just don't know where to begin. OpenGL ES deprecated in iOS 12 and SKShader

I have seen this: Convert OpenGL shader to Metal (Swift) to be used in CIFilter, and if it answers my question, I don't understand how.

I don't think this answers it either: OpenGL ES and OpenGL compatible shaders

Answers/techniques can use either Objective-C or Swift - the existing code is Objective-C, the rest of the project has been converted to Swift 5.

Edit (June 20230) Check out this amazing link, and other videos by this guy. He also has links to a GitHub demo project. It's about the fundamentals of programming with shaders (for those who are lacking the basics)

https://www.youtube.com/watch?v=f4s1h2YETNY

Mozahler
  • 4,958
  • 6
  • 36
  • 56

1 Answers1

7

There are many ways to do what you want:

1) You can use MoltenGL to seamlessly convert your GLSL shaders to MSL.

2) You can use open-source shader cross-compilers like: krafix, pmfx-shader, etc.


I would like to point out that based on my experience it would be better in terms of performance that you try to rewrite the shaders yourself.

Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48
  • Thanks. I will look into open-source shader cross-compilers, first. If time permits, I'll then try rewriting what I have. – Mozahler Jan 01 '20 at 15:16
  • 1
    [This](https://github.com/aras-p/glsl-optimizer) is another cross compiler option which supports GLSL-ES to metal. – Columbo Jan 01 '20 at 16:28
  • 3
    As the designer of both tools, I recommend you use the converter tool in [MoltenVK](https://github.com/KhronosGroup/MoltenVK), which is more robust than the converter tool in MoltenGL, and will handle GLSL in addition to GLSL-ES. – Bill Hollings Feb 29 '20 at 14:59