Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert OpenGLES shaders to Metal compatible ones?

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.

like image 683
Mozahler Avatar asked Dec 31 '19 18:12

Mozahler


1 Answers

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.

like image 71
Hamid Yusifli Avatar answered Nov 15 '22 02:11

Hamid Yusifli