OpenGL ES deprecated in iOS 12 and SKShader

落爺英雄遲暮 提交于 2020-01-24 08:52:09

问题


I am very new to the concept and use of shaders in SpriteKit.

I found this tutorial on how to render a Mandelbrot fractal with a custom shader file - Fractal.fsh - attached to a Color Sprite's Custom Shader property.

https://www.weheartswift.com/fractals-Xcode-6/

It works fine and I thought to my self that learning about OpenGL ES and custom shaders in SpriteKit would be a fun exercise.

According to Apple though, OpenGL ES is deprecated as of iOS 12.

https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/BestPracticesforShaders/BestPracticesforShaders.html

My question is this:

Does this mean that custom shaders for use in SpriteKit should be written in Metal as of now?

I have tried to figure out how to rewrite the fractal.fsh shader code, referred to in the first link, in Metal but I have not - yet - been able to find any resources on how to convert existing custom SKShader's from OpenGL ES to Metal. However, I am NOT looking for someone to rewrite that code to use Metal, only a pointer in the right direction.

UPDATE: Based on the answer from @Knight0fDragon I will try to clarify my question:

The documentation on the SKShader class states that:

"An SKShader object holds a custom OpenGL ES fragment shader."

https://developer.apple.com/documentation/spritekit/skshader

So if a SKShader object holds a custom OpenGL ES fragment shader, what will it hold after the support for OpenGL ES is deprecated?

How would one go on about creating a custom fragment shader to use in SpriteKit if one cannot use OpenGL ES as of iOS 12? First I thought that the *.fsh file containing the GLSL code could be replaced with a *.metal file containing equivalent metal code but that assessment was clearly too naive (because I tried and I couldn't assign the *.metal file to the Color Sprite's Custom Shader property)


回答1:


From the documentation on "Executing Shaders in Metal and OpenGL ":

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.

So, from my understanding, SpriteKit will use Metal as a backend where it is available and convert your shaders for you when compiling them. I did not find an option to directly write the shaders in Metal.




回答2:


According to Apple (see near bottom of the page at this link)...

Apps built using OpenGL ES will continue to run in iOS 12, but OpenGL ES is deprecated in iOS 12. Games and graphics-intensive apps that previously used OpenGL ES should now adopt Metal [emphasis added].

If you are starting from scratch, I suggest you write shaders in Metal.



来源:https://stackoverflow.com/questions/53828497/opengl-es-deprecated-in-ios-12-and-skshader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!