OpenGL ES deprecated in iOS 12 and SKShader
Asked Answered
B

2

5

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)

Battleship answered 18/12, 2018 at 7:51 Comment(2)
As far as I know, spritekit and scene kit converts opengl fsh files to metal for you. If you are looking to have raw opengl support, then you are out of luck since Apple will only support Metal from here on out (Their new MacOS only has metal support, expect it to be dropped completely is iOS13)Withindoors
@Withindoors - Thank you for your reponse, based on that I will update the post to clarify my questionBattleship
V
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.

Vittorio answered 18/6, 2019 at 19:44 Comment(0)
W
0

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.

Willpower answered 21/12, 2018 at 21:57 Comment(2)
Hi there 0x141E, I am not looking for a way to get into 3D rendering. I am trying to figure out how to write shaders for use in SpriteKit sprites. According to Apple: "An SKShader object holds a custom OpenGL ES fragment shader." My question then is this: If a SKShader object holds a custom OpenGL ES fragment shader, what will it hold after the support for OpenGL ES is deprecated?Battleship
I have looked into this issue quite a bit, and basically you are out of luck until Apple provides some way to explicitly author SpriteKit shaders in Metal. What they provide currently is a way to load FSH code that get "automatically" converted into Metal like code. Thing is, it only really works for simple examples and there are weird floating point precision issues in complex shaders. You can find a nice simple shader example here: modejong.com/blog/post19_spritekit_bw_shaderFrons

© 2022 - 2024 — McMap. All rights reserved.